VIM 常用命令(節選自Unix and Linux Forum)

來源:互聯網
上載者:User

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.


=> 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 往下往上翻半頁






相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.