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:
i
a
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:
:w

To write changes to disk and close the file:
:x

To close the file if no change made:
:q

To close the file without writing changes to disk:
:q!

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

Navigating

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:
:123
Of course you want to display line numbers in this case (use one of the followings):
:set nu
:set number

Displaying

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: |

Editing

To cut a line:
dd
To copy a line:
yy
To paste a line after current line/cursor position:
p
To paste a line before current line/cursor position:
P
To undo last change:
u

Selecting

To start visual selection:
v
To start visual line selection:
V
To start visual block selection:
Shift+V
To select three lines, current and next two:
Vjj
To select three lines, current and previous two:
Vkk
To select up to end of line:
v$

Useful Commands

Swap current line with next line:
ddp
Swap current line with previous line:
ddkP

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...