The Knowledge about Vim

1. The models of Vim

  1. normal mode
  2. insert mode
  3. visual mode
  4. replace mode
  5. select mode

1.1 How to switch between models

  • normal mode —– press i —–> insert mode
  • normal mode —– press v —–> visual mode
  • insert mode —– press esc —–> normal mode
  • visual mode —– press esc —–> normal mode
  • normal mode —– press : —–> command line

1.2 How to exit the Vim

1.2.1 Keeping the changes and exit

  • : wq

1.2.2 Changed text and exit without saving

  • : q!

1.2.3 Without changing text and exit

  • : q

2. Basic settings

2.1 Configure the settings by editing the vimrc

2.1.1 What is the vimrc

  • All the debugging and configuration will be stored in the vimrc

2.1.2 Where is the vimrc

  • For windows: $HOME/_vimrc
  • For Mac/Linux/Unix: ~/.vimrc
  • If the vimrc doesn’t exist, you can create it by yourself.

2.1.3 Configuration for the vimrc

2.2 Configuration for the <leader> key

  • The key is mapped to \ by default. So if you have a map of t, you can execute it by default with \ +t. For more detail or re-assigning it using the mapleader variable,

Hide line number, in the vim editor

Show line number, in the vim editor

Turn on relative line numbers

Turn off relative line numbers

use the incremental search

3. vim-plug

  • A Vim plugin is a set of Vimscript files that are laid out in a certain directory structure.

4. Motions and Operation of the vim

4.1 Motions of the vim

1. words motions
w move to next word
if the cursor is in the space go to the head of next word
if the cursor is inside the word go to the head of next word (including of jumping the space)
b motion
if the cursor is at the head character of the word go to the head of previous word (including of jumping the space)
if the cursor is not at the head character of the word go to the head of the word
e motion
if the cursor is pointing at the end character of the word go to the end of the next word
if the cursor is not pointing at the end character of the word go to the end of the word
2. Left-right motion
movement by character
h move the cursor to left, 1 character
l move the cursor to right, 1 character
movement by line
$ go end of the Line
0 go head of the Line
^ go the 1st Non-space character the of the Line
3. Up-down motions
movement by character
j go next line
k go previous line
gg go to the first Non-space character of the file
G go to the last Non-space character end of the file
4. Other motions
movement by character
% while the cursor is on a (,),[,],{, or } goes to its match
H go to the 1st line in the screen
M go to the middle line in the screen
L go to the last line in the screen

4.2 Operators of the vim

4.2.1 Basic operators

Operator Definition
y yank (copy)
p paste
d delte
c change the character where the cursor locates
C change, from the cursor to the end of the line
s substitute the character where the cursor locates
S substitute the whole line
r + [character] replace the character
R enters Replace mode until <ESC> is pressed
> indent
< unindent
gu lower case
gU upper case
i input
x delete the character on the cursor (only delete 1 character)
A append text after the line
u undo previous actions
U undo all the changes on a line
CTRL-R undo the undo’s
o to open a line BELOW the cursor and start Insert mode
O to open a line ABOVE the cursor
a to insert text AFTER the cursor
A to insert text after the end of the line

4.2.2 Formula of the operators and motions

  1. [number] + operator + motion
  2. operator + [number] + operator (2 operators are the same)
Combination Definition
dw 1. if the cursor in the head of a word, it will delete the whole word and the space after the word 2. if the cursor isn’t on the first of a word, it will delete the characters after on the cursor (including the character on the cursor) and the space behind it
d$ delete all the words after the cursor (including the character on the cursor)
de to the end of the current word and the(including the character on the cursor and the space)
dd to delete the line
2dd to delete two lines

4.3 Text-object

Text Definition
w word
s sentence
p paragraph
t tag

5. Command line

Command Definition
/ followed by a phrase searches FORWARD for the phrase. After a search type n to find the next occurrence in the same direction or N to search in the opposite direction.
? followed by a phrase searches BACKWARD for the phrase. After a search type n to find the next occurrence in the same direction or N to search in the opposite direction.
CTRL-O takes you back to older positions
CTRL-I Take to newer positions

6. Execute an external command

:![command]<enter>

:![command] FILENAME <enter>

7. Introduction to UltiSnips

7.1 Prerequirement for the install

  • 1. install of vim-plug
  • Installation of Python2 or Python3

7.2 Installation of the UltiSnips

vim ~/.vimrc

7.3 How to configure the UltiSnips

Reference:

1. vimtutor

2. https://vimzijun.net/

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.