Tips on vi


Show options

To show all options and their current values, use the following command.

:set all
To confirm the specific optiona, use the following command.

:set option-name?

View files in hex format

Command to change to hex view.

Command to change to normal(ascii) view.
:%!xxd -r
On some platforms where xxd is not available, you may try to use od (octal dumping program) command like this.

:%!od -A d -x
For more about od, refer the following

Confirm and change current encoding in vi editor

With vi open, you can confirm the encoding used to display the current text of file with the following command.

:set encoding?
If the current coding is not proper with the file to read, you can change the encoding using set encoding command like the following.

:set encoding utf-8
The above sample is when changing to utf-8.
To list available encodings, you can use the following command.

:help encoding-names

Show line numbers

To show line numbers with vi editor, you can use the following command.

:set number
To hide line numbers, use the following command.

:set nonumber

Ignore case-sensitiveness and disable file wrapping in search

By default, vi searches the file in case-sensitive mode. To change the mode, you can use ignorecase option.

:set ignorecase

To get back to case-sensitive mode, you can use noignorecase option.

:set noignorecase

There are another option, smartcase. For more on it, refer http://vimdoc.sourceforge.net/htmldoc/usr_27.html#27.1

By default, vi searches the file in wrapping around mode. That means when a search reaches the end of file, the search automatically goes from the begging of the search, so, the forward searches with more than one hits never end. To turn off this wrapping, you can use nowrapscan option.

:set nowrapscan

Per-user configuration

In default configuration file, .vimrc or _vimrc, add the path for a per-user configuration using source command.

source ~/.vimrc

With per-user configuration file, you can customize vi to your taste.
The following is a typical per-user configuration

set fileencoding=utf-8
set fileencodings=utf-bom,utf-8,euc-kr,cp949,latim1
set backupdir=c:\\temp

set wrap
set smartindent
set tabstop=3
set shiftwidth=3
set nowrapscan
set number
set ruler

if has("syntax")
  syntax on


Post a Comment