Useful Vim commands and tips

When coding I often switch between both Vim and VScode. The main thing which always impresses me is the amount of commands which are in the editor. Vim is one of them editors the more you put into it the more you get out of it. I have listed some of the command which tend to use the most.

Useful Vim commands and tips

gg=G format code and indent all code. What this means is gg go to the top of the file, = means indent all code and G go to the end of

gt – Go to next tab, I tend to use tabs in Vim rather than buffers so this is useful for me

gT – Go to previous previous tab

* – This searches for all words under the cursor

:sort – This sorts all the lines by alphabetical order

:v/./d – This remove all empty lines from the file

q: – Shows a history commands which have been entered into the editor

:set syntax=html – Changes the syntax of the file to HTML this also works for css and other languages just replace the html with your language

gu – Makes the character lowercase

gU – Makes the character uppercase

Like most things in Vim the above command can be extended for example guu will make the whole line lowercase and 4gUw will make 4 words uppercase

dit – When coding in html remove all content in the html tag

ci{ – This is useful for css remove all the content in the {

>> – This indent code to the right

<< – Indent code to the left

ctrl+a – When the cursor is over a number increase by one

ctrl+x – When the cursor is over a number decrease by one

ddp – As in the wrestler this move the current line down by one line

Leave a Reply

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