Cool tips for vim users

      No Comments on Cool tips for vim users

Hello Folks, I have been using vim for about 2 years now. And it is my primary editor when it comes to editing text or coding(other than java ūüėČ ). Since I have been exploring vim for 2 years, I have learned some cool tips which vim users can use. These things are small but makes a big difference when you use them. So lets go through them one by one.

If you want to take a look at my vim-setup you can have a look here on github.

Uppercase and Lowercase conversion

below mappings takes care of converting a selected text into lower or uppercase.

Beautify JSON

For this mapping you have to have python installed on your system. This¬†mapping takes care of beautifying the json. And if the json is not proper it will show an error message. You can chose your own mapping instead of <leader>j¬†in my case leader is ‘,’

Do not create backup files

A lot of times vim creates some .swap¬†or some backup file etc. which we really don’t want and finally we have to remove them manually. Bellow settings tells vim that please do not create any backup files.

Show trailing spaces

Below config will show the trailing spaces at the end of the line.

Change cursor shape in different modes

In vim by default cursor show up as a square in all modes. I use this config to convert the cursor shape to pipe in insert mode.

Reload vim after making change in ~/.vimrc

The below autogroup will reload vim every time you write the ~/.vimrc file. If you put this in your ~/.vimrc file, you will never have to do source ~/.vimrc from the terminal.

Selecting text till the last character

If you use vim’s default $¬†to go to the end of the line it counts the \n(newline)¬†in it. To avoid that use the below mappings.
If you want to select something till end or till start of line use shift + l or shift + h respectively.

Use ; instead of :

To go to command mode in vim we use shift + ;¬†but actually if we see ; alone is not doing anything, then why not use it to go to command mode. It will help you to navigate to command mode faster and you don’t have to press two keys.

Deleting everything in the file

Generally we use 3 mappings to delete everything in a file, so why not combine them and use just one mapping.

Jump between relative and normal numbering

To jump between relative and normal numbering we go to command mode and type the command :set nu or :set rnu, instead we can map it to something simpler the easier to use. I use F2 and F3 for this purpose.

About Ajit Singh

Hi, I am Ajit Singh, author of I work on a lot of different technologies and tools. I started my career as a software engineer in Chennai (India) and recently I moved to Gurgaon near to my home town. I like reading and writing about technology.

Leave a Reply

Your email address will not be published. Required fields are marked *