VIM 常用命令(节选自Unix and Linux Forum)

Forwarded from  http://www.unix.com/unix-dummies-questions-answers/132518-vim-tips-tricks.html

 

:w => Save [:w filename writes the content to the specified file from current file]

:q => Exit as long as there have been no changes

:q! => Exit and ignore any changes

:wq => Save and Exit.

:x => Exit, saving changes

ZZ => Exit and save changes if any have been made

:10,20w filename => writes the line from 10th line to 20th line in given file name

 

------------------------------------------------------------------------------------------------------------

 

i : Insert before cursor

I : Insert before line

a : Append after cursor

A : Append after line

o : Open a new line after current line

O : Open a new line before current line

r : Replace one character

 

------------------------------------------------------------------------------------------------------------

 

d^ : Deletes from current cursor position to the beginning of the line.

d$ : Deletes from current cursor position to the end of the line.

dw : Deletes from current cursor position to the end of the word.

dd : Deletes three lines from current cursor position downwards.(also :d)

yy : Yank the current line (also :y)

x : Delete a character next to the cursor

X : D elete character to the left of cursor

P : Paste line before the cursor

p : Paste line after the cursor

. : Repeat last edit command

u : Undo last edit (Ctrl+r redo)

U : Undo changes to current line

 

*** Ctrl+p word completion

 

----------------------- ----------------------- ----------------------- ----------------------- -----------------------

 

/pattern : search for pattern

?pattern : search backward for pattern

n :repeat search in same direction

N : repeat search in opposite direction

:%s/old/new/g : replace all old with new throughout file

:%s/old/new/gc : replace all old with new throughout file with confirmations

We can change the substitution delimiter instead of "/" to % or # or @ or !.

Refer the Following Link.

http://www.unix.com/unix-dummies-questions-answers/131585-changing-vi .html


:/pattern/= => Print the line number of the first line that matches pattern.

:g/pattern => Finds (moves to) the last occurrence of pattern in the file.

:g/pattern/p => Finds and displays all lines in the file containing pattern.

:g!/pattern/nu => Finds and displays all lines in the file that don't contain pattern;
also displays the line number for each line found.

:60,124g/pattern/p => Finds and displays any lines between lines 60 and 124 containing pattern

 

-------------------------------------------------------------------------------------------------------------------------------

 

: pwd Print the current directory name.

 

Visual mode.

Shift+v is to select a line
Ctrl+v is to select a block of text.

 

Encryption

 

:X

 

其他常用:

1. 插入一列(注释时常用)

    (1) ctrl+v 进入visual block mode

    (2) 选中一块,按住shift+I, 然后键入要insert的内容

    (3) esc 搞定

 

2. gg跳到文首,G跳到文末

 

3. w 跳到下个字首 b跳到一个字首

 

4. $ 跳到行尾, ^或者0跳到行首

 

5. :set nu 显示行号

 

6. ctrl+f ctrl+b 往前往后翻页

 

7. ctrl+d ctrl+u 往下往上翻半页



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值