11
votes
Why do `cw` and `ce` do the same thing?
The difference between the behavior of the motion in cw vs. dw can be explained simply: normally if you want to change a word you're going to leave the whitespace following it, while deleting a word ...
3
votes
Accepted
How to copy N words under cursor and to right of cursor?
You can do y3w if you are at beginning of a word (so: yank 3 words) or by3w to get at the beginning of the word first (so: back yank 3 words)
3
votes
How can I make w and b act like W and B to navigate big words (space delimited words)?
Vim is very customizable. You can customize the behavior of every key. For normal mode w and b, you could do
nnoremap w W
nnoremap b B
To replicate this behavior in a visual selection, and after an ...
3
votes
Accepted
How to get all distinct words within a set of lines?
You can do something like this:
:let a=[]
:%s/\w\+/\=add(a, submatch(0))/gn
:new
:put =uniq(sort(a))
This will first declare a list a to work with. Then we run a :%s command, to capture all word-...
3
votes
What is the easiest way to select multiple words in visual mode?
For me personally, counting stuff and apply counts is not the easiest thing to do.
I prefer to do several repeats like with viwee.
Or if the ending word is quite away from the cursor position I ...
3
votes
Accepted
Ammend 'w' behavior - ignore operators and brackets - '(', '[' '{', '*', '+', '='
Is it possible?
Anything is possible with some scripting:
nnoremap <silent> <leader>w :call search('\<\w', 'W')<cr>
nnoremap <silent> <leader>e :call search('\w\>'...
2
votes
How to get all distinct words within a set of lines?
You can use grep with the --only-matching/-o flag to accomplish this:
:%!grep -o '\w\+\|\W' | sort -u
2
votes
How to get all distinct words within a set of lines?
Maybe this:
:%s/\W/\r\0\r/g
:sort u
:g/^\s*$/d
The first puts a line break before and after each non-word character.
The second command sorts the entire file with the option "unique", so all ...
2
votes
Accepted
What is the easiest way to select multiple words in visual mode?
I would go with vf3 (with the cursor at the beginning of the first word) because it doesn't require you to count anything you just have to think "I want to put my cursor in this character".
Anyway I ...
2
votes
What is the easiest way to select multiple words in visual mode?
You want 3 words, and this key combination uses number 5, so not so straight-forward in my opinion. I would possition cursor on the start of word1 if needed - with b - and then used v3e (or even v3E - ...
2
votes
Accepted
Prevent W from jumping to next line
As Tumbler41 pointed out in the comments, the simpler solution would be to use E instead of W. However, if you would like to configure W to behave this way, you could do this:
nnoremap <expr> W ...
2
votes
Accepted
Use Word for `*`/`#`
* is roughly equivalent to searching for the string:
'\<' . escape(expand('<cword>'), '/.*~[^$\') . '\>'
(the escape is slightly different for #). So, one option is to create a custom ...
1
vote
Visual mode word behaves differently than in normal mode?
In Vim motions can be either inclusive ("include the rightmost character"), or exclusive ("exclude rightmost character"). w is made exclusive (so you delete exactly four words: "this" "is" "a" "test")....
1
vote
Accepted
iskeyword with context
The 'iskeyword' option defines the codepoints for a single keyword character, but cannot make a statement about its neighbors. In other words, you'd need a regular expression (something like [a-zA-Z][...
1
vote
Accepted
Inconsistent <cword>, <C-R><C-W>, and keyword behavior
It is probably the result of the mappings in $VIMRUNTIME/ftplugin/ruby.vim, which include a mapping of <C-R><C-W> to <Plug><cword> which is then mapped to a call to ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
vi-words × 13normal-mode × 3
cursor-motions × 3
visual-mode × 2
regular-expression × 1
gvim × 1
cut-copy-paste × 1
cursor-movement × 1
functions × 1
navigation × 1
whitespace × 1
filetype-ruby × 1
keyword × 1
list × 1