[Comanddetail] Vim

Source: Internet
Author: User

Character editing:

X: Delete the character at the cursor;

#x: Delete the # characters at the beginning of the cursor;


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


Replace command (R, replace)

R: the character at which the cursor is replaced


Delete command:

D: Delete command, can be combined with the cursor jump character, to achieve range deletion;

d$:

d^:

D0:


Dw

De

Db


#COMMAND


DD: Delete the line where the cursor is located;

#dd: Multi-line deletion;


Paste command (p, put, paste):

P: If the buffer is an entire row, the current cursor is pasted below the line, otherwise, it will be pasted at the back of the current cursor;

P: If the buffer is an entire row, the current cursor is pasted above the row, otherwise, it is pasted at the front of the current cursor;


Copy command (y, yank):

Y: Copy, work behaves similar to D command;

y$

Y0

y^


Ye

yw

Yb


#COMMAND


YY: Copying rows

#yy: Copy multiple lines;


changing commands (c, change)

C: Modify

Edit mode--Input mode


C $

c^

C0


Cb

Ce

cw

#COMMAND


CC: Delete and enter new content

#cc:


Other editing operations


Visualization mode:

V: Selected by character

V: set by row


Note: often combine editing commands;

D, c, y


To undo previous edits:

U (undo): Undo the previous operation;

#u: Undoes the specified number of operations;


Undo the previous undo:

Ctrl+r


Repeat the previous edit operation:

.


Turn screen operation:

Ctrl+f: Turn a screen at the end of the file;

Ctrl+b: Turn one screen to the file header;


Ctrl+d: Half-screen to the tail of the file;

Ctrl+u: Turn half screen to file header;


Vim comes with a practice tutorial:

Vimtutor


Last-line mode in VIM:

Built-in command-line interface


(1) Address delimitation

: Start_pos,end_pos

#: The specific # line, for example, 2 means line 2nd;

#,#: From the left # indicates the line start, to the right # indicates the end of the line;

#,+#: The start of the line from the left #, plus the number of rows on the right #;

.: When moving forward

$: Last line

., $-1

%: Full text, equivalent to 1,$


/pat1/,/pat2/:

Starting from the first line that is matched to the pat1 pattern, until the end of the line to which the first match is PAT2;

#,/pat/

/pat/,$


How to use:

followed by an edit command

D

Y

W/path/to/somewhere: Save the range of rows to the specified file;

R/path/from/somefile: Inserts all the contents of the specified file at the specified location;


(2) Find

/pattern: Looks at the end of the file from the current cursor location;

? PATTERN: From the current cursor location to the file header lookup;

N: In the same direction as the command;

N: Opposite direction with command;


(3) Find and replace

S: Complete the Find and replace operation in the last line mode

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

What to look for: Available modes

Replace with: cannot use mode, but can use \1, \2, ... You can also use "&" to refer to the entire content found in the previous lookup;

Modifier:

I: Ignore case

G: global substitution; By default, each row replaces only the first occurrence;


Find separators in substitutions/can be replaced with other characters, such as

[Email protected]@@

s###


Practice:

1, copy/etc/grub2.cfg to/tmp/directory, use the Find replacement command to delete the beginning of the line in the/tmp/grub2.cfg file blank characters;

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


2. Copy the/etc/rc.d/init.d/functions file to the/tmp directory, and add a # number to the beginning of the line beginning with each line of/tmp/functions with the find replacement command;

:%s/^[[:space:]]/#&/


Multi-file Mode:

Vim FILE1 FILE2 FILE3 ...

: Next Next

:p Rev A previous

: First One

: Last One


: Wall Save All

: Qall Quit all


Window-delimited mode:

Vim-o|-o FILE1 FILE2 ...

-O: Horizontal split

-O: Vertical split


Switch between windows: Ctrl+w, Arrow


Single File Window segmentation:

Ctrl+w,s:split, Horizontal split

Ctrl+w,v:vertical, Vertical split


Customizing the working characteristics of vim:

Configuration file: Permanently valid

Global:/ETC/VIMRC

Personal: ~/.VIMRC


Last line: The current VIM process is valid


(1) Line number

Display: Set number, abbreviated as set Nu

Cancel display: Set Nonumber, abbreviated to set Nonu

(2) Bracket matching

Match: Set Showmatch, abbreviated as set SM

Cancel: Set NOSM

(3) Auto Indent

Enable: Set AI

Disabled: Set Noai

(4) Highlight Search

Enabled: Set Hlsearch

Disabled: Set Nohlsearch

(5) syntax highlighting

Enabled: Syntax on

Disabled: Syntax off

(6) Case of ignoring characters

Enable: Set IC

Do not ignore: set Noic


Get help:

: Help

: Help Subject


Question: How do I set the tab indent to 4 characters?


Practice:

1. Copy the/etc/rc.d/init.d/functions file to/tmp directory, replace the/etc/sysconfig/init in the/tmp/functions file with/var/log;

2. Delete the # at the beginning of all lines in the/tmp/functions file that begin with # and have at least one blank character after #;


[Comanddetail] Vim

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.