Vim split window command

Source: Internet
Author: User

The vim split window command displays two different files, or two different parts of a file, or two files are compared side by side. All of this can be achieved through split windows. | 08.1 | split window | 08.2 | split window with another file | 08.3 | window size | 08.4 | Vertical Split | 08.5 | move window | 08.6 | execute commands on all Windows | 08.7 | use vimdiff display difference | 08.8 | Miscellaneous Chapter: | usr_09.txt | use the previous chapter of the GUI version: | usr_07.txt | edit multiple file directories: | usr_toc.txt | * 08.1 * The simplest command to open a new window is as follows :: the split command splits the screen into two windows and places the cursor in the window above: + ------------------------------------ + |/* file one. c */| ~ | ~ | One. c ==================================|||/* file one. c */| ~ | One. c ==========================|||+ -------------------------------------- + you can see the display two windows of the same file. A row with "=" is a status bar used to display information about the window above it. (On the actual screen, the status bar is reversed.) The two Windows allow you to display two parts of a file at the same time. For example, you can display the variable definitions in the window above, and the codes using these variables are displayed in the window below. The CTRL-W w command can be used to jump between windows. If you go to the window above, it will jump to the window below. If you go to the window below, it will jump to the window above. (The CTRL-W can do the same function which is to prevent you from shrinking your hand late from pressing the CTRL key sometimes for the second time .) Close the window: in fact, any exit edit command can close the window, such as ": quit" and "ZZ. However, "close" can prevent you from accidentally exiting Vim when there is a window left. Close the window. If you have already opened a complete window, but now you only want to edit one of them, the following command can complete this function :: only this command closes all Windows except the current window. If there is no disk in the window to be closed, Vim will display an error message and the window will not be closed. * 08.2 * use the following command to open another window and use this window to edit another specified file: split two. c. If you are editing one. c, the command execution result is: + ------------------------------------ + |/* file two. c */| ~ | ~ | Two. c ==================================|||/* file one. c */| ~ | One. c ==========================|||+ -------------------------------------- + open a window to edit A new file, you can use the following commands: new you can use the ": split" and ": new" commands to create any number of windows. * 08.3 * window size: the split command can accept the number prefix. If this prefix is specified, this number is used as the window height. For example, the following command can open a three-line window and edit the file alpha. c: 3 split alpha. c. You can change the size of an opened window in several ways. If you have a mouse, it is easy: move the mouse pointer to the status bar of the split two windows, and drag up and down. To expand the window: CTRL-W + to zoom out the window: CTRL-W-the two commands accept the Count prefix to specify the number of rows to expand and contract. So "4 CTRL-W +" will increase the window by 4 rows. To set a window to the specified height, you can use this command: {height} CTRL-W _ is to enter a value first, then enter the CTRL-W and an underscore (Shift plus "-" in the American English keyboard "-"). To extend a window as large as possible, you can use the CTRL-W _ command without a number prefix. Using Mouse labels in Vim allows you to quickly complete a lot of work with a keyboard. However, unfortunately, changing the window size requires many keys. In this case, using the mouse will be faster. Move the cursor over the status bar, hold down the left button, and drag it. The status bar moves, which makes a window bigger and smaller. Select the 'winheight' option to set the minimum expected window height while the 'winminheight' option to set the minimum "hard" height. Similarly, 'winwidth' sets the minimum expected width while 'winwidth' sets the minimum hard width. The 'windows' option keeps all windows in the same size when they are closed or new windows are opened. * 08.4 * Vertical split ": split" command to create a window above the current window. To open a new window on the left of the window, run the following command: vsplit or: vsplit two. the result of the c command is as follows: + -------------------------------- + |/* file two. c */|/* file one. c */| ~ | ~ | ~ | ~ | ~ | ~ | Two. c ==================== one. c ==============|||+ ------------------------------------------------ + in reality, the vertical lines in the middle are reversed. This is called vertical split line. It separates a window from the left and right. There is also a "vnew" command to open a Vertical Split new window. Another method is: the vertical new "vertical" command can be placed before any command to split the window. This will replace horizontal split with vertical split when split the window. (If the command does not split the window, This prefix does not work ). You can use the vertical and horizontal separation commands to open any number of windows, and you can set the window layout at will. Next, you can use the following command to jump between Windows: CTRL-W h jump to the Left window CTRL-W j jump to the following window CTRL-W k jump to the above window CTRL-W l jump to the right window CTRL-W t jump to the top window CTRL-W B Jump to the bottom window you may have note that the command like moving the cursor is used to jump to the window. If you like, use the direction keys. * 08.5 * You have split some windows, but the current position is incorrect. In this case, you need a command to move the window. For example, you have opened three windows, like this: + ------------------------------------ + |/* file two. c */| ~ | ~ | Two. c ==================================|||/* file three. c */| ~ | ~ | Three. c ======================================|||/* file one. c */| ~ | One. c ==========================|||+ -------------------------------------- + apparently, the last window should be at the top. Move to that window (w with CTRL-W) and enter the following command: CTRL-W K here uses the capital K. In this way, the window will be moved to the top. You can note that K is used to move up. If you are using vertical split, the CTRL-W K will move the current window above and extend to the width of the screen. Assume that your layout is as follows: + ------------------------------------- + |/* two. c */|/* three. c */|/* one. c */| ~ | ~ | ~ | ~ | ~ | ~ | ~ | ~ | ~ | ~ | ~ | ~ | ~ | ~ | ~ | Two. c ========= three. c ========== one. c ========||||+ ----------------------------------------------- + when you are in the middle window (three. c) using the CTRL-W K, the result will be: + --------------------------------------------- + |/* three. c */| ~ | ~ | Three. c ======================================================||/ * two. c */|/* one. c */| ~ | ~ | Two. c ============================ one. c ==================||| + ----------------------------------------------------- + there are three similar commands (you have probably guessed it ): CTRL-W H move current window to leftmost CTRL-W J move current window to bottommost CTRL-W L move current window to rightmost * 08.6 * execute command on all windows you open several windows, now you want to exit Vim. You can close each window separately. The faster method is: qall, which indicates "quit all" (exit all ). If no disk is saved in any window, Vim will not exit. At the same time, the cursor will automatically jump to that window. You can use the ": write" command to save the file or ": quit! "Discard modification. If you know that a window has been changed and you want to save it all, run the following command: wall, which indicates "write all" (save all ). But in fact, it only saves modified files. Vim knows that it makes no sense to save a file that has not been modified. In addition, the combined commands ": qall" and "wall": wqall save all modified files and exit Vim. Finally, the following command exits Vim and gives up all modifications: qall! Note that this command cannot be undone. To open a window for all parameters for Vim to open a window for each file, you can use the "-o" parameter: vim-o one.txt two.txt three.txt. The result will be: + ------------------------------- + | file one.txt | ~ | One.txt =================================| | file two.txt | ~ | Two.txt ===============================| | file three.txt | ~ | Three.txt ==============================|||+ --------------------------------- + "-o" parameter used to vertically split the window. If Vim has been started, run the ": all" command to open a window for each file in the parameter list. ": Vertical all" opens the window vertically separated. * 08.7 * use vimdiff to display differences there is a special method to start Vim to display the differences between the two files. Let's open a "main. c" and insert some characters. When the 'backup 'option is set, save the file to generate "main. c ~ "Backup file. Enter the following command in the command line: (not in Vim) vimdiff main. c ~ Main. cVim opens two files vertically separated. You can only see the modified and the upper and lower rows. VV + ----------------------------------------- + | ++ -- 123 lines:/* a | ++ -- 123 lines:/* a |

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.