当前位置:网站首页>15. Using the text editing tool VIM

15. Using the text editing tool VIM

2022-07-07 15:37:00 51CTO

VIM Use format

vim  [option] ...file ...

Common options

 +# After opening the file , Place the cursor at # That's ok

+/pattern Let the cursor be at the first pattern The first line of the matched line

-b file Binary open file

-d file1 file2 ... Compare multiple files , amount to vimdiff

-m file Read only open file

15、 Text editing tools VIM Use _vim Shortcut

-e file Go straight into ex Pattern , amount to ex file

-y file easy mode Look directly at the operation documents

VIM Three models

vim There are three patterns ( Command or normal mode 、 Insert or edit mode 、 Extended command mode )

The three need to be converted              

15、 Text editing tools VIM Use _vim Shortcut _02

Extended command mode

In command mode , Under English characters , Hold down shift+:( Input :) Enter extended command mode , The bottom will appear :

15、 Text editing tools VIM Use _vim Shortcut _03

Extended command basic command

w Write save  

wq Write save exit    

x Equate to wq

X encryption  

q sign out

q! Forced exit without saving  

r filename Read the contents of the file into the current file

15、 Text editing tools VIM Use _vim_04

w filenamen Write the current file to another file ( Save as )

15、 Text editing tools VIM Use _vim_05

!commad Carry out orders

r!command Read in the output of the command

15、 Text editing tools VIM Use _vim Shortcut _06

Address delimitation

Format : Start , end

 # Specifically # That's ok

 #,# From left side # Start # end

 #,+# from # Start ,#+# end

 . Current row

 $ The last line

 % The full text , amount to 1,$

 /pattern/ Look down from the current line to find a match pattern first line

 /pattern1/,/pattern2/ From the first time pattern1 From the beginning of the matching line to the first time pattern2 End of match line

Address delimitation followed by an edit command

y Copy

d Delete

w file Save the specified file as

r file Inserts everything in the specified file at the specified location

Find and replace

s/ What to look for / Replace with / Modifier

explain : If there is no modifier behind , Only match the search content once to replace , We need to add g Modifier , Make a global replacement ; If you find that the content contains /, Other delimiters can be used ; Such as [email protected]/[email protected]/[email protected] The command uses @ Replace / Separator

Modifier

i Ignore case

g Global replacement

gc Global replacement , Ask... Before each replacement

customized vim Working characteristics of

overall situation /etc/vimrc    personal ~/.vimrc

Set line number display  set number  Abbreviation set nu 

Cancel line number display set nonumber

Ignore character case and enable set ignorecase Abbreviation set ic

Cancel ignoring case   set noic

Automatic indentation   set autoindent Abbreviation set ai

Cancel auto indent   set noai

Copy the reserved format set paste

Cancel copy retention format   set nopaste

Show tab And line breaks set list  Ban set nolist

Highlight search set hlsearch  Ban set nohlsearch

Syntax highlighting   syntax on  Ban syntax off

File format   windows  set fileformat=dox  unix set fileformat=unix(set ff=dos|unix)

tab Use space instead of   set expandtab (set et Default 8 A space )  Ban set expandtab

Appoint tab How many spaces to replace set tabstop=#

Set the text width    set textwidth=#   set wrapmatgin=#

Set the marking line set cursorline (set cul) Ban set nocursorline

encryption   set key=password  Ban set key=     

Command mode

Command mode is also called normal Pattern

The cursor jumps

h: Left   L: Right j: Next   k: On

#h/l/j/k: Jump # Characters

w: The first part of the next word

e: The end of the next word

b: Current word header

 #w/e/b ditto

H: The first page M In the middle of the page   L Bottom of page

zt Move the cursor to the top of the current screen

zz Move the cursor to the middle of the current screen

zb Move the cursor to the bottom of the current screen

^ Non white space characters at the beginning of the line 0 Head of line   $ At the end of the line

#G Jump to the first place # That's ok   G The last line   1G perhaps gg first line

ctrl+f Turn the tail   ctrl+b Turn the first screen ctrl+d The tail half screen   ctrl+u First half screen

Character editing

x Delete the character at the cursor   #x Delete cursor start x Characters   xp Exchange the position of the character that the cursor is in and the character after it

~ Convert case J Delete line break after current line

Replace the command

r Replace only one character at the cursor   R Switch to replace Pattern , Press esc You can go back to command mode

The delete command

d The delete command

d$ Delete to end of line   d^ Delete to the beginning of the line  

dd Cut cursor line

#dd Multi row deletion

D: Deleting from the current cursor position to the end of the line is equivalent to d$

Copy command

y   y$ y^ Same as above

Paste command

p Paste it behind the target , If yes , Under the line where the cursor is located

P Same as small p contrary

Change the order

c: Switch to insert mode after deletion   c$ c^ cc #cc etc.

lookup

/pattern Find down

?pattern Upward search

n In the same direction as the command

N Against the command

Undo change

u: Undo recent changes   #u It's better to undo many times before

U Undo all changes in the current cursor line

Advanced usage

0y$  ( First of all ,y Start copying ,$ To the end of the line )

100ilgw  Input 100 Time lgw

di“ Delete “” Content between

yi( Copy () Content between

vi[ The cursor is on [] Between , Choose [] Content between

dtx Delete the character until it meets the first after the cursor x character

ytx Copy the character until the first one after the cursor x character

Visualization mode

At the end there is “--visual--” instructions , In visual mode

Allow text blocks to be selected

v character-oriented  

V Facing the whole line

ctrl-v Facing the block

Insert at the beginning of all lines #  crtl+v --- G---I---#---esc

Multi window mode

vim -o|O file1 file2 

-o Split horizontally or up and down   -O Vertically or left and right

Switch between windows ctrl+w

crtl+w,s Horizontal segmentation , Split up and down   ctrl+w,v Vertical segmentation , Left and right split screen

ctrl+w,q Cancel adjacent windows ctrl+w,o Cancel all windows

:wqall sign out

Edit binary

Open the file in binary mode

vim -b file 

The extension command %!xxd convert to 16 Base number    %!xxd -r Return binary .

more vim Please find out how to use it on the Internet .








原网站

版权声明
本文为[51CTO]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071233108004.html