Summary of new usage of vi of vim under linux

  • 2021-07-09 09:47:47
  • OfStack

I've been using the vi editor for several years, but I still haven't used some practical usage. After listening to the introduction of linux in python video today, I still learned some new tricks

1.: set nu displays line number

2. gg--to the beginning of the document

3. G-----to end of file

4. u----Undo operation

5. Ctrl+r--Redo

6.:/better Enter, find the word that matches better, and press n to find the next 1

7.: s/better/dog Enter and replace the first better in this line with dog

s/better/dog Enter and replace all better in this line with dog

% s/better/dog Enter, replace all better in this document with dog

8. vi -O2 file1 file2

Use one screen to display file1 and file2 files at the same time, which is convenient for editing. Press ctrl+w to switch from one file to another file window.

Extended content

Linux Common Commands

-Learned

cd (path switching) rm (followed by-rf to delete files or folders) ls (view files and folders under the current path) mkdir (create folders) touch (create files)
cat (View File Content) mv (Move File or Rename File) rmdir (Delete Empty Folder) whoami (View Current User) pwd (View Current Path)
-/# Root directory linux system has no drive letter, only root directory/.
-cd # Directory Jump
-cp # Copy file cp < Files under current folder > < Destination folder > / < Filename >
# Replication Folder cp-rf < Folder > < Destination folder >
-find # Find File find/(Path)-name '*. py'
find/(path)-size 1024 (+1024 greater than 1024; -1024 less than 1024)
sudo find...... # sudo Gets Permissions

Common commands for Vim

Cursor positioning;

hjkl moves up and down, left and right

0 $skips to the beginning or end of a line

gg shift+G Skip to the beginning or end of the entire file

1G, 2G, 3G...... NG, skip to the beginning of line 1.2. 3 N

/String (n N can be cyclical) to quickly locate to a 1 row,

/^ d Quickly navigate to the line beginning with d,

/txt $fast positioned to line ending in txt.

Text editing (small amount)

y replication. yy 3yy ygg yG (in rows)

d Delete dd 3dd dgg dG (in rows)

p Paste

x Delete the character where the cursor is located

D is deleted from the cursor to the end of the line

u undo Undo

^ r redo Undo, Redo Ctrl + r

r modifies 1 character

Enter other modes

a enters insert mode, inserting behind the cursor

i enters insert mode and inserts in front of the cursor

o Insert another line

A shift + A is inserted at the end of the current line

Enter Last Line Mode (Extended Command Mode)

v Enters Visual Mode

^ v Enter Visual Block Mode Ctrl + v

V enters visual line mode

R enters replacement mode for batch replacement behind the cursor, similar to text Insert on Windows

Automatic completion of VIm keywords in insert mode Ctrl + p/n

The above is all the knowledge points and extended content of this introduction. Thank you for your study and support for this site.


Related articles: