Posts

Showing posts with the label Vim

Comment & Uncomment multiple lines in Vim

Baba Gyani Triviani said: " When someone said 'No Comments' I just had to intervene. No comments? Have multi-line comments my friend! " Commenting and uncommenting multiple lines in Vim can be a little tricky. Here is a small snippet of code to show how you can do this. I have done this for just a few of languages. But you can extend this to any number as per your choice. Save the following into a file and call it vcomments.vim Once this is done, open your ~/.vimrc  file if it exists, or create a new one. There, put the following code. :source ~/ vcomments.vim :map <C-a>  :call Comment()  <Enter> :map  <C-b>  :call Uncomment()  <Enter> Where you can replace a and b of and by whatever is convenient to you. This just calls the functions when the Ctrl + <key>  combination is hit. To use it, just select the lines to comment by using Shift + v and moving cursor up or down to select lines. Then, hit the Ct...

Common VIM Mappings to make life easier

Swami Nikhilaananda said: " When you transition from a known to an unknown, the similarities allow the transition to become smoother " If you have not checked out the previous post about Vi(m) editor , now is the time to read it. Many times, we are used to common keyboard short-cuts like Ctrl + C to copy, Ctrl + v to paste, and so on. However, when we move to Vim, it is tedious to remember all the new shortcuts like y to yank (copy) and p to put (paste). To avoid that, I created a bunch of remappings to enable me to perform common tasks quickly using the same set of keyboard shortcuts that we are so used to. You can do it too. Just open your ~/.vimrc file. If it is not there, create it. Then, paste the contents below as is into the file. Save it and restart vim. These shortcuts will start working (in escape mode) set smartindent set tabstop=4 set shiftwidth=4 set expandtab set mouse=a se nu :map <C-a> GVgg :map <C-n> :enew :map <C-o> :...

VIM Editor [Some cool features]

Swami Nikhilaananda said: " There was a time when I thought Vim was just a bar of dish washing soap. " A text editor is one of the most important tools when writing code. There are tons of editors available. But from time immemorial two editors have always been very popular (and reasons for flame-wars) One is Emacs and the other is VI. Most Linux distributions come pre-installed with a VI called VIM - Vi Improved. However, the editor that comes pre-installed is not the full version. So, first step, go ahead and get the full package so that you can unlock all features.. VIM is also available on Windows. Download VIM here . Why VIM? Before I go to the cool features, I would like to clarify a couple of points. When there are so many awesome graphical editors out there, why should anyone even bother learning Vi? I had this exact question. I used to get annoyed with Vi in the beginning. The reason is simple. When you connect to other machines via ssh, you don't ha...