Search code examples
vimkeyboard-shortcutscapitalization

How do I capitalize the first letter of a word in Vim?


For a long time I've known that I can use ~ in Vim to toggle the case of a character. But is there a way to map a key to capitalize a word and go back to the previous position?

For example:

I like to drink Coca co[l]

If my cursor is at "l" and I realize I need to make the "c" capitalize as well, currently, I need to do:

<C-c> b ~ ll i

Is there a way to map a single key to make the first letter of the word under cursor to be capitalized and keep the cursor at original position?


Solution

  • :nmap <whatever> m`b~``