Linux Vim detailed

Source: Internet
Author: User

Vim mode

The VIM mode is divided into edit mode (command mode), input mode, and last line mode.


Mode to switch to each other:

Input mode--edit mode: ESC

Edit mode--and last-line mode::

Last-line mode--edit mode: ESC

Edit mode--Input mode:

I:insert (enter characters before the cursor)

A:append (enter characters after the cursor)

O: Add a row below the current line of the cursor and enter data in the newly added row

O: In contrast to O, add a row above the current line of the cursor and enter data in the newly added row

I: Enter a character at the beginning of the cursor

A: Enter a character at the end of the line of the cursor

Open VIM:

Vim/filepath

Vim +num/filepath: Cursor jumps to NUM line and edits the file

Vim +/search/filepath: Cursor jumps to SEARCH mode and edits the file


Turn off VIM:

: Q Exit directly

: q! Do not save forcibly quit, when the file has been modified, and you do not want to save,: Q is not able to exit, so the use of the item

: Wq Save and exit

: X Save and exit


: Wq and: X difference:

: Wq: Force write even if the file is not modified, and update the file's modification time.

: x: write only when the file is modified and update the file modification time, otherwise the file modification time will not be updated.


Cursor Jump:

Jump between characters:

H|←: Left

l|→: Right

K|↑: Up

J|↓: Next


Jump between words:

W: The first word of the word

E: The ending of the current or subsequent word;

B: The first word of the current or previous word;


In-line jump:

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

0: Jump to the beginning of the line;

$: Jump to end of line;


Move between rows:

#G: Line #

1G, GG: Back to the line

G: Back-end line


Move between sentences:

): Move to the next sentence

(: Move to the previous sentence


Paragraph movement:

}: Move to the next paragraph

{: Move to the previous paragraph


Edit command:

Character editing:

X: Delete the character at the cursor location

#x: Remove the # characters that are located at the cursor

XP: Replace the position of the current character and the next character

R: the character at which the cursor is replaced


Delete command:

d^: Delete the first non-whitespace character of the cursor to the beginning of a line

D0: Delete cursor to beginning of line

d$: Delete cursor to end of line

DD: Delete the line with the cursor (and cut function)

#dd: Delete the # line after the cursor


Note: The deleted content will be saved to the buffer by the Vim editor;


Paste: P (paste, put)

If this copied or deleted content is not a full line

P: Paste at the back of the current cursor;

P: Paste at the front of the current cursor;


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

P: Paste below the line where the current cursor is located;

P: Above line;


Copy command: Y, yank

y^: Copying the first non-whitespace character of the cursor to the beginning of a line

Y0: Copy cursor to beginning of line

y$: Copy cursor to end of line

YY: Copy cursor row (with clipping function)

#y: # lines after copying the cursor


Alter command: C, change (deletes the specified content and enters input mode at the current cursor)

Also C $, c^, C0, CC, #cc


to undo a previous edit operation:

U:undo actions before undoing

Ctrl+r: Redo Previous undo operation

. : Repeats the previous edit operation


Turn screen operation:

ctrl+f: one screen backward;

Ctrl+b: one screen ahead;

Ctrl+d: Back half screen

Ctrl+u: Forward half screen


Vim's last-line mode


(1) Address, delimitation

: Start_pos,end_pos

#: Line #;

M,n: line m to n rows

M,+n: line m to M after row n rows

.: When moving forward

$: Last line

%: Full text, equivalent to 1,$

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

#,/pat1/: Line # line to next PAT1 pattern matches to row

/PAT1/,/PAT2/: The line to which PAT1 matches the line to PAT2


After you can follow the edit command: d,y,w,r


(2) Find

/pattern: to the tail

? PATTERN: To the header

N: Same direction as command

N: Opposite direction of command


(3) Find and replace

S: In the last line mode, the search and replace operation is done within the bounds of the address;

s/what to look for/replace with content/modifiers

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 ( if no line is added, only one match is replaced )

/: 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 ...

: Next jumps to the next file

: First jumps to file one

:p rev jump on a file

: Last jump to final file

: Wqall save to exit all files

: Q!all force does not save exit all files


Multi-File Window segmentation:

Vim-o|-o FILE1 FILE2 ...

-O Horizontal Split window

-O Vertical Split window


CTRL + w,↑↓←→ Switch 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


The visual mode of VIM

V: Enter the character visualization mode, at which point you move the cursor, the characters you move to are highlighted, and then you can d,y and so on.

V: Enter line visualization mode. You can select N rows at this time

Ctrl + V: Enter block visualization mode.

ESC: Exit Visualization mode


Actual combat:

1, copy the/etc/grub.conf configuration file to the/tmp directory, use the Find replacement command to delete the/tmp/grub.conf file at the beginning of the blank character;

Answer:

1.cp/etc/grub.conf/tmp

2.vim/tmp/grub.conf

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/AC/wKiom1Xq6YWS8dcxAAIzcKzTnnA928.jpg "title=" Vim1.png "alt=" Wkiom1xq6yws8dcxaaizckztnna928.jpg "/>

3. Input:%s/^[[:space:]]\+//g

4. The final results are as follows

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/A8/wKioL1Xq7IayKMkxAAIHpDxZ3AM789.jpg "title=" Vim2.png "alt=" Wkiol1xq7iaykmkxaaihpdxz3am789.jpg "/>



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;

Answer:

    1. Cp/etc/rc.d/init.d/functions/tmp

    2. Vim/tmp/functions

    3. :%s/^[[:space:]]/#&/g



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

Answer: :%s#/etc/sysconfig/init#/var/log#g


4. Delete all lines beginning with # in the/tmp/functions file with # followed by at least one white space character at the beginning of the line #;

Answer: :%s/^#\ ([[: space:]]\+\)/\1/g




This article is from the "Wind Rhyme" blog, please be sure to keep this source http://chinalx1.blog.51cto.com/2334265/1691646

Linux Vim detailed

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.