Linux development tool editor vim

Article directory

  • 1.What is vim?
    • 1.1 Ask Du Niang
    • 1.2 Summarize by yourself
  • 2. Preliminary understanding of vim
    • 2.1 Entry and exit
    • 2.2vim mode
      • 1 Introduction
      • 2.Use
  • 3.vim configuration
    • 3.1 Configure it yourself
    • 3.2 Download plug-in
    • 3.3 Install the files configured by the boss
  • 4. Translation of programs
  • 5. Easy to use instructions

1.What is vim?

1.1 Ask Du Niang







1.2 Summary by yourself

vi/vim are both multi-mode editors. vim is an upgraded version of vi. It is not only compatible with all instructions of vi, but also has some new features: syntax highlighting, visual operations can be run not only in the terminal, but also in x window , mac os, windows

Preliminary understanding of 2.vim

vim: text editor is only responsible for writing code, not compiling and running. It is a multi-mode editor.

2.1 Entering and exiting

Enter: vim
Exit: shift: q
Enter the file: vim code.c

2.2vim mode


vim wq: can also create files

1. Introduction

Command mode, Insert mode, Last line mode

Normal/Normal/Command mode (Normal mode) [vim’s default opening mode]

  1. Control the movement of the screen cursor
  2. Deletion of characters/words/lines
  3. Move and copy a section
  4. Enter Insert mode/last line mode

Basic common instructions of command mode

“yw”: Copy the characters from the cursor to the end of the word into the buffer
yy: Copy the line where the current cursor is located 5yy: Copy 5 lines from the current line [windows: ctrlc]
dd: Cut the line where the current cursor is located ndd [ctrlx]
p: Paste 10p: Paste the content copied 10 times [ctrlv]
u: Undo historical operations [ctrlz]
ctrl + r: Undo [ctrly]
shift~: case conversion
x/shift x: Delete the character pointed to by the cursor nx: Delete n characters

Enter insert mode

i: enter insert mode
a: In command mode, if there is a character here, the cursor moves to the next digit of the character (regardless of whether there is a character behind it or not, it moves to the next digit). If there is no character here, enter the insert mode.
o: Create a new line below the current line under the cursor and enter insert mode

replace

Enter r + x in command mode: replace the character at the cursor position with x
Enter 5r + x in command mode: replace the cursor position 5 characters behind with x
shift r: overwrite replacement [enter replacement mode]

Find

/text: forward search text value
?text: Reverse search for text value
/\ctext: case-insensitive search text

Cursor moves up and down

shiftg: position the cursor to the end of the file
gg: The cursor is positioned at the beginning of the file
Number + shiftg: position the cursor to a specific line

Cursor moves left and right

shift^: position the cursor to the beginning of the line
shift$: position the cursor to the end of the line
w: The cursor jumps to the beginning of the next word, moving backward in units of words. 5w moves backward five words.
e: The cursor jumps to the end of the next word
b: The cursor returns to the beginning of the previous word and moves forward in units of words 5b Same as above

Press “ctrl” + “b”: the screen moves “back” one page
Press “ctrl” + “f”: the screen moves “forward” one page
Press “ctrl” + “u”: the screen moves half a page “back”
Press “ctrl” + “d”: the screen moves half a page “forward”

[The arrows on the keyboard can also be moved which is not convenient]

hjkl: left, lower, upper right

  1. Old style keyboard without arrows
  2. hjkl is more efficient
  3. Follow-up comments will be used later.
  4. Recommended

Insert mode

Text input can only be done in Insert mode. Press the “ESC” key to return to the command line mode.

last line mode

Save or exit the file, you can also perform operations such as file replacement, string search, and line number listing. In command mode, shift: can enter the mode
Mode. To view all your modes: Open vim and enter :help vim-modes directly in the bottom line of the mode

Show/hide line numbers

set nu/set nonu

Split screen operation


After entering the code.c file, you can perform split-screen operation in the bottom line mode vs test.c
ctrl WW: The cursor jumps to another screen

basic instructions

w: save w!: force save
q:Quit q!:Force quit
! cmd: Execute instructions without exiting vim (command line/compile/run/check manual)
: text Jump to text line

2.Use

Input: i/a/o——>Edit/Insert mode
Press “i” to switch to insert mode “insert mode”. After pressing “i” to enter insert mode, you will start inputting files from the current position of the cursor;
After pressing “a” to enter insert mode, text input starts from the position next to the current cursor position;
After pressing “o” to enter insert mode, a new line is inserted, and text is entered starting from the beginning of the line.

The status in the lower left corner changes to You can write code

Enter esc

Exit current mode/return to previous mode

Input: shift:

Bottom row mode

Enter esc

Exit current mode/return to previous mode

Note: You cannot go directly from insert mode to bottom row mode. You cannot go directly from bottom row mode to insert mode.

3.vim configuration

3.1 Configure it yourself

First create a .vimrc file in your working path and then copy and paste the desired configuration

vim configuration, that is, the configuration of .vimrc file and vim operation skills

3.2 Download plug-in

First create a .vim file in your working path and then download it according to the instructions

10 extremely useful Vim plug-ins, how many do you know?

3.3 Install the files configured by the boss

vim configuration

4. Translation of program

5. Easy-to-use commands

  1. In block visual mode, you can use h, j, k, l and other direction keys to move the cursor, and you can use other vim commands for editing operations. For example, you can use the d command to delete a selected block, use the y command to copy a selected block, use the p command to paste a selected block, etc.
  2. Full text alignment: gg ctrl + v shift + g =: Place the cursor at the beginning of the text and enter block visual mode. Align from the beginning of the text to the end of the text by the equal sign.
  3. Delete comments in batches: ctrl + v j x Locate the first / of the comment symbol // Enter block visual mode j: Move the cursor down to the last / x: Delete the selected / Successfully delete the comment again ( Press l first to move to the second one/delete once)
  4. Add comments in batches: In command line mode, enter block visual mode, select the character before the statement you want to add comments, enter a capital i, and enter /
  5. Batch replacement under VS: In bottom row mode: %s/old/new/g