Vim Tips

Here are some nice tips and tricks I learned while practicing VIM at work or at home.

Setting VIM's syntax highlighter to a particular language

The answer is a single command: setf
(setf markdown, setf javascript, etc)

Look up docs about a function, a command, anything

When your cursor is on a word, press shift+K.

Delete efficiently

dtx => d__eletes unt__il x (NOT including character x). It's super useful to delete until the next parens. For instance: dt) or dt{
ctx => lets you go to insert mode after deletion (c__hange vs __delete)


Ctags are pretty old fashioned but they work surprisingly well. I use them mostly at work when diving into unfamiliar Python code.
ctrl+] lets you lookup a symbol, ctrl+T brings you back to where you were.


Vim has native autocomplete!
ctrl+N to trigger autocomplete and ctrl+N/ctrl+P to iterate over suggestions. By default Vim searches the current file and opened buffers.

Editing multiple files

You can start Vim and tell it to open multiple files vim file1 file2 file2.

Better still: when inside of Vim you can tell it to edit a bunch of files.
Let's say I want to edit all my .scss file. I'd type :args path/to/css/files/*.scss. Magic! Now I can do edits, and type :wnext to save and switch to the next file in the list. I can also type :args to see which files have/have not been edited yet.

Last tip about this: vim -p path/to/css/files/*.scss will open a Vim session with all .scss files, each one opened in a different tab. How awesome is that.

Personal .vimrc

Each vim user has to have his/her personal .vimrc. I open sourced mine on Github, over there: