There are many text editors, including gedit and kwrite in graphic mode, Vi, VIM (enhanced version of VI), and nano in text mode. VI and Vim are the most commonly used editors in Linux. Someone once said that there are three kinds of people in the world: VI, emacs, and Third.
(1) initial personalized configuration of your vim
1. What is Vim?
Vim is VI improved, an enhanced version of the editor VI. It is extremely powerful and conforms to the IT Engineer (programmer, O & M) habits. If you are a professional se, you must be looking for an excellent editor that can be customized and flexibly edited. The answer is vim or Emacs.
2. Where is the configuration file?
The configuration file for Windows is the vimrc file under the vim installation directory.
In Linux, the configuration files for RHEL and centos are/etc/vimrc, And the configuration files for Debian and Ubuntu are/usr/share/Vim/vimrc.
The configuration file for Mac OS X is/usr/share/Vim/vimrc.
3. What does RC in vimrc mean?
Why is this meaningless question also listed? The reason is very simple, that is, the second question I want to ask at the beginning of my exposure to VIM is this (the first is the above "1 "). Generally, some commands to be initially executed when running a software, environment, or tool are called run commands, or RC. According to wikipedia.org, the RC abbreviation is derived from MIT's compatible time-sharing system (ctss) [Reference 1]. So if you see systemrc or screenrc later, you will know why.
4. Three basic modes
In "everyone learns Vim", we mentioned that Vim has 6 + 5 models. However, apart from the degree of subdivision, there are actually only three commonly used models: normal Mode, insert mode, and command-line mode.
From normal mode to insert mode, you can press I, I, a, a, O, O, R, R. I and I represent insert, R and R represent replace ).
From insert mode to normal mode, you only need to press ESC.
From normal mode to command-line mode, you can press ":", "/", and "?". ":" Indicates the vim command, "/" indicates the string to be searched down, "?" Indicates that the string to be searched up is entered later.
From command-line mode to normal mode, you only need to press ESC.
You can understand normal mode as normal. To enter any other mode, you need a special method. To return to normal mode from other special modes, Press ESC.
5. The most common configurations in VIM
When you try to google some other people's vimrc configuration, you will find an article called the ultimate Vim configuration, but its author, amix later mentioned in his blog [Reference 2] that the Google search vimrc will rank in the top 10 Vim configuration files, and now it is outdated, so he provides some updates.
(1) color settings
Syntax on "Enable code highlighting
Syntax off "disable code highlighting
Syntax enable "Enable code highlighting
(2) Search Settings
Set hlsearch "enable search highlighting
Set nohlsearch "Disable search highlighting
Set incsearch
Set ignorecase "Case Insensitive during search
(3) User Interface
Set showmode "enable Mode Display
Set ruler "indicates that the cursor position is enabled.
Set number "displays the row number
Set Nonu "no row number is displayed
Set cursorline "emphasizes the row where the cursor is located
Set Partition Height = 1 "command part height is 1
(4) edit the auxiliary Configuration
Set autoindent "auto indent
Set noautoindent "not auto indent
Set smartindent "smart indent
Set autoread "when the file is changed externally, VIM automatically updates and Loads
Set showmatch "show matching parentheses
Refer:
[1] Run commands, http://en.wikipedia.org/wiki/Run_commands
[2] The ultimate Vim configuration (vimrc), http://amix.dk/blog/post/19486
(2) frequently used status switch buttons
1. Normal Mode-> insert mode
I lowercase letter I, insert at the cursor position
Lowercase letter A, insert at the next position of the cursor
I capital letter I, insert at the first non-space position in the row where the cursor is located
A capital letter A, inserted at the last character of the row where the cursor is located
O lowercase letter O, insert a new line at the next line of the row where the cursor is located
O uppercase letters o, insert a new line at the top of the row where the cursor is located
R: lowercase letter R. Replace the character at the cursor once.
R capital letter R. The character at the cursor is continuously replaced until you Press ESC.
2. Normal Mode-> command-line mode
: W save the file
: W! Force save files (provided that you have the permission to modify files)
: Q: exit the buffer.
: Q! Force exit the buffer without saving
: WQ: Save the file and exit the buffer.
: ZZ save the file and exit
: WQ! Force save the file and exit the buffer (provided that you have the permission to modify the File Access)
: W <FILENAME> Save As file named filename
: N1, N2 W <FILENAME> Save the data from row N1 to row N2 as a file named filename
: X if the file is changed, save and exit. Otherwise, exit directly.
3. insert mode-> normal mode
Press ESC
4. command-line-> normal mode
Press ESC
(3) commonly used cursor movement buttons
1. cursor character operations
J down
K up
H left
L right
$ Move the cursor to the end of the line. Pay attention to press shift.
0 move cursor to the beginning of the line (home)
^ Move the cursor to the first non-blank character (home) at the beginning of the line. Press shift.
2. cursor word operations
W cursor move to the first word of the last word
W cursor moves to the first word of the last word and ignores punctuation marks
E move the cursor to the end of the last word
E move the cursor to the end of the last word and ignore punctuation marks
B move the cursor to the first word of the previous word
B. move the cursor to the beginning of the word and ignore punctuation marks.
3. cursor sentence Operations
) Move the cursor to the beginning of the last sentence.
(Move the cursor to the beginning of the previous sentence.
% Used with "(" and ")" to find the matching half
4. cursor Row Operations
Move g cursor to the first non-blank character in the last line of the document
Ng cursor moves to the nth line of the document, equivalent to ": N"
Move the GG cursor to the first non-blank character in the first line of the document, equivalent to "1 GB", also equivalent to ": 1 ″
<N> move the cursor down n rows
5. Optical section operations
} Move the cursor to the beginning of the next section.
{Move the cursor to the beginning of the previous segment
% Used with "(" and ")" to find the matching half
6. cursor page operations
CTRL + F page flip (Pagedown)
CTRL + B page up (Pageup)
CTRL + D flip down half page
CTRL + u flip up half page
H move the cursor to the first line of the current display page
M cursor moves to the middle line of the current display page
L move the cursor to the last line of the current display page
7. freely operate the cursor
CTRL + O return to the top position of the cursor
(4) frequently used editing buttons
1. Delete)
Dd deletes the row where the cursor is located.
NDD deletes n rows down from the row where the cursor is located
D1g delete all rows from the row where the cursor is located to the first row
DG deletes all rows from the row where the cursor is located to the last row
D $ Delete All characters from the cursor position to the end of the line
D0 deletes all characters from the cursor position to the beginning of the line
2. copy operation (Yank)
YY copy the row where the cursor is located
Nyy copies n rows down from the row where the cursor is located
Y1g copies all rows from the row where the cursor is located to the first row.
YG copies all rows from the row where the cursor is located to the last row
Y $ copy all characters from the cursor position to the end of the line
Y0 copies all characters from the cursor position to the beginning of the line
3. paste (paste)
P: lowercase letter P. paste the data in the clipboard, starting from the next row in the row where the cursor is located.
P capital letter P, paste the data in the clipboard, starting from the last line of the row where the cursor is located
4. Undo and redo operations)
U (UNDO) undo the previous operation
CTRL + R (redo) Redo the previous operation
5. Repeated operations
. Repeat the previous operation.
6. Replace)
R replaces the character at the cursor
R enters the replacement mode until you Press ESC to exit
CC replaces the row where the cursor is located
CW replaces the English word of the cursor
~ Case sensitivity
7. Typographical operations
: Le <ft> align the cursor row to the left
: RI <ght> align right of the row where the cursor is located
: Ce <nter> center of the row where the cursor is located
(5) frequently used multi-buffer operation buttons
1. Multi-file editing mode
(1) The argument list mode contains multiple file path parameters when opening the vim editor.
(2) buffer list mode: after entering the vim Editor, open multiple buffers for editing.
2. open multiple files in a single buffer zone
: Files: displays the files currently opened.
: N switch to the next Buffer
: N switch to the content of the previous Buffer
: 2n switch to the next Buffer
: Bn next buffer content (buffer next)
: Buffer previous)
3. open multiple files in multiple Buffers
: SP [filename] open a new buffer. If filename exists, the content is the file; otherwise, it is the current file.
CTRL + W n create a buffer
CTRL + w Q exit the buffer where the cursor is located
CTRL + w j move cursor to next Buffer
CTRL + w k move cursor to previous Buffer
CTRL + w l move cursor to right Buffer
CTRL + w h move cursor to left Buffer
CTRL + W v left and right cutting window New Buffer
CTRL + w s create a buffer in the Upper/lower cut window
CTRL + W o maximize the buffer where the cursor is located, and hide other Buffers
(6) shortcut keys for common search and bookmarking operations
1. Search for strings
/String: Search down the string "string"
? String to search for the string "string"
2. Repeat the previous search
N find the next matched string based on the last Search Condition
N find the last matched string based on the last Search Condition
3. Search for words
* Search for words at the cursor position (exact match)
# Search for words at the cursor position (exact match)
G * search down the word at the cursor position (partial match)
G # search for words at the cursor position (partially match)
4. Mark)
Ma a is a lowercase letter, which sets the document bookmarks A for the cursor
Ma A is an uppercase letter, and a is the place where the cursor is located.
5. Use bookmarks (mark)
'A to file bookmarks A, above the tab key
'A to the beginning of the line where file bookmarks A are located, and left of the Enter key
'A to bookmarks A, above the tab key
'A to the beginning of the row where global booka is located, and left of the Enter key
'N' if n = 0, the buffer will open the last document, and the cursor is at the last position of the last edit, 1-9 and so on.
'N' if n = 0, the buffer will open the last document, and the cursor will start at the beginning of the row where the last edited position is located, and so on from 1 to 9.
6. view the bookmarks list
: Marks: view all current bookmarks
(7) Encryption
1. Encrypt Your text files
When you use Vim to open or create a file, if you add the-x parameter, that is:
Vim-x filename
Then Vim will prompt you:
Enter entryption key:
After you enter the password, VIM will prompt you to repeat the input to confirm:
Enter same key again:
When you set the password, it is displayed in *, not in plaintext. When someone (including yourself) opens the file next time, VIM will prompt:
Need encryption key for "Main. cpp"
Enter encryption key:
In this case, you only need to enter the password you set before. If the password you entered is incorrect, VIM does not prompt you for a wrong password, but displays a bunch of meaningless junk code.
2. unencrypt and reset the password
Open the encrypted file and enter:
: Set key =
In this way, your password is set to null, and you do not need to enter the password in the future. If you reset the password, you can enter:
: X
Note that X is an uppercase letter. At this time, VIM will prompt you, as long as you repeatedly enter two new passwords:
Enter entryption key :*****
Enter sanme key again :*****
3. Encryption Problems
Vim's encryption function can be said to be a lot of problems. For example:
(1) If the password is incorrectly entered, VIM will not reject visitors from editing files. When the file is edited and saved in case of garbled characters, the entire file becomes messy and unrecognizable. In the future, even if you use the correct password to open the file, you will not see the correct document.
(2) If the source code file to be compiled is encrypted, it cannot pass the compiler syntax check.
(3) files cannot be encrypted. What problems does this cause? The problem is that if other users find a way to read your swap file, they can bypass the decryption link and your encryption will be meaningless. The solution is not to use swap files. There are three methods. One is to modify your vimrc file (Vim configuration file ):
Set noswapfile
Second, enter the command at the beginning of opening the file with vim:
Vim-X-N filename
(Note that-X is an encryption parameter. It has nothing to do with what we call swap. Do not confuse it)
Third, after entering Vim to edit the file, enter:
: Setlocal noswapfile
However, the disadvantage of not switching files is that you may face the tragedy of data loss that cannot be recovered. So if you want to use encryption and do not want to lose files, you should press ": W.
Vim practical basic operation skills