[Vim practice] Various operation methods for convenient screen division
Vim, like other modern editors, is designed for easy screen splitting. You can move between windows with commands, so once you get used to it, you can smoothly work in multiple windows. It’s not a difficult command, and there’s not a lot to learn, so let’s become familiar with it.
Practice of vim
Split screen
Command to split the screen. There are separate commands for top and bottom and left and right. When splitting, the windows are evenly divided into equal widths. Another command is provided to resize the window.
Even if you type the command “:split” or “:vsplit”, it works in the same way.
Split screen vertically | :sp (:split) | |
---|---|---|
Split the screen | :vsp (:vsplit) |
Close window
Command used to close a split window. If you close all windows, you will be returned to the terminal (command prompt). If you aim to be a vimmer, remember all the commands below. There is always an opportunity to use it.
Close current window | :q |
---|---|
Close all windows | :qall |
Close all but the current window | :only |
Move window
Even if you divide the window, you can not move unless you know the following command, so be sure to remember it. The key to input after “ctrl + w” is the same as the key for moving the cursor in vim, so I think it can be moved intuitively.
Move windows sequentially | ctrl + ww |
---|---|
Move to bottom window | ctrl + wj |
Move to upper window | ctrl + wk |
Move to left window | ctrl + wh |
Move to right window | ctrl + wl |
Change window size
When the window is split, it is split into the same size, but you may want to change the size depending on your work. In that case, use this command to change the size of the window. You can specify the degree of change by entering a number before typing the following command. (Example: 5 ctrl + w >)
Increase the vertical size of the current window | ctrl + w + |
---|---|
Reduce the vertical size of the current window | ctrl + w – |
Increase the horizontal size of the current window | ctrl + w > |
Reduce the horizontal size of the current window | ctrl + w < |