diff --git a/doc/pages/changelog.asciidoc b/doc/pages/changelog.asciidoc index ce46177f..0c8fd7d4 100644 --- a/doc/pages/changelog.asciidoc +++ b/doc/pages/changelog.asciidoc @@ -3,6 +3,11 @@ This changelog contains major and/or breaking changes to Kakoune between released versions. +== Development version + +* Arrow keys and ``, `` are not normal mode commands + anymore but default key mappings. + == Kakoune 2019.07.01 * Re-organized bundled script files directory hierarchy. diff --git a/doc/pages/keys.asciidoc b/doc/pages/keys.asciidoc index d8681e99..d4bba91f 100644 --- a/doc/pages/keys.asciidoc +++ b/doc/pages/keys.asciidoc @@ -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*, **:: +*h*:: select the character on the left of the end of each selection + `` maps to this by default. + (See <>) -*j*, **:: +*j*:: select the character below the end of each selection + `` maps to this by default. + (See <>) -*k*, **:: +*k*:: select the character above the end of each selection + `` maps to this by default. + (See <>) -*l*, **:: +*l*:: select the character on the right of the end of each selection + `` maps to this by default. + (See <>) *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 -**, **:: +**:: select to line begin + `` maps to this by default. + (See <>) -**, **:: +**:: select to line end + `` maps to this by default. + (See <>) *pageup, *:: scroll one page up diff --git a/doc/pages/mapping.asciidoc b/doc/pages/mapping.asciidoc index 8e488c1b..5216e179 100644 --- a/doc/pages/mapping.asciidoc +++ b/doc/pages/mapping.asciidoc @@ -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 ** are unlikely to work in Kakoune's terminal UI. + +== Default mappings + +Some mappings exist by default in the global scope: + +In normal mode: + + * `` maps to `h` + * `` maps to `l` + * `` maps to `k` + * `` maps to `j` + * `` maps to `` + * `` maps to `` + +Shift version of those mappings exist as well +(for example `` maps to `H`). diff --git a/src/main.cc b/src/main.cc index d07f5a1f..bdaa4729 100644 --- a/src/main.cc +++ b/src/main.cc @@ -337,6 +337,25 @@ void register_registers() register_manager.add_register('_', std::make_unique()); } +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(); diff --git a/src/normal.cc b/src/normal.cc index ad085458..5661d6cc 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -2175,21 +2175,11 @@ static constexpr HashMap { {'k'}, {"move up", move_cursor} }, { {'l'}, {"move right", move_cursor} }, - { {Key::Left}, { "move left", move_cursor} }, - { {Key::Down}, { "move down", move_cursor} }, - { {Key::Up}, { "move up", move_cursor} }, - { {Key::Right}, {"move right", move_cursor} }, - { {'H'}, {"extend left", move_cursor} }, { {'J'}, {"extend down", move_cursor} }, { {'K'}, {"extend up", move_cursor} }, { {'L'}, {"extend right", move_cursor} }, - { shift(Key::Left), {"extend left", move_cursor} }, - { shift(Key::Down), {"extend down", move_cursor} }, - { shift(Key::Up), {"extend up", move_cursor} }, - { shift(Key::Right), {"extend right", move_cursor} }, - { {'t'}, {"select to next character", select_to_next_char} }, { {'f'}, {"select to next character included", select_to_next_char} }, { {'T'}, {"extend to next character", select_to_next_char} }, @@ -2266,13 +2256,9 @@ static constexpr HashMap { {alt('B')}, {"extend to previous WORD start", repeated>>} }, { {alt('l')}, {"select to line end", repeated>>} }, - { {Key::End}, {"select to line end", repeated>>} }, { {alt('L')}, {"extend to line end", repeated>>} }, - { shift(Key::End), {"extend to line end", repeated>>} }, { {alt('h')}, {"select to line begin", repeated>>} }, - { {Key::Home}, {"select to line begin", repeated>>} }, { {alt('H')}, {"extend to line begin", repeated>>} }, - { shift(Key::Home), {"extend to line begin", repeated>>} }, { {'x'}, {"select line", repeated>} }, { {'X'}, {"extend line", repeated>} },