Summary of new usage of vi (vim) under Linux

Summary of new usage of vi (vim) under Linux

I have used the vi editor for several years, but I have never used some practical uses. After listening to the introduction of Linux in the python video today, I still learned a few new tricks.

1. :set nu displays line numbers

2. gg--------to the beginning of the file

3.G--------To the end of the file

4.u---------Undo operation

5.Ctrl+r-----Redo

6.:/better, press Enter to search for words matching better, press n to search for the next one

7.:s/better/dog, press Enter to replace the first "better" in this line with "dog"

:s/better/dog, press Enter to replace all better in this line with dog

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

8. vi -O2 file1 file2

Use one screen to display both file1 and file2 for easy editing. Press ctrl+w to switch from one file window to another.

Expanded content

Common Linux commands

- Learned

cd (change the path) rm (followed by -rf to delete a file or folder) ls (view the files and folders in the current path) mkdir (create a folder) touch (create a file)
cat (view file contents) mv (move files, you can also rename files) rmdir (delete empty folders) whoami (view current user) pwd (view current path)
- / # The root directory of Linux system has no drive letter, only the root directory /.
- cd #directory jump
- cp # copy file cp <file in current folder> <destination folder>/ <file name>
# Copy folder cp -rf <folder> <destination folder>
- find # Find files find /(path) -name '*.py'
find /(path) -size 1024 (+1024 is greater than 1024; -1024 is less than 1024)
sudo find ........ # sudo obtains permissions

Vim commonly used commands

Cursor positioning;

hjkl move up, down, left, and right

0 $ Jump to the beginning or end of the line

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

1G, 2G, 3G........NG, jump to the beginning of line 1.2.3 N

/String(n N can be looped) quickly locate a certain line,

/^d quickly locates the line starting with d,

/txt$ quickly locates the line ending with txt.

Text editing (small amount)

y copy. yy 3yy ygg yG (in lines)

d delete dd 3dd dgg dG (in lines)

p Paste

x Delete the character where the cursor is

D Delete from cursor to end of line

u undo

^r redo Undo, redoCtrl + r

r Modify a character

Enter other modes

a Enter insert mode, insert after the cursor

i Enter insert mode, insert before the cursor

o Insert into a new line

A shift + A insert at the end of the current line

: Enter last line mode (extended command mode)

v Enter visual mode

^v Enter visual block mode Ctrl + v

V Enter Visual Line Mode

R Enter replace mode and perform batch replacement after the cursor, similar to Insert for text on Windows

VIm keyword autocompletion in insert mode Ctrl + p / n

The above are all the knowledge points and extended content introduced this time. Thank you for your learning and support for 123WORDPRESS.COM.

You may also be interested in:
  • The complete version of the common Linux tool vi/vim
  • Linux Vim Practical Commands Explained
  • Linux common text processing commands and vim text editor
  • How to operate vi and vim editors in Linux
  • Detailed explanation of Linux text editor Vim

<<:  A brief talk about Mysql index and redis jump table

>>:  React uses antd's upload component to implement the file form submission function (complete code)

Recommend

Share 10 of the latest web front-end frameworks (translation)

In the world of web development, frameworks are ve...

JavaScript to implement input box content prompt and hidden function

Sometimes the input box is small, and you want to...

Steps to build the vite+vue3+element-plus project

Use vite to build a vue3 project You can quickly ...

Comprehensive website assessment solution

<br />Sometimes you may be asked questions l...

Detailed explanation of how to create an array in JavaScript

Table of contents Creating Arrays in JavaScript U...

17 404 Pages You'll Want to Experience

How can we say that we should avoid 404? The reas...

Example code for text origami effect using CSS3

Preface This article mainly shares with you an ex...

Several common CSS layouts (summary)

Summary This article will introduce the following...

Detailed explanation of Vue's caching method example

Recently, a new requirement "front-end cache...

About ROS2 installation and docker environment usage

Table of contents Why use Docker? Docker installa...