How to use the first letter of a word in Vim?

For a long time, I knew that I could use ~ in Vim to switch the character case. But is there a way to match the key to make amends and return to the previous position?

For example:

I like to drink Coca co[l] 

If my cursor is in "l" and I understand that I need to do also "c", currently I need to do:

 <Cc> b ~ ll i 

Is there a way to map one key so that the first letter of the word under the cursor is uppercase and keep the cursor in its original position?

+17
vim capitalization keyboard-shortcuts
Jun 27 2018-10-06T00:
source share
4 answers
 :nmap <whatever> m`b~`` 
+15
Jun 27 '10 at 5:52
source share

Personally, this is exactly what I prefer not to do for the macro. There is no need to fill your .vimrc dozens of such one-time solutions, because the solution so naturally arises from the β€œtools” of the standard Vim commands that you can simply connect it like a second nature.

I type a long word:

 the gallicizatio| 

( | - cursor position). Suddenly, I realize that I forgot to use Gallicization. So bam !, I hit ESC (which is mapped to the cap lock key on my keyboard, so it only takes a little finger click) and then b~A , and I keep typing as if nothing had happened. This erroneous G was capitalized during the time that the Emacs user starts moving his right hand to the arrow keys, and I have already moved on to the rest of the sentence.

On the contrary, with a macro that I have not used for some time, it will probably take more time to remember which keys I assigned to this macro. The best solution is to very well learn the important "core" teams that can be combined on the fly in accordance with simple rules with millions of possible effects.

+9
Aug 10 2018-12-21T00:
source share

you can also use macro

 q<register> <Cc> b ~ ll iq 

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

+2
Jun 27 2018-10-10T00:
source share

I often do this and use the EX command line to get multiple records matching the condition. In this case, I use a backlink that looks like this:

:%s/\(\w\)\(\w*\)/\U\1\L\2/g

and BOOM, the problem is solved in all words that are in a specific context.

EDIT: Look here too, just realized if there was this link that has similar answers:

The capital letter of each word in the selection using vim

+2
Aug 02 '13 at 13:55 on
source share



All Articles