Thursday, February 4, 2016

Re: Feature or bug? dw oddities


when '_' is not included in 'cpo' options, make the w motion during a change operation
behave as expected.

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/

Also make dw work as expected
https://groups.google.com/d/msg/vim_use/vunNWLFWfQg/MmJh_ZGaAgAJ

So in summary, if you want to have the w motion work more consistent,
remove the '_' from the cpo settings.

# HG changeset patch
# Parent 119affd4a4e3305a9bb052ad18199ddbc88d1b40

diff --git a/runtime/doc/change.txt b/runtime/doc/change.txt
--- a/runtime/doc/change.txt
+++ b/runtime/doc/change.txt
@@ -96,6 +96,7 @@ 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
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -2245,6 +2245,9 @@ A jump table for the options with a shor
character, the cursor won't move. When not included,
the cursor would skip over it and jump to the
following occurrence.
+ *cpo-_*
+ _ Do not special case the word motion for "cw"
+ and "dw" (see |cw| |d-special|)

POSIX flags. These are not included in the Vi default value, except
when $VIM_POSIX was set on startup. |posix|
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
@@ -172,10 +172,11 @@
#define CPO_CHDIR '.' /* don't chdir if buffer is modified */
#define CPO_SCOLON ';' /* using "," and ";" will skip over char if
* cursor would not move */
+#define CPO_WORD '_' /* do not special-case word motions cw and dw, it works as expected */
/* default values for Vim, Vi and POSIX */
-#define CPO_VIM "aABceFs"
-#define CPO_VI "aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>;"
-#define CPO_ALL "aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>#{|&/\\.;"
+#define CPO_VIM "aABceFs_"
+#define CPO_VI "aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>;_"
+#define CPO_ALL "aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>#{|&/\\.;_"

/* characters for p_ww option: */
#define WW_ALL "bshl<>[],~"
Hi Elmar!

On Do, 04 Feb 2016, Elmar Hinz wrote:

>
> > last line. I've since downloaded a proper version of elvis and it
> > behaves the same as all the other clones apart from vim.
> >
>
> Summarising this, you think vim is behaving differently than most
> other vi derivates?
>
> Why is the comment quoted by Christian Brabandt telling, vim tries to
> behave like vi?

Well, we can perhaps use this patch.

Mit freundlichen Grüßen
Christian
--
Es gibt mehr alte Trinker als alte Ärzte.

--
--
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: