Vim Editor 1

Source: Internet
Author: User

Vim Editor VI improved

Vi:visual interface

Vim +/pattern F1 After opening the file, the cursor is at the beginning of the first line that is matched to PATTERN, and the N key jumps to the next, that is, the regular match is supported

Vim +n F1 Open the F1 file directly and position the cursor on nth line

Vim-b F1 to open files in binary mode

Vim-d F1 F2 ... Compare multiple Files

Vim-m F1 Open File as read-only

Ex F1 or vim-e F1 directly into ex mode


VI +/^user passwd

VI or VIM supports regular expression matching, that is, open the passwd file and position the cursor at the match to the line beginning with the user


Vim mode:

Command mode (normal): Default open mode, move cursor, cut paste Delete, etc.

Insert mode or edit mode (insert): Modify text

Extended Command mode (Extended command): Save, Exit, help,: number after plus commands

Visual mode (visual): Block selection operation

ESC key to exit the current mode. Press the ESC key two times to return to command mode

I:insert, inserting before the cursor

I: Insert at the beginning of the cursor

A:append, inserting after cursor

A: Insert at the end of the line where the cursor is located

o: Insert a new row below the line where the cursor is located

O: Insert a new row above the line where the cursor is located


Locking and unlocking: ctrl+s,ctrl+q

Extended mode:

: Q exit

: q! Force quit do not save changes

: Wq Save Exit

: X Save exit

: R F2 reads F2 file contents to the next line of the current cursor

: W F3 writes the current edits to another file

!cmd Execute command and display, enter exit

R!cmd reads the output of the command to the next line of the current cursor

: The arrow keys can choose the history command of VI, operation with Bash, supported shortcut key operation ^w,^u,^e


Command mode:

ZZ: Save exit

ZQ: Do not save exit

HJKL: Lower left upper right move

#cmd: 3h moves left 3 characters

W: The next word in the first word

E: Current or next word ending

B: Current or previous word header

#cmd: 3w Jump down 3 words

H: Skip to Current page top M: page L: Bottom

^: Jump to the first non-whitespace character at the beginning of a line

0: Jump to the beginning of the line, note that the number zero

$: Jump to end of line

#G或者: #: Jump to the specified line, 3G third row,: 10 line 10th

Shift+3: # #, match the word at the cursor and highlight all the same words in the file, N-Key jump

G: Last line

1G,GG: First line

): Next sentence (: last sentence.) The sentences are separated by.

}: Next paragraph {: previous paragraph. Paragraphs are separated by a blank line

CTRL+F: Flip a screen to the end of the file

CTRL+B: Flip a screen to the file header

Ctrl+d: Turn half screen at the end of the file

Ctrl+u: Turn half screen to file header

X: Delete the character at the cursor

#x: Remove the # characters after the cursor

XP: Swap the position of the character where the cursor is located and the character after it

~: Convert Case

R: replace 1 characters at cursor location, 3r three characters

R: Full replacement mode, ESC exits

D: Delete range, can match the direction key HJKL Delete the current line and the same direction row

d$: Delete to end of line

d^: Delete to non-empty header

D0: Delete to the beginning of the line

Dw,de,db

DD: Delete Row, 3dd down delete 3 rows

D: Delete from the cursor's current position to the end of the line, leaving blank lines equal to d$

Y: Copy, Y$,y0,y^,ye,yw,yb

YY: Copy line, y copy entire row

P: lowercase, paste the line below the current cursor, if the text is pasted behind the cursor

P: Uppercase, if the line paste is pasted at the current cursor on the top of the line, if the text is pasted in front of the cursor

C: Switch to insert mode after modification

C$,c^,c0,cb,ce,cw

CC: Delete the current line and enter new content

C: Delete the current cursor to the end of the line and switch to insert mode


100iroot[esc] paste root 100 times

0y$: Combo command: 0-Move to the beginning of the line, y copy from here, $-copy to the last character of the bank

Ye: Copy from current position to the last character of this word

GU: Variable Capitalization

GU: variable lowercase


Extended Command mode: start with: For the command, shown in the lower left corner, the following: omitted, no longer explained

#,#:3,9: From line 3rd to line 9th

#,+#:3,+4: From line 3rd to line 7th

.: When moving forward

$: Last line., $-1: Current line to the second penultimate line

%: Full text, equivalent to 1,$


VIM supports regular expressions, in extended command mode

/PAT1/,/PAT2/: From the first time the PAT1 pattern is matched to a row, until the end of the line that was first matched to the PAT2

#,/pat/,/pat/,$

How to use: followed by an edit command

D,y,w,r

W F3: Saves rows in the specified range to the specified file

R F2: Inserts all content from the specified file at the specified location

Vim +/usera passwd jump directly to the UserA line

:/^bin/,/^halt/y copy lines beginning with bin, ending with halt

/word: Looking down from the cursor

? Word: Looking up from the cursor

N: With the command in the same direction N: With the command inverse direction

s/what to look for/replace content/modifiers: Find and replace

S/root/rooter/g

s/root/&er/g Ibid.,& to refer to what was previously found

S/r. T/&er/g shorthand, using regular mode

S/r. T/user:&/g Regular

Modifier: I ignores case, G global substitution, GC global substitution, ask before each replacement

Find separators in substitutions/can be replaced with other characters, such as #@+, to facilitate the replacement of paths such as:

[Email protected]/[email protected]/[email protected]: replace/etc with/VAR, replace All

s#/boot#/#i: Replace/boot with/and ignore case

VI fstab

:%s/^#/*/indicates that lines beginning with # are replaced with * beginning with *

: 1s/root/root/g replaces root of the first line as root

: 1s/root/a&b/g

:%s/^#//means Delete comment #

:%s/^uuid/#&/

:%d empty file

:%[email protected]/dev/[email Protected]/etc/[email protected]


Command mode: Undo Changes

U: Undo Recent Changes, 3u undo 3 times before

U: Undo all changes to this line, as the cursor must always be positioned on this line, otherwise invalid

Ctrl+r: Redo

.: Repeat an action

N.: Repeats the previous action n times


Recording macro: Command mode

QA//Start recording macro, name a

Operation Edit ... Start operation

Q//Exit Edit operation

@a//Run macro A

@@//Repeat macro execution


Vim Registers:

There are 26 named registers (A,B,C...Z) and 1 unnamed registers

Name Register format: "register name. Placed between a number and a command, such as 3 "tyy means copying 3 rows into the T register

If no name is specified, an unnamed register is used: 3yy for copying three rows to the untitled register


There are 10 digital registers (0-9) 0 for recent replication and 1 for recently deleted content. Change 1 dumps to 2, 2 dumps to 3, and so on, the digital registers cannot be shared between different sessions.

Format: Number "register command, 5" BDD, without designation use unnamed register 4 "Y

3yy: Copy 3 rows

3 "AYY: Copy 3 rows to a register

"AP: Paste the contents of a register


To edit a binary file step:

DD If=/dev/zero OF=B1 Bs=1 count=6

Hexdump B1

Hexdump-c B1

Vim-b B1

:%!xxd switch to readable hexadecimal

To edit a binary file

:%!xxd-r back into binary

: Wq Save Exit


Visual mode:

V Character-oriented

V Line-oriented

Ctrl + V for block

Visual keys can be used in conjunction with mobile Keys, W,),}, arrows, etc.

Highlighted text can be deleted, copied, changed, filtered, searched and replaced


Multi-file Mode:

Vim F1 F2 F3 ...

: Next Next

:p Rev A previous

: First One

: Last One

: Wall Save All

: Qall Quit all

: Wqall


Multiple windows:

Vim-o F1 F2

O: Horizontal split, O: Vertical split

CTRL+W switching between windows

Single File window split, repeatedly open the current file, Windows Ctrl+tab switch, in order from the top down, from left to right.

: vs Around

: SP up/Down

CTRL+WW window switch, same as Ctrl+tab

CTRL+WH switch to the left window, WL right window, WJ down, wk up. HJKL Lower left upper right

Ctrl+w,s Horizontal split, split

Ctrl+w,v Vertical Division, vertical

Ctrl+w,q Cancel Adjacent window

Ctrl+w,o Cancel All Windows

: Wqall exit


Customizing the VIM configuration file

Global/ETC/VIMRC, Personal ~/.VIMRC

Set [No]nu line number

Set [NO]SM bracket pairs match

Set [No]ai Auto Indent

Set [No]hlsearch Highlight Search

Set [No]ic ignores character case

Syntax On[off] Syntax highlighting

Set Fileformat=dos Enable Windows format

Set Fileformat=unix enable UNIX format


"Set Text width

: Set textwidth=65

: Set wrapmargin=15

: Help Option-list View a list of all options

: Set Or:set All view all set settings

: source% makes the currently edited configuration file effective (abbreviated as: so%), editing window cannot be closed

Vimtutor command line open directly, can be freely edited, closed after automatic restoration, used to practice vim command

E. Open current Directory

: Echo $MYVIMRC shows the path to the VIMRC configuration file

: Source $MYVIMRC

Nmap, Ev:e $MYVIMRC <cr> define shortcut key editing VIMRC

: Tabedit $MYVIMRC newly opened tab page

: Tabclose Close the current tab

Nmap, Ev:tabedit $MYVIMRC <cr> via shortcut keys, Ev opens VIMRC profile in new tab


Combine multiple function operations by setting up a unified shortcut key first Mapleader

"--------------Mappings---------------"

Let Mapleader = ","

Nmap <leader>ev:tabedit $MYVIMRC <cr>

Nmap <leader><space>:nohlsearch<cr>

Nmap <leader>w:w<CR>


"Automatic loading of VIMRC files

Augroup autosourcing

autocmd!

Autocmd bufwritepost _VIMRC source% Auto Load VIMRC file

Augroup END


"Window toggle, ctrl+j down, ctrl+k up, Ctrl+h left, ctrl+l right

Nmap <c-j> <c-w><c-j>

Nmap <c-k> <c-w><c-k>

Nmap <c-h> <c-w><c-h>

Nmap <c-l> <c-w><c-l>


"Set the TAB key to 4 spaces

Set ts=4

Set Expandtab

Set Autoindent


This article is from the "Rackie" blog, make sure to keep this source http://rackie386.blog.51cto.com/11279229/1931946

Vim Editor 1

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.