Vim Program Editor

Source: Internet
Author: User
Tags modifier line editor

Text Editor:

Line Editor: SED

Full Screen Editor: Nano,vi,vim


Vim Program Editor

Vim can be considered an advanced version of VI

Vi:visual Interface Full Screen text editor

VIM:VI improved improved full-screen text editor

Vim Tutorial:

Vimtutor


Modal Editor:

Edit mode: Type command completion cursor move, text copy, move, delete

Input mode: can be edited for any content

Last-line mode: Enter command to decide how to save and leave


Switch between modes:

Vim opens the file directly into edit mode;


Edit mode-à input mode

Input I,i,a,a,o,o,r,r can enter input mode (insert modes)

I: Insert from the current cursor location;

I: Start inserting from the first non-whitespace character at the line where the cursor is currently located;

A:append append input from the current cursor;

A: Insert from the end of the line at the beginning of the current line;

o: Insert a new line from the next line in the row where the cursor is located;

O: Insert a new line from the previous line on the row where the cursor is located;

R: Replaces only the character of the cursor at a time;

R: Always replace the text of the cursor until the ESC key is pressed


Input mode-à edit mode

ESC exits input mode and returns to edit mode


Edit mode-à last-line mode

: Enter the last line mode from edit mode


Last-line mode-à edit mode

ESC exits the last line mode and returns to edit mode


Open vim

#vim Open the VIM program editor

#vim/path/to/somefile to open the specified file

+#: #为行号, after opening the cursor to the beginning of the # line

+/pattern to select the cursor position by mode


Turn off vim to turn vim off in last-line mode

: Q Quit Vim

: q! If you have modified the file, do not save the exit, use! Force quit, do not save

: w Save the edited file

: w! If the file property is read-only, forcing the file to be written can eventually be saved, depending on the permissions on the file

: Wq to exit after saving

: wq! Quit after forcing save

: X Save exit

ZZ Capital ZZ If the file has not changed, then do not save leave, if the file is changed, save and exit

: w [filename] Saves the edited file as another file similar to save As

: R [FileName] in the edited file, read in another file, add the contents of the filename file to the line of the cursor behind

: #,# w [filename] Saves the contents of the # line to the # line as a filename file


Cursor Jump: In edit mode

Jump between characters:

H: The cursor moves one character to the left

L: The cursor moves one character to the right

J: Move the cursor down one character

K: The cursor moves up one character

#COMMAND: Jumps to the specified number of rows, such as 10k up 10 rows

In-line jump:

^: Jump to the beginning of the first flying white space character

0: Jump to the absolute beginning

$: Jump to absolute end of line

Move between rows

#G: Move to Line # of file

1G,GG: Move to the first line of the file

G: Move to the last line of the file

Move between sentences:

): Jump to the next sentence

(: Jump to the previous sentence

Move between paragraphs

{: Jump to the beginning of the next paragraph

}: Jump to the beginning of the previous paragraph


Edit command:

Character Editing commands:

X: Large x to remove a character forward, equivalent to backspace

x: Lowercase x Deletes one character backwards, equivalent to Del

#x: Remove the back # characters at the cursor location

XP: Swap the character at the cursor and a character position at the back


Delete command:

D:

d^ Delete all characters at the beginning of the cursor

d$ Delete all characters at the end of the line at the cursor

D0 Delete all characters at the beginning of the cursor

Dw,de,db,dg

DD: Delete cursor in the row

#COMMAND

Note: Deleting content is saved to the buffer by the VIM editor


Paste command: P (paste, put)

If the previously copied or deleted content is not a complete line:

P Lowercase: Paste at the back of the current cursor

P Capital: Paste at the front of the current cursor

If the copied content is a full row (can be more than one line)

P Lowercase: Pasted below the current cursor line

P Capital: Paste to the line above the current cursor


Copy command: Y, yank

Y:

YY: The line where the cursor is copied

#yy: Copy the Down # line where the cursor is located

#COMMAND

Y1, y1g, YG, y$, y^, y0, ye, yw, yb


Changing commands: C, change both file editing and mode conversion

C$,C^,C0,CB,

Ce,ce,cw

CC: Delete cursor line, enter insert mode

#COMMAND


Undo the previous editorial work

U:undo

Undo the previous edit operation

#u

Ctrl+r Recovery of previous revocation work

.: Repeats an edit operation


Turn screen operation :

Ctrl+f: Screen down one page

Ctrl+b: Screen up one page

Ctrl+d: Screen moves down half page

Ctrl+u: Screen moves up half page


Example:

# Vim/tmp/test/test_vim +3

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/B7/wKioL1XsAaCyhInHAABTEnUz3KE201.jpg "/>

# Vim/tmp/test/test_vim +/^a

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/BA/wKiom1Xr_3nQGNB8AABIjU6QOP4001.jpg "/>


Last-line mode:

(1) Address, delimitation

: Start_pos,end_pos

#: Line #

#,#: From # line to # line

#,+#: From # Line to section #+ #行

.: When moving forward

$: Group after row

%: Full text, equivalent to 1,$


/PAT1/: The first time the line is matched to this pattern;

#,/pat1/: Starting from #, the first line to be matched by this pattern

/pat1/,/pat2/: The first line that is matched by this pattern to the row that is matched to the second time

You can follow the edit command:

Y,w,r


(2) Find

/pattern: Searching the tail

? PATTERN: Searching for the header

N: Same direction as command

N: Opposite direction of command


(3) Find and replace

S: In the last-line mode, the Find-and-replace operation is done within the bounds of the ground-setting

s/ What to look for / what to replace with / modifier

What to look for: Available modes

What to replace: You cannot use a pattern, but you can use a back reference symbol to refer to what the grouping brackets in the preceding pattern match to;

\1, \2, ...

&: Refers to the entire content of the "What to find" matches;

Modifier:

I: Ignore case

G: Global Substitution

C: Prompt the user to confirm whether to replace

/: Used for delimiters, so, to find the content or replace with the content that appears in this symbol, to use \ to escape it, use format: \/

The delimiter can be replaced with other characters: @, #等, for example;


Multi-file Mode:

Vim FILE1 FILE2 ...

: N Edit Next file

: N Edit Previous file

: Files lists all the files that are currently open by this vim

: Next edit Next file

: First editing of a file

:p Rev Edit Previous file

: Last edit Final file


: Wqall Save and exit all open files

: Q!all force quit all open files


Multi-File Window segmentation:

Vim-o|-o FILE1 FILE2 ...

Ctrl+w, arrow (arrows) Toggle window

Single File Window segmentation:

Ctrl+w, S:split, horizontal split

Ctrl+w, v:vertical, vertical split


Some of the working features of the custom vim:

(1) Line number

Display: Set Nu

Disabled: Set Nonu

(2) Bracket matching

Display: Set SM

Disabled: Set NOSM

(3) Auto indent:

Set AI

Set Noai

(4) Highlight Search

Set Hlsearch

Set Nohlsearch

(5) Syntax coloring

Syntax on

Syntax off

(6) Ignore character case

Set IC

Set Noic


: Help for assistance

: Help SUBJECT


The permanent effect of the feature setting is as follows:

Global configuration file:/ETC/VIMRC

User profile: ~/.VIMRC default does not exist can be created manually

# Vim ~/.VIMRC

1 "This file says quotation marks are comments

2 set Nu "Display line number

3 Set Hlsearch "highlight

4 Set autoindent "Auto Indent

5 syntax on "Syntax detection color display


Practice:

1. Copy the/etc/grub2.cfg configuration file to the/tmp directory and use the Find replacement command to delete the white space character at the beginning of the/tmp/grub2.cfg file; CentOS:/etc/grub.conf

%s/^[[:space:]]//g


2. Copy the/etc/rc.d/init.d/functions file to the/tmp directory, and add a # to the beginning of the line beginning with a blank character for each line of/tmp/functions with the find replacement command; The original whitespace character is reserved;

%s/^\s\+/#&/g


3, replace the/etc/sysconfig/init in/tmp/functions file is/var/log;

%[email protected]/etc/sysconfig/[email Protected]/var/[email protected]


4.Delete the line at the beginning of the/tmp/functions file so # starts with # and at least followed by a blank character #

%s/^\ (#\) \ (\s\+\)/\2/g



If there is any mistake, please correct me!

Thank you!

Vim Program Editor

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.