8 Eylül 2012 Cumartesi

vi Commands: Basic and Useful

Basic Commands

To open a file in vi fire following command from terminal:
vi myFile.txt

Be patient! Don't start to write immediately, because you are not in so called "Insert" mode. Use one of the followings to enable editing:
Using i causes to insert all what you type before the cursor position. Using a causes to insert after the cursor position.

Edit file as you wish, then just press to ESC to leave the insert mode and you are in command mode again.

Saving and Closing

To write changes to disk:

To write changes to disk and close the file:

To close the file if no change made:

To close the file without writing changes to disk:

To write changes to disk, when root permission required but vi not opened with this permission:
:w !sudo tee %


When editing a file, you need to navigate inside the file frequently. For example, you need to going to end of the file:
Or, you need to going to a specific line number, say 123:
Of course you want to display line numbers in this case (use one of the followings):
:set nu
:set number


If you don't like 8 as tab size like me, you can change it to 4 with this command:
:set ts=4
If you want to apply last two commands to all files which will be opened in future without retyping for each file, write this command in shell prompt (not in vi):
EXINIT="set nu|set ts=4"; export EXINIT
You can add other commands separating with the pipe: |


To cut a line:
To copy a line:
To paste a line after current line/cursor position:
To paste a line before current line/cursor position:
To undo last change:


To start visual selection:
To start visual line selection:
To start visual block selection:
To select three lines, current and next two:
To select three lines, current and previous two:
To select up to end of line:

Useful Commands

Swap current line with next line:
Swap current line with previous line:

Hiç yorum yok:

WSO2 ESB + ClientAccesPolicy.xml + CrossDomain.xml

ClientAccesPolicy.xml and CrossDomain.xml files have to be found at root of your services Silverlight and Flex clients to be able to acce...