Common Vim commands (Excerpted from UNIX and Linux Forum)

Source: Internet
Author: 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, 20 W filename
=> Writes the line from 10th line to 20th line in given file name

 

Bytes ------------------------------------------------------------------------------------------------------------


 

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

 

Bytes ------------------------------------------------------------------------------------------------------------

 

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


 

Bytes -------------------------------------------------------------------------------------------------------------------------------

 

: 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

 

Other common features:

1. Insert a column (frequently used for comments)

(1) Ctrl + V entering visual Block Mode

(2) Select a part, hold down SHIFT + I, and type the content to be inserted.

(3) ESC.

 

2. gg jumps to the beginning and G to the end of the text.

 

3. W jump to the next beginning B and jump to the first.

 

4. $ jump to the end of the line, ^ or 0 to the beginning of the line

 

5.: Set nu displays the row number

 

6. Press Ctrl + F Ctrl + B to flip the page forward

 

7. CTRL + D Ctrl + u move up half page






Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.