Showing posts with label vim. Show all posts
Showing posts with label vim. Show all posts

Monday, December 12, 2011

How to comment code in VI or VIM


Mark the area which is to be commented using the *blockwise* visual mode (CTRL-V, in Windows this is CTRL-Q).

Press I (capital i) and write the text you want to prepend to each line of the selected block, e.g. #####.

Then press ESC and the text will be inserted to the left of each line of the selected block.

Sunday, October 09, 2011

vim color tuning

A great way to tune color automatically in vim is by calling:

set background=dark

Since the default on linux is "backgroun=light"

I have also placed this inside the /etc/vimrc to have a global effect

Saturday, October 01, 2011

VIM ignoring case search

Just type:
:set ignorecase



and to return back to normal:
:set noignorecase


If you would like to search case insensitive one time only without changing the mode in vim, for example lets search for the word "earth" case insensitively:

/\cearth

The \c character tells vim that the search should be case insensitive.

Thursday, September 29, 2011

Deleting all lines that are empty or contain spaces in vim

To delete all lines that are empty in vim:

:g/^$/d

To delete all empty lines or empty lines that contain spaces:

:g/^\s*$/d

Note that \s represents the space character in the regular expression. Or simply, you can also represent the space character with [ ]:

:g/^[ ]*$/d

Pasting code into VIM without the indentation problem

Frequently, when pasting code into vim, i get lots of indentation spaces that really frustrate me.
I discovered that this vim issue can easily be handled by typing in the command mode in vim:

:set paste

Then going to insert mode and pasting the source code.

Disable Autoindent in VIM

To disable autoindent in vim, you can do the following:


:set noautoindent | set nosmartindent | set nocindent

Or place the folowing lines in your .vimrc (linux) or _vimrc (windows):

set noautoindent
set nosmartindent
set nocindent