[Linux] The use of vim editor in Linux


 Table of contents

1. Introduction to vim

2. Command mode

2.1 Cursor positioning operation

2.2 Text copy, paste, cut, undo

2.3 Text manipulation

3. Insert mode

4. Bottom line mode

1. View the mode of vim

 2. Split-screen operation in bottom row mode

3. Execute instructions without exiting vim

4. Global replacement/global search for bottom line mode

4.1 Global replacement

4.2 Global search

5. Why can vim configurations between users not affect each other?

How to quickly configure vim?

6. Add ordinary users to the trust list


1. Introduction to vim

vim is an editor in Linux, of course it does not support debugging. But it has a variety of modes and powerful functions.

2. Command mode

When opening vim, the default is command mode. The significance of the command mode is to improve editing efficiency.

2.1 Cursor positioning operation

1. $ Let the cursor quickly move to the end of the line. - row right;

2. ^ allows the cursor to quickly move to the beginning of the line. - row left;

3. G makes the cursor quickly move to the beginning of the last line of the file. --bottom;

4. gg makes the cursor quickly return to the beginning of the first line of the file. --top;

5. Line number + G to jump to any line;

6. h left, j down, k up, l right (character by character, all support n operation);

7. w moves backward and b moves forward by word (word by word, both support n operation);

8. cw deletes the current word and switches to insert mode, cnw deletes n words and switches to insert mode.

2.2 Text copy, paste, cut, undo

1. yy copies the line where the cursor is located, and nyy copies multiple lines;

2. p paste, np paste multiple times;

3. u undo, ctrl+r undo;

4. dd cuts the line where the cursor is located, ndd cuts multiple lines, ndd+p cuts and pastes;

5. X cuts backwards, nx cuts n characters backwards; X cuts forwards, nX cuts n characters forwards.

2.3 Text manipulation

1.~ Convert the current position of the cursor to upper and lower case letter by word;

2. R is converted to the replacement mode for batch replacement;

3. r replaces a single character, and nr performs the same replacement on n characters.

3. Insert mode

1. i enters insert mode from command mode;

2. a enters insert mode from command mode and moves backward by one character;

3. o enters insert mode from command mode and wraps the line.

4. Bottom line mode

1. set no to display the line number, set nonu to hide the line number;

2. wq! force save and exit

1. View the mode of vim

:help vim-modes//查看vim的模式

 2. Split-screen operation in bottom row mode

vs copy.c//分屏
ctrl ww//光标在分屏间的切换

3. Execute instructions without exiting vim

!ls//在vim中使用ls指令
!gcc test.c//使用gcc编译test.c生成a.out文件
!./a.out//运行s.out文件

4. Global replacement/global search for bottom line mode

4.1 Global replacement

%s/printf/cout/g

s stands for replace and g stands for global. Replace all printf with cout.

4.2 Global search

/查找内容

Use / plus find content to perform global search of content.

5. Why can vim configurations between users not affect each other?

Although every user uses the same vim, the configuration of vim does not affect each other, each with its own.

Each user has his own configuration file in his home directory, called .vimrc (hidden file, created by himself)

For example, to add line number function in .vimrc, you can write set nu in .vimrc, save and exit.

How to quickly configure vim?

After searching for VimForCpp in gitee, execute the link directly in the shell to complete the configuration.

6. Add ordinary users to the trust list

1. Log in with the root user

2. Use vim to open /etc/sudoers

3. Find the 100th line

4. After adding the trust account below, ordinary user jly can use sudo to elevate the privilege.

Guess you like

Origin blog.csdn.net/gfdxx/article/details/127484519