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

Monday, April 15, 2013

Line numbers in Vim



I would like to cover all aspects known for me related to the line numbers in Vim.

CommandDescription
:0
move cursor to the first
:42
42gg
42G
move cursor to 42nd
:G
move cursor to the last


Show line numbers in current file
:set number

Hide line numbers in current file
:set nonumber

Wednesday, March 7, 2012

Dealing with Tabs in vim

To insert space characters whenever the tab key is pressed, set the 'expandtab' option:
:set expandtab

With this option set, if you want to enter a real tab character use Ctrl-V<tab> key sequence.

To control the number of space characters that will be inserted when the tab key is pressed, set the 'tabstop' option. For example, to insert 4 spaces for a tab, use:

:set tabstop=4

After the 'expandtab' option is set, all the new tab characters entered will be changed to spaces. This will not affect the existing tab characters. To change all the existing tab characters to match the current tab settings, use:
:retab

To change the number of space characters inserted for indentation, use the 'shiftwidth' option:
:set shiftwidth=4

For example, to get the following coding style,
*No tabs in the source file.
*All tab characters are 4 space characters.

use the following set of options:
:set tabstop=4
:set shiftwidth=4
:set expandtab

Add the above settings to your .vimrc.

Friday, March 25, 2011

Vim necessary commands

Reload the file with selected encoding:
:e ++enc=<encoding>