VimLearn

Just for personal learning and some notes


What

Vim is a mode text editor which has many modes
including Normal Mode, Insert Mode etc.

Each mode has its own functions and operations.

The normal mode in Vim is like a language, that we have different operations,
hava different concepts and commands,
and we can combine them to better edit our file in command line mode.

  • the conclusion from the video that introduces the Vim

The combination of commands are like [extra_param][command]

Mode

  • Normal Mode -> with key ‘i’ -> Insert Mode
  • Normal Mode -> with key ‘R’ -> Replace Mode
  • Normal Mode -> with key ‘v’ -> Visual Mode
  • Normal Mode -> with key ‘Shift V’ -> Visual Mode lmo
  • Normal Mode -> with key ‘Ctrl V’ -> Visual Mode block
  • Normal Mode -> with key ‘:’ -> Command-line Mode

Vim Command

‘:help command’ - list the introductions of the command

We should know that in Vim, the command ‘:w’ and the command ‘w’ is different.
The first is the vim command, and the second is just a command in normal mode

When we enter the introduction, we can use ‘:q’ to quit and back to our open file.
Like we open another file which includes the introductions of the command.

‘:w’ - save the file

‘:q’ or ‘:quit’ - quit the current window not the whole vim

In vim, there is concept of ‘window’ such as when we use ‘:sp’ command to split window,
or use ‘:help’ to open the window which contents the introduction of the command.
When we open this window, we can use ‘:q’ to quit them and back to our open file.

‘:qa’ - quit all, this is the command to quit the vim, or we can say, quit all windows.

‘:set number’ - set line number

This is a vim command to put line number to better edit the file,
the usage of this we can use ‘: set number’ to temporary set the number,
once we need to put line number every time we open the file with vim,
we can add a file named ‘.vimrc’ (vim reconfigure) in our home directory ‘~/.vimrc’,
and put ‘set number’ to it, then next time we use vim we will find the line number.

‘:sp’ - split screen, split the current text screen so we can see mutil screens that shows the text.

‘:set sw’ - set the spaces which indent includes

‘/search’ - search command ‘/‘ can help us move to the position of searched words.
For example, ‘/is’ is to search the words “is”

Movement

these movements command can be used in normal mode

‘j’ - moves down
‘K’ - moves up
‘h’ - moves left
‘g’ - moves right
‘b’ - moves one word backward
‘e’ - moves to the end of a word
‘0’ - moves to the head of the line
‘^’ - the same effect as ‘0’ does
‘$’ - moves to the end of the line
‘^U’ - hold up, switch to up page
‘^D’ - hold down, swicth to down page
‘G’ - moves to the end of the buffers(file)
‘gg’ - moves to the head of the buffers(file)
‘L’ - Lowest, moves to the end of current page
‘M’ - Middle, moves to the middle of current page
‘H’ - Highest, moves to the top of current page
‘F[word to be found]’ - find the fisrt word that equals to the find param we give,
and the moves to that place. Note that this command’s range is limited to the current line.

Like we see in the conclusion,
this command abstracts our moving operations as commands in normal mode.

Thus we can combine these with other operations to help us move faster in the file,
such ‘3j’ command in normal mode can help us move 3 lines one time.

Text Command

Special Text

‘^’ - The start of one line
‘$’ - The end of one line

Normal Mode

‘X’ - Delete one Character where cursor is on.

‘v’ + cursor move - select the text you have selected

‘y(yank)’ - copy the select text

It’s a command which we can use it to copy the text, we can also use ‘yy’ to copy the whole line.
‘[number]yy’ is a special command which can help us copy the next [number] lines from the current line(includes the current line).
‘yw’ can copy the current word.

‘p(paste)’ - paste the copy line to the current position

‘o’ - add a new line after the line where the cursor locates.

‘O’ - add a new line as command ‘o’ and change into the insert mode

‘dd’ - delete the current line

‘u’ - undo the last change you did including actions in insert mode

‘di[parentheses]’ - for example, when cursor is in words “[htt//sfsdfdfa]”,
we can use ‘di[‘ command to delete the content which is included in the “[]”

‘da[parentheses]’ - delete all include the parenthese itself

Visual Mode

When we enter the key ‘v’ in normal mode, we will be in the state of ‘Visual Mode’.
This mode can help us select mutil words, then we can use ‘y’ or ‘p’ to operate on these words.
Or we can just operate one word one time.

‘V’ - when we use this command in Visual Mode or Normal Mode,
we can now select a whole line once we move

‘^V’ - when we use this command, we will enter the ‘visual block mode’,
which we can select a rectangular blocks of text.

Special Command

^V : Ctrl-V :

Expand Reading

Vim offers 12 clipboards which are “0,”1,”2……”9,”” ,
we can use ‘:reg’ in normal to check the content in clipboard,
the default clipboard is “” and “0,
we can use ‘“Ny’ in Visual Mode(^V) to copy the selected text to a clipboard

In conclusion, we can place ‘p’, ‘y’ or something else with ‘“Np’…,
the meaning is that we can copy or paste to and from different clipboards.


Settings for VIM

There are ways to set the VIM:

  1. System setting files are located in /etc/.vimrc
  2. User setting files are located in ~/.vimrc (priority is higher than system)

We can use command :set all in VIM to check the settings.

Reference

  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.

请我喝杯咖啡吧~

支付宝
微信