7 Small Reasons to Love Vim

These are some cool things you can do with Vim that save time and can help prevent mistakes from mouse selection. They’re mostly little things, but altogether they make up an editing environment that I simply love.

1. NERDTree (Docs) file deletion

<Ctrl-L> to open NERDTree, hjkl to move, mdy to delete

2. Easymotion (Docs). Check out their example GIFs, and you’ll never see movement with the keyboard the same again.

3. Executing shell commands without changing windows

:!ls ~  :!rm -rf ~/old.txt

4. Deleting everything inside quotation marks, function blocks, parameters lists, or tags

di" di' di` di{  di(  di[  di< (Delete text within first matched pair)
dit   (Delete text inside first matched "tag" e.g.: <div>TEXT</div>)

5. Selecting/deleting large blocks of text

Selecting: V <Ctrl-F> (page by page)
           V 500j (select 500 lines)
Deleting: d500d (delete 500 lines)

6. Searching Dash (paid app, but worth it) using dash.vim (Docs)

:Dash each underscore  :Dash Vim

7. Deleting only blank lines on either side of the cursor

In ~/.vimrc:
" Ctrl-up/down deletes blank line below/above, and Ctrl-k/j inserts.
nnoremap <silent><C-Down> m`:silent +g/\m^\s*$/d<CR>``:noh<CR>
nnoremap <silent><C-Up> m`:silent -g/\m^\s*$/d<CR>``:noh<CR>
nnoremap <silent><C-j> :set paste<CR>m`o<Esc>``:set nopaste<CR>
nnoremap <silent><C-k> :set paste<CR>m`O<Esc>``:set nopaste<CR>

If you have more awesome Vim tricks, shoot them to me in the comments!

Leave a Reply

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