diff --git a/runtime/doc/motion.txt b/runtime/doc/motion.txt index 606fd53feee90c..2d5d79d200f564 100644 --- a/runtime/doc/motion.txt +++ b/runtime/doc/motion.txt @@ -402,7 +402,8 @@ WORD before the fold. Special case: "cw" and "cW" are treated like "ce" and "cE" if the cursor is on a non-blank. This is because "cw" is interpreted as change-word, and a -word does not include the following white space. +word does not include the following white space. This behavior can be +adjusted via |cpo-_|. Another special case: When using the "w" motion in combination with an operator and the last word moved over is at the end of a line, the end of diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 25dca5fb517f91..906c994053ca7b 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -1829,6 +1829,9 @@ A jump table for the options with a short description can be found at |Q_op|. character, the cursor won't move. When not included, the cursor would skip over it and jump to the following occurrence. + *cpo-_* + _ When using "cw" on a word, do not include the + whitespace following the word in the motion. *'cscopepathcomp'* *'cspc'* 'cscopepathcomp' 'cspc' number (default 0) diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 92b1cf2d55e8f9..0011efc64030cd 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -7193,8 +7193,10 @@ static void nv_wordcmd(cmdarg_T *cap) // Another strangeness: When standing on the end of a word "ce" will // change until the end of the next word, but "cw" will change only one // character! This is done by setting "flag". - cap->oap->inclusive = true; - word_end = true; + if (vim_strchr(p_cpo, CPO_CHANGEW) != NULL) { + cap->oap->inclusive = true; + word_end = true; + } flag = true; } } diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index 9c6393e014d36b..1d614c9d8a5680 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -129,9 +129,11 @@ #define CPO_REGAPPEND '>' /* insert NL when appending to a register */ #define CPO_SCOLON ';' /* using "," and ";" will skip over char if * cursor would not move */ -/* default values for Vim and Vi */ -#define CPO_VIM "aABceFs" -#define CPO_VI "aAbBcCdDeEfFiIJkKlLmMnoOpPqrRsStuvWxXyZ$!%+<>;" +#define CPO_CHANGEW '_' // do not special-case cw, it works as + // expected +// default values for Vim and Vi +#define CPO_VIM "aABceFs_" +#define CPO_VI "aAbBcCdDeEfFiIJkKlLmMnoOpPqrRsStuvWxXyZ$!%+<>;_" /* characters for p_ww option: */ #define WW_ALL "bshl<>[],~"