June 19, 2016

Quick Vim Tips

02:59 Posted by Durga swaroop Perla , , , , No comments
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 in the Vim series, but individually not extensive enough to get their own dedicated article.

So, here are some useful tips for Vim

1. 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
2. Open a link in a browser from vim
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
3. 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
4. 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"
  execute "normal! `z"
So, that is all for this Quick tips article. More will be coming in the future. So, stay tuned.
Happy Vimming!
PS: To see all the vim tutorials of FreBlogg , visit : VimTutorials.org

If you have liked this article and would like to see more, subscribe to our Facebook and G+ pages.
Facebook page @ Facebook.com/freblogg
Google Plus Page @ Google.com/freblogg


Post a Comment

Please Enter your comment here......