Change line editing bindings to match readline's

In the end, no better solution materialized so far, and custom
Kakoune line editing bindings are hard to remember. Using well
known readline bindings seems just more convenient.

Closes #800, although it does not contain all the binding proposed
by it (I might accept a few additional ones, such as <c-w>, but not
too much, I still see that as a hack pending a nicer solution).
This commit is contained in:
Maxime Coste 2018-09-03 22:15:28 +10:00
parent 60a338b9bd
commit 4b7e77ae00
2 changed files with 24 additions and 24 deletions

View File

@ -679,40 +679,40 @@ The following keys are recognized by this mode to help with editing (See <<comma
*<esc>*:: *<esc>*::
abandon without abandon without
*<left>*, *<a-h>*:: *<left>*, *<c-b>*::
move cursor to previous character move cursor to previous character
*<right>*, *<a-l>*:: *<right>*, *<c-f>*::
move cursor to next character move cursor to next character
*<home>*:: *<home>*, *<c-a>*::
move cursor to first character move cursor to first character
*<end>*:: *<end>*, *<c-e>::
move cursor past the last character move cursor past the last character
*<backspace>*, *<a-x>*:: *<backspace>*, *<c-h>*::
erase character before cursor erase character before cursor
*<del>*, *<a-d>*:: *<del>*, *<c-d>*::
erase character under cursor erase character under cursor
*<c-w>*:: *<a-f>*::
advance to next word begin advance to next word begin
*<c-a-w>*:: *<a-F>*::
advance to next WORD begin advance to next WORD begin
*<c-b>*:: *<a-b>*::
go back to previous word begin go back to previous word begin
*<c-a-b>*:: *<a-B>*::
go back to previous WORD begin go back to previous WORD begin
*<c-e>*:: *<a-e>*::
advance to next word end advance to next word end
*<c-a-e>*:: *<a-E>*::
advance to next word end advance to next word end
*<up>*, *<c-p>*:: *<up>*, *<c-p>*::

View File

@ -437,21 +437,21 @@ public:
void handle_key(Key key) void handle_key(Key key)
{ {
if (key == Key::Left or key == alt('h')) if (key == Key::Left or key == ctrl('b'))
{ {
if (m_cursor_pos > 0) if (m_cursor_pos > 0)
--m_cursor_pos; --m_cursor_pos;
} }
else if (key == Key::Right or key == alt('l')) else if (key == Key::Right or key == ctrl('f'))
{ {
if (m_cursor_pos < m_line.char_length()) if (m_cursor_pos < m_line.char_length())
++m_cursor_pos; ++m_cursor_pos;
} }
else if (key == Key::Home) else if (key == Key::Home or key == ctrl('a'))
m_cursor_pos = 0; m_cursor_pos = 0;
else if (key == Key::End) else if (key == Key::End or key == ctrl('e'))
m_cursor_pos = m_line.char_length(); m_cursor_pos = m_line.char_length();
else if (key == Key::Backspace or key == alt('x')) else if (key == Key::Backspace or key == ctrl('h'))
{ {
if (m_cursor_pos != 0) if (m_cursor_pos != 0)
{ {
@ -461,23 +461,23 @@ public:
--m_cursor_pos; --m_cursor_pos;
} }
} }
else if (key == Key::Delete or key == alt('d')) else if (key == Key::Delete or key == ctrl('d'))
{ {
if (m_cursor_pos != m_line.char_length()) if (m_cursor_pos != m_line.char_length())
m_line = m_line.substr(0, m_cursor_pos) m_line = m_line.substr(0, m_cursor_pos)
+ m_line.substr(m_cursor_pos+1); + m_line.substr(m_cursor_pos+1);
} }
else if (key == ctrl('w')) else if (key == alt('f'))
to_next_word_begin<Word>(m_cursor_pos, m_line); to_next_word_begin<Word>(m_cursor_pos, m_line);
else if (key == ctrl(alt('w'))) else if (key == alt('W'))
to_next_word_begin<WORD>(m_cursor_pos, m_line); to_next_word_begin<WORD>(m_cursor_pos, m_line);
else if (key == ctrl('b')) else if (key == alt('b'))
to_prev_word_begin<Word>(m_cursor_pos, m_line); to_prev_word_begin<Word>(m_cursor_pos, m_line);
else if (key == ctrl(alt('b'))) else if (key == alt('B'))
to_prev_word_begin<WORD>(m_cursor_pos, m_line); to_prev_word_begin<WORD>(m_cursor_pos, m_line);
else if (key == ctrl('e')) else if (key == alt('e'))
to_next_word_end<Word>(m_cursor_pos, m_line); to_next_word_end<Word>(m_cursor_pos, m_line);
else if (key == ctrl(alt('e'))) else if (key == alt('E'))
to_next_word_end<WORD>(m_cursor_pos, m_line); to_next_word_end<WORD>(m_cursor_pos, m_line);
else if (key == ctrl('k')) else if (key == ctrl('k'))
m_line = m_line.substr(0_char, m_cursor_pos).str(); m_line = m_line.substr(0_char, m_cursor_pos).str();