One, multi-file editing 1. Use Vim to edit multiple files
There are two forms of editing multiple files, one being a parameter that is used before entering Vim is multiple files. Another is to enter vim and then edit the other files. Create two new files and edit them simultaneously
$ vim 1.txt 2.txt
Default Access 1.txt
to file editing interface
- Command line mode input
:n
edit 2.txt file, you can !
:n!
Force switch, the input of a file is not saved, just switch to another file
- Command line mode input
:N
edit 1.txt file, can be !
forced to :N!
switch, the input in the previous file is not saved, just switch to another file
2. Open a new file after entering vim
- Command line mode enter
:e 3.txt
open new file 3.txt
- Command line mode input
:e#
back to the previous file
- command-line mode input
:ls
to list previously edited documents
- Command line mode input
:b 2.txt
(or number) can be directly into the file 2.txt edit
- Enter
:bd 2.txt
(or number) in command-line mode to delete a file item from a previously edited list
- Command line mode input
:e! 4.txt
, new open file 4.txt, discard the file being edited
- Enter
:f
The file name you are editing in command line mode
- Input in command line mode
:f new.txt
, change the file being edited name to New.txt
3. Recover files
If the document is not saved due to a power outage, you can use the recovery method, enter the vim -r
document, input :ewcover 1.txt
to restore
$ vim -r 1.txt
Second, Visual Mode 1. Introduction to Visual Mode commands
- Enter in normal mode
v
(lowercase), enter the character selection mode, you can move the cursor, where the cursor will be selected. The selection is deselected when the V-meeting is pressed again.
- In normal mode input
Shift+v
(lowercase), enter the line selection mode, press V will be the entire row selection, you can move up and down the cursor select more rows, again, press once Shift+v
can be deselected.
- In normal mode
Ctrl+v
(lowercase), this is the area selection mode, you can select the rectangular region, and then cancel the selection by one time Ctrl+v
.
- Enter
d
Delete selection area in normal mode
- Enter
y
Copy selection area contents in normal mode
2. Visual Mode Command Practice
Copy the practice file to the current directory
$ cp /etc/protocols .
Open the practice file
$ vim protocols
- In normal mode
9G
, jump to line 9th, enter Shift+v
(lowercase v), enter the visual mode for row selection, select 5 rows, press >>
indent, indent 5 rows into oneshiftwidth
- Enter in normal mode
Ctrl+v
(lowercase v), enter visual mode for rectangular area selection, select the first column character and then x
delete the whole column
Third, Windows Operation 1. Introduction to Windows operation
Vim can open multiple windows in one interface for editing, which are called Vim windows. There are many ways to open a method, for example, you can use the command-line mode to enter : New
Open a new Vim window, and enter the window to edit a new file (normal mode input ctrl+w
can also, but Ctrl+w
the shortcut key for Chrome to turn off the tab in Chrome, so you can practice it in IE or other browsers, except for the : New
command, The various methods listed below can also open a new window in command mode or Normal mode:
- Command-line mode enter
:sp 1.txt
open new Landscape window to edit 1.txt
- Command-line mode
:vsp 2.txt
to open a new vertical window to edit 1.txt
Ctrl-w s
split the current window into two horizontal windows in normal mode
Ctrl-w v
split the current window into two vertical windows in normal mode
- In normal mode
Ctrl-w q
, it is: Q ends the split window. If you have input in a new window, you need to use the mandatory character! namely: q!
Ctrl-w o
Open a window in normal mode and hide all previous windows
Ctrl-w j
move to the following window in normal mode
Ctrl-w k
move to the upper window in normal mode
Ctrl-w h
move to the left window in normal mode
Ctrl-w l
move to the right window in normal mode
Ctrl-w J
move the current window below in normal mode
Ctrl-w K
move the current window to the top in normal mode
Ctrl-w H
move the current window to the left in normal mode
Ctrl-w L
move the current window to the right in normal mode
Ctrl-w -
reduce the height of the window in normal mode
Ctrl-w +
increase the height of the window in normal mode
2. Windows Operation exercises
Open the practice file
$ vim 1.txt
- command-line mode input
:new
open a new vim window
- Command-line mode enter
:sp 2.txt
open new Landscape window to edit 2.txt
- Command-line mode enter
:vsp 3.txt
open new Landscape window to edit 3.txt
- If you use a non-Chrome browser, you can use
Ctrl+w
the jump between windows
- Enter
:q!
exit multi-window editing in command-line mode of different windows
Iv. document Encryption 1. Create an encrypted document
$ vim -x file1
Enter your password to confirm the password so that the next time you open, VIM will ask you to enter the password
V. Executing external commands in vim
Enter command-line mode !
to execute external shell commands
:!ls
Used to display the contents of the current directory
:!rm FILENAME
Used to delete a file named filename
:w FILENAME
Save the file you are editing in the current VIM as a filename file
Vi. viewing Help in the Help system 1.vim
- Press
F1
vim
to open your own preset help document in normal mode
- Enter
:h shiftwidth
shiftwidth
The open Help file in command line mode
- Input
:ver
display version and parameters in command line mode
Seven, function set 1.vim function setting
Can be set when editing the file function settings, such as the command line mode input :set nu
(display number of lines), set value exit Vim will not be saved. To permanently save the configuration, you need to modify the Vim configuration file. Vim configuration file ~/.vimrc
, you can open the file for modification, but be careful not to affect the normal use of vim
2. Get the current settings
- Enter
:set
or :se
display all modified configurations in command line mode
- command-line mode input
:set all
displays all the SetPoint values
- Command-line mode
:set option?
to enter a setting value that displays option
- Command line mode to enter the
:set nooption
cancel current set value
Description of the 3.set function
:set autoindent(ai)
automatic indentation of input settings in command line mode
- Command line mode input
:set autowrite(aw)
set AutoArchive, default not open
- Enter or in command line
:set background=dark
mode light
, set the background style
- Command line mode input
:set backup(bk)
set automatic backup, default not open
- Command line mode input
: set cindent(cin)
set C language style indent
For more detailed parameters, please refer to the VIM manual
(Big Data Engineer Learning Path) The second step is to get started with the advanced features of the VIM editor----