freblogg-vim-image

Vim is one of the most powerful text editors available. And, hence it is not really possible for everyone to know everything or get the same ideas on improving their work experience. And, so this article includes a few tips and handy shortcuts that will help your productivity just as we have been doing with various Vim articles, but individually not extensive enough to get their own dedicated article.

So, here are some useful tips for Vim:

Change your directory locally

Usually to change the current directory in Vim, you would do, 

:cd <path/directory>

But that would change it in all open buffers. So, to change it locally either just in a window or rather just in a split window , you can use lcd.

:lcd $HOME    "change the directory locally to $HOME

Now, this is something that I have found out recently and has been very useful ever since.
Especially if you are some one who does a lot of documentation in Vim or some one who works extensively with HTML, this would be invaluable to you. Just put the cursor on the URL and press gx

gx  "opens a link in your default browser

Edit and source your Vimrc fast

If you are using vim as your editor, changing, updating vimrc becomes one of the things that you do very frequently. It can be adding new mappings, deleting the old ones or adding new plugins etc. What ever that is having these mappings will help you do that much faster.

Opens vimrc in a vertical split

:nnoremap <leader>r  :vsp $MYVIMRC

Source your vimrc to get the new changes.

:nnoremap <leader>sv  :source $MYVIMRC

Automatically delete trailing white-spaces

If you are one of those people (including me) who wouldn't like to have trailing white spaces at the end of lines, then you would absolutely want to have this in your vimrc file. This will take care of all those nasty white-spaces on all lines.

autocmd! BufWritePre * call DeleteTrailingSpaces()

function! DeleteTrailingSpaces()
  execute "normal! mzA "
  "Deletes all Trailing spaces"
  %s/\s\+$//g
  execute "normal! `z"
endfunction

So, that is all for this Quick tips article. More will be coming in the future. So, stay tuned.

Happy Vimming!



Published

Category

Software

Tags