diff --git a/doc/pages/keys.asciidoc b/doc/pages/keys.asciidoc index 61946506..1b380c19 100644 --- a/doc/pages/keys.asciidoc +++ b/doc/pages/keys.asciidoc @@ -612,7 +612,7 @@ the wanted object: *w*:: select the whole word -*W*:: +**:: select the whole WORD *s*:: diff --git a/src/main.cc b/src/main.cc index a3802a85..a92bc0d5 100644 --- a/src/main.cc +++ b/src/main.cc @@ -48,7 +48,8 @@ static const char* startup_info = " * '*' Does not strip whitespaces anymore, use built-in '_' to strip them\n" " * 'l' on eol will go to next line, 'h' on first char will go to previous\n" " * selections merging behaviour is now a bit more complex again\n" -" * 'x' will only jump to next line if full line is already selected\n"; +" * 'x' will only jump to next line if full line is already selected\n" +" * WORD text object moved to instead of W for consistency\n"; struct startup_error : runtime_error { diff --git a/src/normal.cc b/src/normal.cc index 0a36d059..21609090 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1181,17 +1181,16 @@ void select_object(Context& context, NormalParams params) const int count = params.count <= 0 ? 0 : params.count - 1; on_next_key_with_autoinfo(context, KeymapMode::Object, [count](Key key, Context& context) { - if (not key.codepoint() or key == Key::Escape) + if (key == Key::Escape) return; - const auto cp = *key.codepoint(); static constexpr struct ObjectType { - Codepoint key; + Key key; Optional (*func)(const Context&, const Selection&, int, ObjectFlags); } selectors[] = { { 'w', select_word }, - { 'W', select_word }, + { alt('w'), select_word }, { 's', select_sentence }, { 'p', select_paragraph }, { ' ', select_whitespaces }, @@ -1199,12 +1198,12 @@ void select_object(Context& context, NormalParams params) { 'n', select_number }, { 'u', select_argument }, }; - auto obj_it = find(selectors | transform(std::mem_fn(&ObjectType::key)), cp).base(); + auto obj_it = find(selectors | transform(std::mem_fn(&ObjectType::key)), key).base(); if (obj_it != std::end(selectors)) return select_and_set_last( context, std::bind(obj_it->func, _1, _2, count, flags)); - if (cp == 'c') + if (key == 'c') { const bool info = show_auto_info_ifn( "Enter object desc", @@ -1253,9 +1252,9 @@ void select_object(Context& context, NormalParams params) { '`', '`', 'g' }, }; auto pair_it = find_if(surrounding_pairs, - [cp](const SurroundingPair& s) { - return s.opening == cp or s.closing == cp or - (s.name != 0 and s.name == cp); + [key](const SurroundingPair& s) { + return key == s.opening or key == s.closing or + (s.name != 0 and key == s.name); }); if (pair_it != std::end(surrounding_pairs)) return select_and_set_last( @@ -1264,6 +1263,10 @@ void select_object(Context& context, NormalParams params) Regex{format("\\Q{}", pair_it->closing), RegexCompileFlags::Backward}, count, flags)); + if (not key.codepoint()) + return; + + const Codepoint cp = *key.codepoint(); if (is_punctuation(cp) or cp == '_') { auto re = Regex{"\\Q" + to_string(cp), RegexCompileFlags::Backward}; @@ -1281,7 +1284,7 @@ void select_object(Context& context, NormalParams params) {{'\'','q'}, "single quote string"}, {{'`','g'}, "grave quote string"}, {{'w'}, "word"}, - {{'W'}, "WORD"}, + {{alt('w')}, "WORD"}, {{'s'}, "sentence"}, {{'p'}, "paragraph"}, {{' '}, "whitespaces"}, diff --git a/test/normal/object/around/big-word/cmd b/test/normal/object/around/big-word/cmd index 2591ecc3..ddbe85ee 100644 --- a/test/normal/object/around/big-word/cmd +++ b/test/normal/object/around/big-word/cmd @@ -1 +1 @@ -W + diff --git a/test/normal/object/end-extending/big-word/cmd b/test/normal/object/end-extending/big-word/cmd index 534740a4..ef14531d 100644 --- a/test/normal/object/end-extending/big-word/cmd +++ b/test/normal/object/end-extending/big-word/cmd @@ -1 +1 @@ -}W +} diff --git a/test/normal/object/end/big-word/cmd b/test/normal/object/end/big-word/cmd index cd1b8fb2..7a3a9427 100644 --- a/test/normal/object/end/big-word/cmd +++ b/test/normal/object/end/big-word/cmd @@ -1 +1 @@ -]W +] diff --git a/test/normal/object/inner/big-word/cmd b/test/normal/object/inner/big-word/cmd index 12d2f19a..1e55efb3 100644 --- a/test/normal/object/inner/big-word/cmd +++ b/test/normal/object/inner/big-word/cmd @@ -1 +1 @@ -W + diff --git a/test/normal/object/start-extending/big-word/cmd b/test/normal/object/start-extending/big-word/cmd index f2ed5a2e..5078694d 100644 --- a/test/normal/object/start-extending/big-word/cmd +++ b/test/normal/object/start-extending/big-word/cmd @@ -1 +1 @@ -{W +{ diff --git a/test/normal/object/start/big-word/cmd b/test/normal/object/start/big-word/cmd index b8c68dc9..d8192e06 100644 --- a/test/normal/object/start/big-word/cmd +++ b/test/normal/object/start/big-word/cmd @@ -1 +1 @@ -[W +[