vi vim Press GA at the end of the edit. Add a new line below the last line and press Go.

vim quickly jumps to the end of the file and adds a new line below the last line

Move to the end and enter text entry mode GA (capital G and capital A)

In normal mode (the mode just entered, esc mode)
GA or Shift + ga
First G or shift + g to the last line
Then A or shift + a to the end of the line and enter text entry mode

Add a new line below the last line (cursor wraps, text does not wrap) Go (uppercase G, lowercase o)

In normal mode (the mode just entered, esc mode)
Go or Shift + g then o
First G or shift + g to the last line
Then lowercase o and add a new line below that line

Directory

  • vim quickly jumps to the end of the file and adds a new line below the last line
    • Move to the end and enter text entry mode `GA` (capital G and capital A)
    • Add a new line below the last line (the cursor wraps, the text does not wrap) `Go` (uppercase G, lowercase o)
    • vi’s various working modes
    • Move to the end and enter text entry mode
    • Add a new line below the last line (cursor wraps, text does not wrap)
    • Expand knowledge
      • Cursor moves quickly
        • First line (first line), last line (beginning of the last line)
        • a certain line
        • Top of screen, middle of screen, bottom of screen
        • Beginning of line and end of line
        • up down left right
      • Add a new line and enter text entry mode
      • copy cut paste delete
        • copy
          • Visual selection to copy or cut
        • Paste
          • Paste the contents of vim’s own clipboard
          • To paste the contents of the system clipboard, use Ctrl + Shift + small v
        • delete
          • Delete and then automatically enter text insertion mode
          • Delete, stay in ESC mode
          • Delete row, delete entire row
            • Delete the entire current line
            • Delete multiple lines
      • Undo (rewind) (reverse) redo (forward)
      • Find and replace
          • Find
        • replace
          • `&` can represent search results
            • Replace the horizontal bar minus sign (- letter) with backticks on both sides
            • Replace the bar minus sign (- one or more letters) with backticks on both sides
          • Limit replacement to a visible selection
      • Save and exit
      • Line number
      • other
      • After the action, you will enter the text input editing mode.
          • Enter text input insertion mode INSERT mode
          • Enter text input overwrite replacement mode REPLACE mode
    • attached
      • Solve the problem that the top, bottom, left and right in the editing mode of vim in Ubuntu22.04Desktop desktop version become ABCD
        • Solution 1, uninstall and reinstall vim
        • Solution 2, modify `/etc/vim/vimrc.tiny`

Various working modes of vi

  1. Normal mode, the mode when you just enter vi, esc mode, I think it can be called shortcut mode (key mode), press esc mode
  2. Text input mode (a, A, i, I, o, O, s, S, C enters insert mode R enters overwrite mode)
  3. Bottom command line mode (starting with colon :, starting with /, starting with ?)
  4. Continuous string selection visual mode (v)
  5. Block selection can be modal (ctrl + v)

Move to the end and enter text entry mode

In normal mode (the mode just entered, esc mode)
GA or Shift + ga
First G or shift + g to the last line
Then A or shift + a to the end of the line and enter text entry mode

Add a new line below the last line (cursor wraps, text does not wrap)

In normal mode (the mode just entered, esc mode)
Go or Shift + g then o
First G or shift + g to the last line
Then lowercase o and add a new line below that line

Expand knowledge

vi vim keyboard map

Cursor moves quickly

#### The beginning of the document, the end of the document The beginning of the document: `gg` or `1gg` The end of the document: `G$` or `999999gg$` or `999999G$` (The end of the document is (the end of the last line) (the end of the last line) )(end of last line)

First line (first line), last line (beginning of the last line)

The first flight is the beginning of the document: gg or 1gg or 1G

The last line is the beginning of the last line (the beginning of the last line): G or 999999gg or 999999G or :999999

To get to the last line, in esc mode, press the G key when the keyboard is uppercase or press the shift + g key when it is lowercase.
To reach the first line, press lowercase g twice gg or enter Colon:0 or Colon:1

  • gg or :0 or :1 ——–The beginning of the first line
  • G —————————-Begins with the last line
    888G or 888gg or :888 to line 888 or the last line

A certain line

The beginning of a line: line number gg or line number G or colon line number, such as 1gg,2G,3gg,666G,888gg,:777,:999

  • Line number gg such as: 1gg, 3gg, 666gg,
  • Line number G such as: 1G, 3G, 4G,5G,666G ,
  • Colon line number For example: :0=:1 , :3 , :666 ,

You can use 0 for the colon, and the effect is the same as 1. gg and G cannot start with 0, and the words starting with 0 will take effect directly to the beginning of the line.

At the top of the screen, in the middle of the screen, at the end of the screen

HAt the top of the screen? MMiddle of the screen? LAt the end of the screen

First and last line
  • Current line start: 0(zero)
  • The first character of the current line: ^ (Shift + 6)
  • End of current line: $ (Shift + 4) or 999999space or 9999999999right
Up, down, left and right

Number right click=Number space=Number lowercase l: Move the cursor to the right several characters
Number Down Key=Number Enter: Move the cursor down a few lines
Left key on numbers=Number lowercase h: Move the cursor several characters to the left
Number Up Key: Move the cursor up several lines

Add a new line and enter text entry mode

  • Add a new line below the current line and enter editing mode, use o in lowercase
  • Add a new line above the current line and enter editing mode, capitalize O

Copy cut paste delete

Copy

yy=y1y=1yy Copy the line where the cursor is
yyp=y1yp=1yyp Copy and paste the current line down
yyP=y1yP=1yyP Copy and paste the current line up

3yh or y3h The first three characters of the cursor? 3yl or y3l The cursor and the last two characters
yy This line? y0The beginning of the line reaches the cursor? y^The first character of this line reaches the cursor? y$Cursor to end of line
3yy or y3y this line and the next two lines
yw Cursor to character after space

Visual selection to copy or cut

There are three ways to choose capture

  • v Lowercase v selects continuous text, the first and last lines do not need to include the entire line
  • V Capital V selects continuous text, all lines are whole lines
  • Ctrl + v lowercase v, block selection, text can be discontinuous, diagonal box chip selection

First move the mouse to the desired starting position, then press v
Then you can select up, down, left, or right like you would with a mouse holding down the left button.
After selecting the area, press y to copy, press d or x to cut, p to paste, c or sDelete

#### Cut (delete) `d, D, x, edit mode,

Cut d syntax is like copied y syntax
dd=d1d=1dd Cuts the cursor line, along with the newline character, and the line disappears
3dh or d3h The first three characters of the cursor? 3dl or d3l The cursor and the last two characters
dd This line? d0The beginning of the line reaches the cursor? d^The first character of this line reaches the cursor? d$Cursor to end of line
3dd or d3d this line and the next two lines

x cuts the cursor character
X Cut the character before the cursor

Paste
Paste the contents of vim’s own clipboard

Paste is divided into Paste before and after the cursor and Paste above and below the current line

p Paste lowercase p after the cursor or below the current line
P Uppercase P is pasted before the cursor or on the current line

  • When the clipboard content is not a whole line, paste it before and after the cursor
    When the clipboard content is the entire line, paste to the top and bottom of the current line

  • When selecting a fragment with lowercase v, paste before and after the cursor
    When using capital V to select multiple lines, paste above and below the current line. Paste before and after the cursor.

When using y3hp or 9ylp or y6hP, 8ylP, etc. to select non-whole lines,

When using yyP`` or yyp, etc., it is not before and after the cursor, but up and down of the current line
yyp=y1yp=1yyp copies and pastes the current line below the line, not after the cursor
yyP=y1yP=1yyP copies and pastes the current line below the line, not after the cursor
y3yp=3yyp is to copy and paste the current and 3 lines below the line, not after the cursor
y6yP=6yyP is to copy and paste the current and 6 lines below the line, not after the cursor

To paste the contents of the system clipboard, use Ctrl + Shift + small v

Ctrl + Shift + small v

Delete

c,C,s,SPure deletion will enter the editing mode.
d,D,x,X means cutting. To facilitate p,P pasting, it will remain in Esc mode.

Delete and then automatically enter text insertion mode
  1. S clears the cursor line (capital S), retains the newline character, and turns the line into a blank line.
    S=cc=c1c=1cc

    s deletes the cursor character (lowercase s), deletes a character

  2. C deletes the cursor to the end of the line (capital C), including the cursor character to the end of the line.

    The operation syntax of c (lowercase c) is similar to d and y. Its function is to delete, just like d, but after execution Will enter text input insertion mode
    cc=c1c=1cc=S clears the cursor line and retains the newline character. The line is still there and becomes blank line,
    3ch=c3hThree characters before the cursor? 3cl=c3lThe cursor and the two characters after it
    c0The beginning of the line reaches the cursor? c^The first character of this line reaches the cursor? c$The cursor reaches the end of the line
    3cc or c3c this line and the next two lines
    C Cursor to end of line (capital C)

Delete, stay in ESC mode

d, D, x, X are cut, have deletion effect, and stay in ESC mode
dd=d1d=1dd Cut (copy and delete) the current line, the line disappears, and stays in ESC mode
Lowercase x=1x~= approximately equal to Delete: delete the cursor character, the del key does not cut, it only deletes, not copies
Capitalized X=1X: Cut the left character, the back key will not delete it
Lowercase 88x cuts the right side and the cursor, a total of 88 characters
Capitalized 88X cuts 88 characters to the left of the cursor (excluding the cursor)

Delete rows, delete entire rows
Delete the entire current line

The effects of deleting the entire current row are:

  1. Delete it together with the newline character and the line disappears
  • cc=c1c=1cc=S clears the cursor line and retains the newline character. The line is still there and becomes Blank line and enter insert editing mode
  1. Keep the newline character, the line is still there, turn it into a blank line, keep the blank line
  • dd=d1d=1dd Cut (copy and delete) the current line, the line disappears, and stays in ESC mode
Delete multiple lines

3S=c3c=3cc, delete this line and the 2 lines below, a total of 3 lines, leave a blank line, and enter the insert editing mode
c3↓=3c↓, delete this line and the 3 lines below, a total of 4 lines, leave a blank line, and enter the insert editing mode
c3↑=3c↑, delete this line and the 3 lines above, a total of 4 lines, leave a blank line, and enter the insert editing mode

Undo (Rewind) (Back) Redo (Forward)

uUndo (rewind) (rewind)

ctrl + r Redo CTRL + r , Undo Undo, Undo Back, Undo Back, Forward

Find and Replace

Search

Support regular expressions
/pattern searches down for patterns matching
?pattern up
n Next
N Previous

Replace

:s/a/b The first a in this line becomes b
:s/a/b/g All a’s in this row become b
:%s/a/b The first a in all lines becomes b
:%s/a/b/g All a’s in all lines are changed to b, and a’s in the entire document are changed to b.

The % percent sign represents all lines, and g represents all matches in a line.

& amp; can represent search results
Replace the horizontal bar minus sign (-letter) with backticks on both sides
:%s/\-\w/\` & amp;\`/g
### ↑The above will match -command to -c. You can use \> to limit the tail. \b will not match it.
:%s/-\w\>/\` & amp;\`/g
:%s/\-[A-Za-z]/\` & amp;\`/g
### ↑The above will match -command to -c. You can use \> to limit the tail. \b will not match it.
:%s/\-[A-Za-z]\>/\` & amp;\`/g
Replace the horizontal bar minus sign (-one or more letters) with backticks on both sides

vi uses basic regular expressions. The + sign represents the letter plus sign. You need to backslash escape \ + to represent one or more times;

:%s/\-[A-Za-z]\ + /\` & amp;\`/g

Some commands may contain numbers, so use /w alphanumeric underlines.

:%s/\-\w\ + /\` & amp;\`/g

The horizontal bar minus sign - outside the square brackets can also represent characters without escaping.

:%s/\-\w/\` & amp;\`/g
:%s/-\w/\` & amp;\`/g

:%s/\-[A-Za-z]/\` & amp;\`/g
:%s/-[A-Za-z]/\` & amp;\`/g

:%s/\-[A-Za-z]\ + /\` & amp;\`/g
:%s/-[A-Za-z]\ + /\` & amp;\`/g

:%s/\-\w\ + /\` & amp;\`/g
:%s/-\w\ + /\` & amp;\`/g

Limit replacement to the visible selected area

Use the cursor to determine the starting point, then v for continuous string selection, or ctrl + v for block selection
Press colon :, :'<,'> appears at the bottom

:<,’>

Append s/pattern/content/g after :'<,'> to become :'<,'>s/pattern/conten/g
Press Enter to replace the content matched by the pattern.

Save and exit

:w—————-Save
:q—————-Exit
:q! or ZQ —–force exit
:wq or ZZ or :x or :exit——– Save and exit (ZZ is uppercase and has no colon. ZZ is more intelligent and saves only when modifications are detected)
:wq! or :x! or :exit!————- Force save and exit (ZZ cannot add an exclamation mark and cannot be enforced)

Line number

:set nu Display line number :set nonu Turn off line number

Others

. Repeat the previous action (dot)
nSpacebar moves the cursor after n characters
nEnter key moves the cursor down n lines

After the action, you will enter the text input editing mode

There are two types: insert mode / replace mode
Both a and i enter insert mode. Don’t be confused about whether a is overwriting because i is insert. i is insert before the cursor, a is insert after the cursor, and append is not overwriting.

Enter text input insertion mode INSERT mode
  1. a Insert after cursor
  2. i insert before cursor
    I starts inserting after the cursor moves to the first character of this line
  3. O inserts a line above the cursor
    o inserts a line under the cursor
  4. S delete this row
    s deletes the cursor character
  5. C Delete the cursor to the end of the line
    c The small c operation syntax is similar to d and y. Its function is to delete, just like d, but it will enter after execution. Text input insert mode, and keep blank lines, d is cut
  6. 3ch or c3h The first three characters of the cursor? 3cl or c3l The cursor and the last two characters
    cc This line? c0The beginning of the line reaches the cursor? c^The first character of this line reaches the cursor? c$Cursor to end of line
    3cc or c3c this line and the next two lines
  7. First R enter overwrite mode, then press the keyboard insert button
Enter text input overwrite and replace mode REPLACE mode
  1. Press the insert button in insert mode
  2. R directly enters overwrite mode (lowercase r followed by character only replaces the character at the cursor, and remains in normal mode after replacement)

Attachment

Solution to the problem that the top, bottom, left, and right in the edit mode of vim in Ubuntu22.04Desktop desktop version become ABCD

In the editing mode of vim in the Ubuntu22.04Desktop desktop version, the up, down, left, and right keys become ABCD, and the backspace key also fails.

Solution 1, uninstall and reinstall vim
sudo apt remove vim
sudo apt install -y vim
Solution 2, modify /etc/vim/vimrc.tiny
  1. Change compatibility mode to incompatible mode
    Change set compatible to set nocompatible, or add it to the end
  2. Add a set backspace=2
set nocompatible
set backspace=2

It is temporarily unavailable to use vi and vim. You can use nano or gedit to modify it.

Remote use

sudo nano /etc/vim/vimrc.tiny

For this machine

sudo gedit /etc/vim/vimrc.tiny

Original /etc/vim/vimrc.tiny

" Vim configuration file, in effect when invoked as "vi". The aim of this
" configuration file is to provide a Vim environment as compatible with the
" original vi as possible. Note that ~/.vimrc configuration files as other
" configuration files in the runtimepath are still sourced.
" When Vim is invoked differently ("vim", "view", "evim", ...) this file is
" _not_ sourced; /etc/vim/vimrc and/or /etc/vim/gvimrc are.

" Debian system-wide default configuration Vim
set runtimepath=~/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vim82,/usr/share/vim>
set compatible

" vim: set ft=vim:

Modified /etc/vim/vimrc.tiny

" Vim configuration file, in effect when invoked as "vi". The aim of this
" configuration file is to provide a Vim environment as compatible with the
" original vi as possible. Note that ~/.vimrc configuration files as other
" configuration files in the runtimepath are still sourced.
" When Vim is invoked differently ("vim", "view", "evim", ...) this file is
" _not_ sourced; /etc/vim/vimrc and/or /etc/vim/gvimrc are.

" Debian system-wide default configuration Vim
set runtimepath=~/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vim82,/usr/share/vim>

set nocompatible
set backspace=2

" vim: set ft=vim:

Modify with script

echo '" Vim configuration file, in effect when invoked as "vi". The aim of this
" configuration file is to provide a Vim environment as compatible with the
" original vi as possible. Note that ~/.vimrc configuration files as other
" configuration files in the runtimepath are still sourced.
" When Vim is invoked differently ("vim", "view", "evim", ...) this file is
" _not_ sourced; /etc/vim/vimrc and/or /etc/vim/gvimrc are.

" Debian system-wide default configuration Vim
set runtimepath=~/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vim82,/usr/share/vim>

set nocompatible
set backspace=2

"vim: set ft=vim:' | sudo tee /etc/vim/vimrc.tiny

or

sudo sed -ie 's/compatible/nocompatible\
set backspace=2/' /etc/vim/vimrc.tiny

View and experiment with vim’s top, bottom, left, and right

sudo vi /etc/vim/vimrc.tiny

reduction

echo '" Vim configuration file, in effect when invoked as "vi". The aim of this
" configuration file is to provide a Vim environment as compatible with the
" original vi as possible. Note that ~/.vimrc configuration files as other
" configuration files in the runtimepath are still sourced.
" When Vim is invoked differently ("vim", "view", "evim", ...) this file is
" _not_ sourced; /etc/vim/vimrc and/or /etc/vim/gvimrc are.

" Debian system-wide default configuration Vim
set runtimepath=~/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vim82,/usr/share/vim>
set compatible

"vim: set ft=vim:' | sudo tee /etc/vim/vimrc.tiny