Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Vim Editor-use detailed instructions

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

Vim Editor

1. Basic mode:

Edit mode, command mode

Input mode

Last row mode

two。 Open files, convert between modes

# vim [OPTION]... FILE...

+ #: after opening the file, place the cursor directly at the beginning of line #

-/ PATTERN: after opening the file, directly place the cursor at the beginning of the first line matched by PATTERN

Mode conversion:

Edit mode-- > input mode

I:insert, enter at the current cursor

A:append, enter after the current cursor

O:open, open a new line below the current cursor to enter

I: enter at the beginning of the line where the current cursor is located

A: enter at the end of the line where the current cursor is located

O: enter a new line above the line of the current cursor

Input mode-- > edit mode

ESC

Edit mode-- > last line mode

:

Last line mode-- > edit mode

ESC (normal press 2 times, press 1 time reaction is slow)

Turn off mode:

: Q exit in the last line mode without any changes

: q! Do not save the changes, force do not save and do not exit

Wq saves the changes, saves and exits

: X save exit

W / PATH/SOMESWHERE is saved to the specified place

ZZ is in edit mode. Save and exit directly. There is no need to switch to the last line mode and then save exit.

3. Cursor jump

Jump between characters

H: to the left

J: down

K: up

L: to the right

Single jump of words

W: jump to the beginning of the next word

E: jump to the end of the current or next word

B: jump to the beginning of the current or previous word

Jump at the beginning and end of the line

^: jump to the beginning of the current line

0: jump to the line of the current line

$: jump to the end of the current line

Interline movement

G: jump to the last line

# G: jump to line

1G clock gg: jump to the first line

Edit commands for 4.vim

Character editing

X: delete the letter where the current cursor is located

# x: delete the # th character backward where the current cursor is located

Xp: swaps where the current cursor is located and the characters following it

R:replace, press r key, then press a key to replace the character at the current cursor with a

Delete command:

D: delete command, which can be combined with cursor jump characters to delete within the range.

Delete: delete the content from the current cursor to the end of the line

D ^, d0: deletes the content at the beginning of the line where the current cursor is located

Dd: delete the entire line of the pawn mark

# dd: delete on multiple lines, starting with the behavior of the current cursor

Dw:

De:

Db:

Paste the command (pmenade putjinghouse):

P: if the buffer is stored in advance, it is pasted below the line of the current cursor; otherwise, it is pasted behind the cursor.

P: if the buffer is stored in advance, paste it above the line of the current cursor; otherwise, paste it behind the cursor

Copy command (yQuery yank):

Y: copy, working behavior similar to d command

Y ^: copy the location of the current cursor to the beginning of the line

Y0: copy the location of the current cursor to the beginning of the line

Copy: copy the current cursor to the end of the line

Yy: copies the entire line of the current cursor

# yy: implement multiline copy, starting with the current cursor

Yw:

Ye:

Yb:

Change command (c _ change):

C: modify

Edit mode-- > input mode

Delete: modify the cursor to the end of the line, delete the content from the cursor to the end of the line, and change it into insert mode

C ^: modify the cursor to the beginning of the line, delete the content from the cursor to the beginning of the line directly, and change to insert mode

C0: modify the cursor to the beginning of the line, delete the content from the cursor to the beginning of the line directly, and change to insert mode

Cw:

Cb:

Ce:

Cc: modify the entire row and change it to insert mode

Undo the previous editor (u.j.undo):

U: undo the previous action

# u: undo a previously specified number of actions

Undo the previous undo: even if you undo the previous action with u, you regret it and want to change it back.

Ctrl+r

Repeat the previous editing action:

.

Visualization mode:

V: select by character

V: select by row

Note: often combined with editing commands to achieve multi-line deletion, replication, etc.

Flip the screen:

Ctrl+f: flip a screen to the end of the file

Ctrl+b: flip a screen to the head of the file

Ctrl+d: flip half the screen to the end of the file

Ctrl+u: flip half the screen to the head of the file

The last line mode in 5.vim

Built-in command line interface

(a) address definition

: start_pos,end_pos

#: specific line #, for example, 2 represents line 2

#, #: from line to line

#, + #: add a few lines from which line

.: the dot represents the current line

$: represents the last line

$- 1: represents the penultimate line

%: represents the full text, which is equal to 1 $

/ pat1/,/pat2/

From being matched by pattern pat1 for the first time to being matched by pattern for the first time

How to use: followed by an editing command

D: indicates that the deletion action is performed after a successful match

Y: indicates that the copy action is performed after a successful match

W: indicates that the write is performed to the specified file after a successful match

W / PATH/SOMEWHERE

(B) search

/ PATTERN: look at the end of the file from the current cursor

? PATTERN: look for the file header from the current cursor

N: in the same direction as the command

N: opposite to the direction of the command

(C) find and replace

S: complete the find and replace operation in the last line mode

S / what to find / what to replace with / modifier

What to find: you can use regular expressions

To be replaced by: regular expressions cannot be used, but references such as &,\ 1,\ 2 can be referenced.

Modifier:

I: ignore case

G: global replacement, by default, each line replaces only the first occurrence

The delimiter "/" in find replacement can be replaced with other characters; for example

Example:% s @

Cases of scurvy:% s#

6. Multi-file mode

# vim FILE1 FILE2 FILE3...

Next next

The last one in last

: the first first

: the previous prev

: wall saves all

Qall exits all

Wqall saves all and exits

Multi-file window delimited mode:

# vim-o |-O FILE1 FILE2...

-o: split horizontally

-O: vertical split

Switch between multiple file windows:

Ctrl+w,Arrow (up, down, left and right arrow)

Single file window segmentation

Ctrl+w,s (split horizon file)

Ctrl+w,v (Vertical violation File)

7. Customize the working characteristics of vim

(a) set the line number

Show line number: set nu (number)

Do not display line number: set nonu (nonumber)

(B) highlight the word that is hit by the search

Highlight: set hl (hlsearch)

Do not highlight: set nohl (nohlsearch)

(C) indent

Auto indent: set ai (autoindent)

Cancel automatic indentation: set noai (noautoindent)

(d) grammatical coloring

Display color: syntax on

Do not display color: syntax off

(e) automatically match parentheses

Automatically match parentheses: set sm (showmatch)

Do not automatically match parentheses: set nosm (noshowmatch)

(F) ignore character case

Ignore case: set ic (ignorecase)

Do not ignore case: set noic (noignorecase)

8. Configuration file

# vim / etc/vimrc configure globally, install vim, and this file already exists

# vim ~ / .vimrc configures the user. This file may not exist in advance and needs to be created by yourself.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report