Vim from Little White to Initial



Vim is a text editor developed from VI. Code completion, compilation, error jump and other convenient programming functions are particularly rich, and are widely used by programmers. Join Emacs as the favorite editor for Unix-like system users. andWindows ❤️ LinuxAttitude change I believe you will often use the Vim text editor. There are many articles about Vim on the internet. This article only records the memo you often use as a memo. However, there is always only one word in the skilled way.use

Vim from Little White to Initial

Renewal of History

06 September 2019 – Preliminary draft

Read the original text –…

Extended Reading

Vim English Document –…

Vim Chinese Document –…

Vim Keyboard Diagram

Vim from Little White to Initial
Vim from Little White to Initial
Vim from Little White to Initial

Vim Initial 5 Steps

Complete the following exercises. Congratulations on opening Vim’s door

  1. vim HelloWorld.txt
  2. Type I
  3. Editors enter arbitrary information, such as Hello World
  4. Type [ESC]
  5. Type: WQ save exit

You can visit Vim Online Practice Simulator to familiarize yourself with Vim by booting.

Vim Basic Concept

Vim Common Patterns

Vim from Little White to Initial

  • Normal Mode
  • Insert Mode
  • Visual Mode
  • Command Mode

(1) Normal Mode
Normal mode is mainly used to browse and modify text content.

In general, opening Vim is normal mode. In any mode, just press the Esc key to return to normal mode.

Insert Mode
Insertion patterns are used to add content to text, and I and o are commonly used by myself.

I Start typing text and enter insertion mode before the character where the cursor is located

O (letter o) Open a new line under the line of the cursor to enter text and enter insertion mode.

(3) Visual Mode
The visual mode is equivalent to the normal mode after highlighting the selected text.

Visual mode has sub-modes, the visual feasible mode selected by the unit of action, using the “V” key to enter (that is, Shift + v); and the visual block mode selected by the unit of block, using the “Ctrl + v” key to enter.

Command Mode
Command mode is mostly used to manipulate text files (rather than the contents of text files), such as saving files, or to change the state of the editor itself, such as setting multi-column windows, labels or exiting the editor.

configuration file

By runningvim -VView the entire initialization process

The global configuration of Vim is generally in/etc/vimrcEffective for all users

User Personal Configuration in~/.vimrcYou can configure your favorite configurations like:set numberDisplay line number added

vim ~/.vimrc

" Configuration file for vim
set modelines=0         " CVE-2007-2438

" Normally we use vim-extensions. If you want true vi-compatibility
" remove change the following statements
set nocompatible        " Use Vim defaults instead of 100% vi compatibility
set backspace=2         " more powerful backspacing

" Don't write backup file if vim is being called by "crontab -e"
au BufWrite /private/tmp/crontab.* set nowritebackup nobackup
" Don't write backup file if vim is being called by "chpass"
au BufWrite /private/etc/pw.* set nowritebackup nobackup

let skip_defaults_vim=1

set ai                  " auto indenting
set ruler               " show the cursor position
set hlsearch            " highlight the last searched term
set history=1000        " keep 1000 lines of history
syntax on               " syntax highlighting
filetype plugin on      " use the file type plugins

Common Vim commands

Here are Vim’s relatively high-frequency commands. Use combination methods in daily use and remember several core commands.

Normal Mode

command Function (Interpretation)
h,j,k,l hTo the left,jExpressing the following,kTo the right,lExpress upward
Ctrl+ f Previous page
Ctrl+ b next page
weWE Skip to the back of the word, lowercase including punctuation
bB Jump the cursor forward in units of words, lowercase containing punctuation
o Open a new line
^ The beginning of a line
$ The end of a line
gg The first line of the document
[N]G Line N or last of the document
dd Delete a line
dw Delete a word
x Delete the last character
X Delete the previous character
D Delete the last character of a line
[N]yy Copy one or N rows
yw Reproduce a word
p paste
u Undo the previous step
ctrl+ r Restore the previous step
. Repeat the last command
/pattern Search for a string under the cursor, which can be a regular expression
?pattern Search the cursor for Strings
n Search down for the previous search action
N Search up for the previous search action

Insert Mode

command Function (Interpretation)
i Insert in front of the cursor
I Insert to the beginning of the row
a Insert it behind the cursor
A Insert to the last position of the line
oO New line
Esc Close insert mode

Visual Mode

command Function (Interpretation)
v Select one or more characters
V Select the row
ctrl+ v Selected column

Command Mode

command Function (Interpretation)
:set nu set number
:set nonu Cancel display line number
:set paste Setting Paste Mode
:%s/old/new/g Full text replacement
:w Preservation
:wq, :x Save and close
:q Close (saved)
:q! Forced closure
:split Divide a window horizontally
:vsplit Divide a window vertically
:close close window
Ctrl+ W Switch window,hTo the left window,jTo the lower window,kTo the upper window,lTo the right window

Reference Articles

Vim Chinese Documents

Concise VIM Training Strategies

Chapter 4 Vim Editor and Shell Command Script

The latest edition of Linux Should Learn That Way: Word Version, PDF Version