# 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

### 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 :

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.