Skip to main content
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 ...
dash-tom-bang's user avatar
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)
r1amu's user avatar
  • 66
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 ...
husB's user avatar
  • 2,143
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-...
Christian Brabandt's user avatar
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 ...
Maxim Kim's user avatar
  • 13.9k
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\>'...
Tommy A's user avatar
  • 6,810
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
Peter Rincker's user avatar
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 ...
Ralf's user avatar
  • 9,417
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 ...
statox's user avatar
  • 50.6k
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 - ...
grodzik's user avatar
  • 4,738
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 ...
DJMcMayhem's user avatar
  • 17.9k
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 ...
Mass's user avatar
  • 14.4k
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")....
Matt's user avatar
  • 21.6k
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][...
Ingo Karkat's user avatar
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 ...
garyjohn's user avatar
  • 6,429

Only top scored, non community-wiki answers of a minimum length are eligible