How to use split in vim
First, the role
Use split to display two different files, or to display two different places of a file at the same time, or to compare two files by side. This can all be achieved through the split window. For example, the left two windows are mytool.h and mytool.cpp to the right of the two windows are Commonfun.h and commonfun.cpp. Similarly, you can read the code when the configuration file, when debugging a new window, this feature to bring us a lot of convenience.
Second, usage
Create a new 5 files: main.cpp, Commonfun.h, Commonfun.cpp, mytool.h, mytool.cpp write some code.
Then there are a few commands:
Vim Commonfun.h
Split Commonfun.cpp
Press Ctrl+w +k to switch the cursor to the window above
Vsplit mytool.h
Press ctrl+w+ J to switch the cursor to the following window
Vsplit Mytool.cpp
Can achieve the above effect.
Third, the specific command analysis
Command |
Explain |
Split |
Horizontal split Window |
Vsplit |
Vertical split Window |
Ctrl+w |
Jump between windows |
Ctrl+w+h |
Jumps the cursor to the adjacent left window (HLJK and the same usage in vim) |
Ctrl+w+l |
Jumps the cursor to the adjacent right-side window |
Ctrl+w+j |
Jumps the cursor to the next adjacent window |
Ctrl+w+k |
Jumps the cursor to the adjacent window above |
Ctrl+w+t |
Jumps the cursor to the topmost window |
Ctrl+w+b |
Jumps the cursor to the bottom window |
Iv. Specific Command parsing
1,: Quit&close
Both can implement the function of closing the window, but quit closes the last window, and close does not close the last window. Use close without worrying about accidentally exiting Vim.
2.: only
This command can close all other windows. This command closes all windows except the current window. If one of the windows you want to close does not have a disk, Vim displays an error message and the window is not closed.
3, Ctrl-w
If you press and hold CTRL-W, the cursor will continue to jump between windows. If you have good eyesight, you can use it. If you need precise positioning, you can add hlkj (left and right) as in Vim.
4.: Split
This command splits the current window, so be careful when using this command by jumping the cursor to the window you want to split.
5,: Qall
All exit, Vim will not exit if any of the windows are not filed. At the same time the cursor will automatically jump to that window you can use the ": Write" command to save the file or ": quit!" to discard the changes.
6,: Wall
This command represents "Write All" (save All). But in fact, it will only save the modified file.
7, Vim-o one.txt two.txt three.txt
This command is used under the terminal, that is, one-time open 3 files and use the Split form display.
How to use split in vim