patch 9.1.0589: vi: d{motion} and cw work differently than expected
Problem: vi: d{motion} and cw command work differently than expected
Solution: add new cpo-z flag to make the behaviour configurable
There are two special vi compatible behaviours (or should I say bugs?):
1): cw behaves differently than dw. That is, because cw is special cased
by Vim and is effectively aliased to ce.
POSIX behaviour is documented here:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/vi.html#tag_20_152_13_81
2): d{motion} may make the whole delete operation linewise, if the start
and end of the motion are on different lines and there are only
blanks before the start and after the end of the motion.
Did not find a related POSIX link that requires this behaviour.
Both behaviours can be considered inconsistent, but we cannot easily
change it, because it would be a backward incompatible change and also
incompatible to how classic vi behaved.
So let's add the new cpo flag "z", which when not included fixes both
behaviours and make them more consistent to what users would expect.
This has been requested several times:
https://groups.google.com/d/msg/vim_use/aaBqT6ECkA4/ALf4odKzEDgJ
https://groups.google.com/d/msg/vim_dev/Dpn3xtUF16I/T6JcOPKN6usJ
http://www.reddit.com/r/vim/comments/26nut8/why_does_cw_work_like_ce/
https://groups.google.com/d/msg/vim_use/vunNWLFWfQg/MmJh_ZGaAgAJ
https://github.com/vim/vim/issues/4390
So in summary, if you want to have the w motion work more consistent,
remove the 'z' from the cpo settings.
related: #4390
closes: #15263
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/option.h b/src/option.h
index e84f7f9..fba2672 100644
--- a/src/option.h
+++ b/src/option.h
@@ -212,6 +212,7 @@
#define CPO_REPLCNT 'X' // "R" with a count only deletes chars once
#define CPO_YANK 'y'
#define CPO_KEEPRO 'Z' // don't reset 'readonly' on ":w!"
+#define CPO_WORD 'z' // do not special-case word motions cw and dw
#define CPO_DOLLAR '$'
#define CPO_FILTER '!'
#define CPO_MATCH '%'
@@ -231,9 +232,9 @@
#define CPO_SCOLON ';' // using "," and ";" will skip over char if
// cursor would not move
// default values for Vim, Vi and POSIX
-#define CPO_VIM "aABceFs"
-#define CPO_VI "aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>;"
-#define CPO_ALL "aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>#{|&/\\.;"
+#define CPO_VIM "aABceFsz"
+#define CPO_VI "aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZz$!%*-+<>;"
+#define CPO_ALL "aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZz$!%*-+<>#{|&/\\.;"
// characters for p_ww option:
#define WW_ALL "bshl<>[]~"