When you have a server, or operate several servers, there are few things more frustrating and frustrating than not being proficient with VIm. The VIM mode is also popular among various editors. Therefore, it is necessary to learn VIM.

There is no practical content in this section on servers, just simple operations and proficiency with VIm.

This chapter aims at how to learn VIM quickly, mainly reflected in the following three aspects

  1. How to use it flexibly with no plug-in and zero configuration (vim mode for various editors)
  2. Understand common configurations
  3. This section describes some common plug-ins

Mastering the operation of vim without plug-in and zero configuration can also greatly improve the efficiency of programmers in various editors.

With vim in common use, you’ll be comfortable with vim.

Knowing the common plug-ins, you’ll be able to tailor it to your IDE. But in general, it is of limited benefit to server operation and maintenance, and is often not as powerful as an IDE tool in a special language for programmers to code. However, it has the biggest benefit of satisfying maslow’s hierarchy of needs: pretending to be pushy. That’s why I use it.

  • Address: Using Vim and its configuration
  • Series of articles: My Server Operations Notes

High frequency operation

Here are the high-frequency actions I use countless times a day using Vim

  • :wThe fast preservation
  • <C-[>Exit insert mode, andescsimilar
  • 0Move quickly to the top of the line
  • ggQuickly move to the top of the file
  • GMove quickly to the end of the file
  • <c-o>Move to the last position
  • zzMove the cursor to the middle of the screen
  • : 12Move quickly to a particular row
  • ddShear line
  • yyCopy the bank
  • yi{Copy the contents of the parentheses
  • =i{Automatic indentation
  • <c-p>Automatic completion
  • "*yyCopy to the system clipboard
  • *Find keywords quickly, similar to sublime/vscodeCommand + d
  • :nohUnhighlight keyword
  • oQuickly get into INSERT mode and navigate to the next row
  • uundo

None Plug-in zero configuration operation

Fast moving

Fast mobility is the most important thing for Vim, more than anything else. It is also the basis for editing and modification.

  • Up (k) down (j) left (H) right (L) movement, it should be noted that the use of up, down, left and right arrows is prohibited

    If you need to move several lines, you can add a number before the operation. For example, 10j represents moving ten rows down. By combining numbers with operations, that’s vim’s idea.

  • Reduce the left and right movement of the previous step, which is too inefficient. Use B, B, W, W instead

    B) back a word W means forward a word. B) back a WORD W means forward a WORD, a big WORD.

    Among them, the difference between Word and Word is illustrated with an example. Hello. World has three words (‘hello’, ‘.’, ‘world’) but only one word.

  • Use f, F, T, T for finer left and right movement control

    F refers to find a character, quickly moving to the position of the next character, and f refers to the previous search. Combine B and W to achieve fast left and right movement. T refers to tail a character, the character before the position of the next character, and t refers to the previous search.

  • Use 0, $to move the beginning and end of the line

  • Use % to quickly move to the match character

    Such as moving quickly from open parentheses to close parentheses, or from open quotes to close quotes, is most commonly used in coding!

  • Use

    ,

    to move up and down extensively

    < Ctrl-D > move down half a page,

    move up half a page.

    You can also use

    ,

    to move the entire page.

  • Use GG, G to move first and last lines

  • :128 Indicates a quick location to 128 lines. Currently, it is used only in debugging

  • Zz quickly positions the current cursor to the middle of the screen, ZB to the end of the screen, and ZT to the top of the screen

  • * Position the word under the current cursor and point to the next one, # point to the previous one

  • Gd is commonly used in encoding to locate the declaration position of the current variable and GF to the file pointed to by the current path.

  • Finally, if you find that you have made a mistake, use

    -o to return to the position above the cursor

The editor

Vim edits are in Insert Mode, and the above quick moves are in Normal Mode. Editing text requires first going into Insert Mode.

I, I, a, a, O, o go into Insert Mode.

I refers to insert text, which is edited before the cursor, and I refers to the beginning of the line. A refers to append text, which is edited after the cursor, and A refers to the end of the line. O refers to append text, which is edited on the line after the cursor, and O refers to edit on the line before the cursor.

Personal habits: I, A, O, O are used more than I and A.

Esc and

can exit Insert Mode.
[>

I prefer to use

because Esc is too far away, and Esc is prone to conflict with other hotkeys in some editors.
[>

Modify the

Delete can also be manually deleted by using the DELETE key in Insert Mode, but the efficiency is too low, it is recommended to delete in Normal Mode, just enter viM state is Normal Mode.

  • Use x(dl) to remove specific characters

    You can combine x with the quick movement described above to delete specific characters under the cursor

    Put an L in brackets to indicate that x is short for DL.

    ddeleteIs the basis for all modification operations.dldlDelete the character to the right of the cursor.dhThe character to the left of the delete cursor, the basic form of all deletes, is the core idea of Vim.

  • Use daW to delete specific words

    Daw means to delete a word. Db, dw can also be used to delete words.

  • Use dt, df plus a specific character to delete the text before the character

  • Use di(, da(to delete text within specific symbols, such as parentheses and quotation marks

    Di (means delete in (, not delete parentheses. Da (means delete a(, will be deleted with parentheses. The same goes for di’, di” and so on, most commonly used in coding!

  • Use D (D $) to delete all text after this character

  • Delete the entire line using dd

  • Replace all d of the above operations with C, indicating that the deletion will enter editing mode

    C stands for change, meaning to delete, and like D, is the basic verb of vim

  • R plus a specific character indicates that a specific character is used instead of the original character

Files and multiple Windows

  • Use :Ex (Explore) to browse the directory

    Locate the file and press Enter to enter the specified file

  • Use :ls to list buffers

    Buffer list to save the most recently used files, the line has a label

  • Use :bn to access the most recently used file

    Bn refers to buffer next, the next buffer in the buffer list, that is, the last file used

  • Enter the file numbered N in the buffer list using :b[N]

    B 10 refers to buffer 10, which enters the buffer list, i.e. the file was used last time

  • Use: SBN, : VBN to open recently used files in a new window

    S means split, horizontal. V stands for vertical.

  • Use :on(ly) to keep only the current window

Basic operation

Basic operations refer to find, replace, undo, redo, copy, paste, save, etc

  • / {pattern} to find

    / And then the word or regular expression to be searched. N down, n up.

  • : s/aa/bb/g to replace

    S stands for substitute and G stands for global substitute.

  • U to cancel

    U stands for undo, undo. Can be combined with a number for multiple undo.

  • The < Ctrl – r > redo

  • Yy copies the entire line

    Y stands for yank, copy. By combining y with fast movement, you can use multiple cases of copying, such as copying the contents of parentheses, copying the contents of quotes.

    When copying, the current contents are put into a register, using :reg to view the register list.

  • P paste

    P is for paste.

  • “*y Copies content to system clipboard

    The :reg will list the registers, “* the register represents the system clipboard (), so this is putting the contents on the system clipboard.

    If the list without the registers, vim does not support the system clipboard, also can use the command vim – version | grep clipboard.

  • “*p Paste the system clipboard content

Vim configuration

1tab == 2space

set expandtab
set smarttab
set shiftwidth=2
set tabstop=2
Copy the code

Keep Operation Records

When you close a file and re-enter it, you can use u to undo it

set undofile
set undodir=~/.vim-config/undo_dirs
Copy the code

Swap files are not generated

"Do not generate swap files (swap files are generated when a file is opened but not closed properly)
set noswapfile
Copy the code

The plug-in

The following are the plugins used in my VIm configuration, and the shortcut keys may be customized by me.

nerdtree

File manager

  • ,nnToggle the file manager window, similar to Sublime’sCommand + k + b
  • ,nfLocate the current file location

In the file Management window

  • maCreate a file or folder
  • mdDelete files or folders
  • IToggle the display status of hidden files

ctrlp.vim

CTRLP, similar to Sublime’s CTRLP

  • <c-p>Find files under the current project
  • ,bLook for files in buffer
  • ,fLook in recently opened files

In CTRLP window, < C-j > and < C-K > control up and down movement.

ag.vim

Find keywords, similar to Sublime’s Command + Shift + F

  • Ag key *.jsFind keywords under a particular file

Note: The_silver_searcher needs to be installed first

vim-commentary

Annotation commands

  • :gccComments the current line, similar to sublime’s<c-/>

vim-fugitive

Git extensions

  • :GblameView the ownership of the current row
  • :GdiffView differences with workspace files
  • :GreadThe equivalent ofgit checkout -- file
  • :GwriteThe equivalent ofgit add file

syntastic

Syntax checker plugin to set ESLint

  • :SyntasticCheckSyntax check, the default syntax check will be performed when saving, but there will be a lag
  • :lne[xt]Next grammatical error
  • :lp[revious]The last grammatical error
  • :! eslint %:p --fixAutocorrect error

emmet-vim

  • <c-y>,Similar to sublime<c-e>

delimitMate

Parentheses and quotation marks are automatically completed

goyo

  • :GoyoSwitch to Gotyo mode

vim-colors-solarized

You can change background to Dark and light in the configuration file to switch themes

summary

This chapter will help you get comfortable with using Vim to edit text on a server and, if necessary, to program in Linux. In addition to being proficient with VIm on a server, however, you also need to deal with multi-window management. See the next chapter on TMUX and multi-window management.


Welcome to follow the public account Shanyuexing. I will regularly share some articles on the front and back end and operation and maintenance, and there will be a daily review and summary of technology and life. Welcome to follow and exchange