Monday, February 8, 2016

Re: Feature or bug? dw oddities

diff --git a/runtime/doc/change.txt b/runtime/doc/change.txt
--- a/runtime/doc/change.txt
+++ b/runtime/doc/change.txt
@@ -96,12 +96,13 @@ These commands delete text. You can rep
(except `:d`) and undo them. Use Visual mode to delete blocks of text. See
|registers| for an explanation of registers.

+ *d-special*
An exception for the d{motion} command: If the motion is not linewise, the
start and end of the motion are not in the same line, and there are only
blanks before the start and after the end of the motion, the delete becomes
linewise. This means that the delete also removes the line of blanks that you
might expect to remain. Use the |o_v| operator to force the motion to be
-characterwise.
+characterwise or set |cpo-z|).

Trying to delete an empty region of text (e.g., "d0" in the first column)
is an error when 'cpoptions' includes the 'E' flag.
@@ -248,7 +249,7 @@ Replace mode" |mode-ins-repl|).
Special case: When the cursor is in a word, "cw" and "cW" do not include the
white space after a word, they only change up to the end of the word. This is
because Vim interprets "cw" as change-word, and a word does not include the
-following white space.
+following white space (see also |cpo-z|).
{Vi: "cw" when on a blank followed by other blanks changes only the first
blank; this is probably a bug, because "dw" deletes all the blanks; use the
'w' flag in 'cpoptions' to make it work like Vi anyway}
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -2187,6 +2187,9 @@ A jump table for the options with a shor
*cpo-Z*
Z When using "w!" while the 'readonly' option is set,
don't reset 'readonly'.
+ *cpo-z*
+ z Special casing the word motion for "cw" and "dw"
+ (see |cw| |d-special|)
*cpo-!*
! When redoing a filter command, use the last used
external command, whatever it was. Otherwise the last
diff --git a/src/normal.c b/src/normal.c
--- a/src/normal.c
+++ b/src/normal.c
@@ -8659,8 +8659,11 @@ nv_wordcmd(cmdarg_T *cap)
* will change only one character! This is done by setting
* flag.
*/
- cap->oap->inclusive = TRUE;
- word_end = TRUE;
+ if (vim_strchr(p_cpo, CPO_WORD) != NULL)
+ {
+ cap->oap->inclusive = TRUE;
+ word_end = TRUE;
+ }
flag = TRUE;
}
}
diff --git a/src/ops.c b/src/ops.c
--- a/src/ops.c
+++ b/src/ops.c
@@ -1659,6 +1659,7 @@ op_delete(oparg_T *oap)
&& !oap->block_mode
&& oap->line_count > 1
&& oap->motion_force == NUL
+ && (vim_strchr(p_cpo, CPO_WORD) != NULL)
&& oap->op_type == OP_DELETE)
{
ptr = ml_get(oap->end.lnum) + oap->end.col;
diff --git a/src/option.h b/src/option.h
--- a/src/option.h
+++ b/src/option.h
@@ -154,6 +154,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, it works as expected */
#define CPO_DOLLAR '$'
#define CPO_FILTER '!'
#define CPO_MATCH '%'
@@ -173,9 +174,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<>[],~"
Hi Bram!

On Sa, 06 Feb 2016, Bram Moolenaar wrote:

> There are a few more places in the docs that need to point to this flag.
>
> Is there a better character than "_" to use for this?

Updated patch uses 'z'

Also added some more references to it in the documentation.

> Also, plugin writers must be aware of the two different behaviors.

I am not sure, what is meant with this statement. The current behaviour
does not change, only when removing the 'z' flag from 'cpo' it will
behave more consistent (as other vi clones behave).

Best,
Christian
--
Eine freie Seele, wie die seine, kommt in Gefahr, frech zu
werden, wenn nicht ein edles Wohlwollen das sittliche Gleichgewicht
herstellt.
-- Goethe, Maximen und Reflektionen, Nr. 190

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: