Vim tips & tricks

February 23, 2015

Vim is a text editor based on vi editor common to Unix-linke systems. It is by far one of the most advanced cli editors. Note that there also are gui implementations. These are some of the commands i regularly use. I won’t add them all, so if you can’t find something here, use the manual. If I start using new ones often I will add them. If you notice one I should know about, please comment below.

Basics

vim file.text +[n] Open a file at linenumber
:[n] Jump to linenumber
:0 Jump to start of file

:$ Jump to end of file

/[search] Search for a string in the file. Find next by pressing n

Advanced
:%s/search/replace/g Search and replace a string
:set number Set line numbers

:set nonumber Disable line numbers

Nice to knows
:t Duplicate a line

:m Move current line after

Require extra software

:%!xmllint –format - Format xml

comments powered by Disqus