tags:

views:

110

answers:

3

For a long time, I know in vim we can use "~" to toggle the case of a character. Though, 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?

+5  A: 
:nmap <whatever> m`b~``
Ignacio Vazquez-Abrams
Wow, thanks for quick reply. This is exactly what I'm looking for!
Patrick
+4  A: 

Have a look here.

Bozhidar Batsov
This is a good guide, too. Thanks for sharing.
Patrick
A: 

you can also use macro

q<register> <C-c> b ~ ll i q

and then do @<register> every time you need to use it.

Amir Rachum
The problem with this approach is that the length of "ll" is uncertain for every word.
Patrick