0

I navigate by big words much more often would like to just type w and b instead of W and B every time. I wonder if Vim has a setting for this.

4
  • 1
    BTW, "big words" are called WORDS in Vim's :help (as opposed to regular words).
    – Friedrich
    Commented May 20 at 8:58
  • I thought the wording didn't matter that much for something like this post, and that by big words I meant WORDS.
    – Oneechan69
    Commented May 20 at 9:24
  • Wording always matters. More so when discussing technical topics.
    – romainl
    Commented May 20 at 10:46
  • It didn't matter in the sense that everybody understood what you meant, I does matter as there's an established term used within this domain. I didn't mean to point out a mistake as much as I wanted to hint to the correct word (or WORD).
    – Friedrich
    Commented May 20 at 11:14

1 Answer 1

3

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 operator (such as d, c, y), you could do

xnoremap w W
onoremap w W
xnoremap b B
onoremap b B

In the above, the x and o refer to visual and operator-pending modes respectively.

You could extend these, to include

  • the navigation to the end of WORDS with e, and ge
  • using W,B,E,gE to navigate by words instead of WORDS

Have a look at :h usr_05.txt (notably, sections 5.1 and 5.3) for more information.

5
  • This answers the question as it was asked: it will work for navigation. Note that this will not affect visual and operator-pending modes. You would also have to define the same mappings as vnoremap and onoremap to have consistency across modes.
    – Friedrich
    Commented May 20 at 8:54
  • @Friedrich means xnoremap, not vnoremap. It would also be good to suggest the "swap" (nnoremap W w) so that you can still navigate by words as needed.
    – D. Ben Knoble
    Commented May 21 at 16:18
  • Thanks Friedrich and Ben, have edited these into my answer
    – husB
    Commented May 21 at 17:05
  • @D.BenKnoble I see no reason to exclude select mode (although I never use it). That's probably why I'm not aware why to prefer :xnoremap to :vnoremap. Would you care to elaborate?
    – Friedrich
    Commented May 21 at 18:16
  • 1
    @Friedrich in select mode (which I admittedly rarely use), the “printable” keys delete the selected text and start inserting (like a traditional editor: highlight with mouse, type to wipe away and insert new content). So mapping characters like w, b in select mode doesn’t make sense, usually.
    – D. Ben Knoble
    Commented May 21 at 20:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.