Make arrow keys normal mode mappings instead of commands

This commit is contained in:
Maxime Coste 2019-09-15 19:40:38 +10:00
parent 33a00c7031
commit fc3a1b6973
5 changed files with 59 additions and 20 deletions

View File

@ -3,6 +3,11 @@
This changelog contains major and/or breaking changes to Kakoune between
released versions.
== Development version
* Arrow keys and `<home>`, `<end>` are not normal mode commands
anymore but default key mappings.
== Kakoune 2019.07.01
* Re-organized bundled script files directory hierarchy.

View File

@ -99,17 +99,25 @@ is a sequence of non whitespace characters. Generally, a movement on it own
will move each selection to cover the text moved over, while holding down
the Shift modifier and moving will extend each selection instead.
*h*, *<left>*::
*h*::
select the character on the left of the end of each selection
`<left>` maps to this by default.
(See <<mapping#default-mappings,`:doc mapping default-mappings`>>)
*j*, *<down>*::
*j*::
select the character below the end of each selection
`<down>` maps to this by default.
(See <<mapping#default-mappings,`:doc mapping default-mappings`>>)
*k*, *<up>*::
*k*::
select the character above the end of each selection
`<up>` maps to this by default.
(See <<mapping#default-mappings,`:doc mapping default-mappings`>>)
*l*, *<right>*::
*l*::
select the character on the right of the end of each selection
`<right>` maps to this by default.
(See <<mapping#default-mappings,`:doc mapping default-mappings`>>)
*w*::
select the word and following whitespaces on the right of the end of each selection
@ -165,11 +173,15 @@ the Shift modifier and moving will extend each selection instead.
*%*::
select whole buffer
*<a-h>*, *<home>*::
*<a-h>*::
select to line begin
`<home>` maps to this by default.
(See <<mapping#default-mappings,`:doc mapping default-mappings`>>)
*<a-l>*, *<end>*::
*<a-l>*::
select to line end
`<end>` maps to this by default.
(See <<mapping#default-mappings,`:doc mapping default-mappings`>>)
*pageup, <c-b>*::
scroll one page up

View File

@ -142,3 +142,19 @@ NOTE: Although Kakoune allows many key combinations to be mapped, not every
possible combination can be triggered. For example, due to limitations in
the way terminals handle control characters, mappings like *<c-s-a>* are
unlikely to work in Kakoune's terminal UI.
== Default mappings
Some mappings exist by default in the global scope:
In normal mode:
* `<left>` maps to `h`
* `<right>` maps to `l`
* `<up>` maps to `k`
* `<down>` maps to `j`
* `<home>` maps to `<a-h>`
* `<end>` maps to `<a-l>`
Shift version of those mappings exist as well
(for example `<s-left>` maps to `H`).

View File

@ -337,6 +337,25 @@ void register_registers()
register_manager.add_register('_', std::make_unique<NullRegister>());
}
void register_keymaps()
{
auto& keymaps = GlobalScope::instance().keymaps();
keymaps.map_key(Key::Left, KeymapMode::Normal, {'h'}, "");
keymaps.map_key(Key::Right, KeymapMode::Normal, {'l'}, "");
keymaps.map_key(Key::Down, KeymapMode::Normal, {'j'}, "");
keymaps.map_key(Key::Up, KeymapMode::Normal, {'k'}, "");
keymaps.map_key(shift(Key::Left), KeymapMode::Normal, {'H'}, "");
keymaps.map_key(shift(Key::Right), KeymapMode::Normal, {'L'}, "");
keymaps.map_key(shift(Key::Down), KeymapMode::Normal, {'J'}, "");
keymaps.map_key(shift(Key::Up), KeymapMode::Normal, {'K'}, "");
keymaps.map_key(Key::End, KeymapMode::Normal, {alt('l')}, "");
keymaps.map_key(Key::Home, KeymapMode::Normal, {alt('h')}, "");
keymaps.map_key(shift(Key::End), KeymapMode::Normal, {alt('L')}, "");
keymaps.map_key(shift(Key::Home), KeymapMode::Normal, {alt('H')}, "");
}
static void check_tabstop(const int& val)
{
if (val < 1) throw runtime_error{"tabstop should be strictly positive"};
@ -672,6 +691,7 @@ int run_server(StringView session, StringView server_init,
register_options();
register_registers();
register_keymaps();
register_commands();
register_highlighters();

View File

@ -2175,21 +2175,11 @@ static constexpr HashMap<Key, NormalCmd, MemoryDomain::Undefined, KeymapBackend>
{ {'k'}, {"move up", move_cursor<LineCount, Backward>} },
{ {'l'}, {"move right", move_cursor<CharCount, Forward>} },
{ {Key::Left}, { "move left", move_cursor<CharCount, Backward>} },
{ {Key::Down}, { "move down", move_cursor<LineCount, Forward>} },
{ {Key::Up}, { "move up", move_cursor<LineCount, Backward>} },
{ {Key::Right}, {"move right", move_cursor<CharCount, Forward>} },
{ {'H'}, {"extend left", move_cursor<CharCount, Backward, SelectMode::Extend>} },
{ {'J'}, {"extend down", move_cursor<LineCount, Forward, SelectMode::Extend>} },
{ {'K'}, {"extend up", move_cursor<LineCount, Backward, SelectMode::Extend>} },
{ {'L'}, {"extend right", move_cursor<CharCount, Forward, SelectMode::Extend>} },
{ shift(Key::Left), {"extend left", move_cursor<CharCount, Backward, SelectMode::Extend>} },
{ shift(Key::Down), {"extend down", move_cursor<LineCount, Forward, SelectMode::Extend>} },
{ shift(Key::Up), {"extend up", move_cursor<LineCount, Backward, SelectMode::Extend>} },
{ shift(Key::Right), {"extend right", move_cursor<CharCount, Forward, SelectMode::Extend>} },
{ {'t'}, {"select to next character", select_to_next_char<SelectFlags::None>} },
{ {'f'}, {"select to next character included", select_to_next_char<SelectFlags::Inclusive>} },
{ {'T'}, {"extend to next character", select_to_next_char<SelectFlags::Extend>} },
@ -2266,13 +2256,9 @@ static constexpr HashMap<Key, NormalCmd, MemoryDomain::Undefined, KeymapBackend>
{ {alt('B')}, {"extend to previous WORD start", repeated<select<SelectMode::Extend, select_to_previous_word<WORD>>>} },
{ {alt('l')}, {"select to line end", repeated<select<SelectMode::Replace, select_to_line_end<false>>>} },
{ {Key::End}, {"select to line end", repeated<select<SelectMode::Replace, select_to_line_end<false>>>} },
{ {alt('L')}, {"extend to line end", repeated<select<SelectMode::Extend, select_to_line_end<false>>>} },
{ shift(Key::End), {"extend to line end", repeated<select<SelectMode::Extend, select_to_line_end<false>>>} },
{ {alt('h')}, {"select to line begin", repeated<select<SelectMode::Replace, select_to_line_begin<false>>>} },
{ {Key::Home}, {"select to line begin", repeated<select<SelectMode::Replace, select_to_line_begin<false>>>} },
{ {alt('H')}, {"extend to line begin", repeated<select<SelectMode::Extend, select_to_line_begin<false>>>} },
{ shift(Key::Home), {"extend to line begin", repeated<select<SelectMode::Extend, select_to_line_begin<false>>>} },
{ {'x'}, {"select line", repeated<select<SelectMode::Replace, select_line>>} },
{ {'X'}, {"extend line", repeated<select<SelectMode::Extend, select_line>>} },