How to use vi on linux

vi is quite useful if you want to edit a file with a command shell.

maybe most of us are not familar of it, since we are too used of the GUI interface.

Here is some basic useage of this tool, and I will put all the original article at the bottom.


1. mode change

we as know, there are two mode of vi, edit mode and command mode.

edit mode for input, all the character in pressed on the keyboard will displayed in the editor;

command mode is for control, every character you input may have some special function, which will be particular illustrated below.

of course we can tell the mode from the indicator from the bottom of the eidtor.

a. from command to edit

'i' or 'a', change command mode to edit mode

b. from edit mode to command

use 'esc'


2. basic command

some are used so often, that I will mark it with different color.

ENTERING TEXT

i            insert text left of cursor
a            append text right of cursor

MOVING THE CURSOR

h            left one space
j            down one line
k            up one line
l            right one space


BASIC EDITING
x         delete character
nx        delete n characters
X         delete character before cursor

dw        delete word
ndw       delete n words
dd        delete line
ndd       delete n lines
D         delete characters from cursor to end of line
r         replace character under cursor
cw        replace a word
ncw       replace n words
C         change text from cursor to end of line
o         insert blank line below cursor
                  (ready for insertion)
O         insert blank line above cursor
                  (ready for insertion)
J         join succeeding line to current cursor line
nJ        join n succeeding lines to current cursor line
u         undo last change

MOVING AROUND IN A FILE


w            forward word by word

b            backward word by word

$            to end of line

0 (zero)     to beginning of line

H            to top line of screen

M            to middle line of screen

L            to last line of screen

G            to last line of file

1G           to first line of file

<Control>f   scroll forward one screen

<Control>b   scroll backward one screen

<Control>d   scroll down one-half screen

<Control>u   scroll up one-half screen

n            repeat last search in same direction

N            repeat last search in opposite direction

ZZ save file and then quit

:wq      save and quit

:w            save file
:q!            discard changes and quit file


3 search mode
this is very very useful if you are reading a log file.

a.press 'esc' to command mode

b.press '/' call the search input c. input the text you wan't to search.

And the cursor will moves to the first occurrence of that text.

To repeat the search in a forward direction, type

n

To repeat the search in a backward direction, type

N


the origin content is from:

http://www.washington.edu/computing/unix/vi.html

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值