Learning VI and VIM editor (+): Vim's multi-window function (2)

Source: Internet
Author: User

Next, continue to learn the multi-window functionality of the VIM editor. This article focuses on adjusting window size, buffer and its interaction with Windows, pagination editing, closing and leaving Windows.

Resizing the window:

In Gvim, you can use the mouse to adjust the size of the window, just use the mouse to click and drag the window boundaries. If it is in vim, just turn on Mouse selection (": Set Mouse=a"), you can also adjust the window size with the mouse.

Window resizing commands:

^w=: Attempts to resize all windows to the same size (this command is affected by the current winwidth and winheight option values). If the available screen blocks are not evenly divided, vim is divided as evenly as possible.

^w-: Reduces the height of the current window by one line. There is also an ex command in Vim: resize, which explicitly specifies the size of the window to be reduced. For example, the ": resize-n" command can reduce the current window by n rows. Also , vim can reduce the window size even if it is not in a multi-window editing session (that is, only one window), and the empty screen area is left to the command-line window.

^w+: Adds a row to the height of the current window. Use the ": Resize +n" command to increase the current window by n rows. Once the maximum height of the window is reached, using this command will no longer be effective.

: Resize N: Sets the height of the current window to n rows and sets the value to absolute size.

^w< and ^w>: respectively, can reduce and increase the width of the current window.

^w| : Adjusts the current window to the maximum possible width. It is also possible to explicitly specify how the window is changed through the vertical resize n command, and n defines the new width of the window.

Window Sizing Options:

Some vim options can affect the behavior of the resizing commands explained above.

when the window becomes active (active), winheight and Winwidth define the minimum height and width of the window, respectively. since the default behavior of vim at split time is evenly distributed, it is assumed that after averaging the split, the width of the two Windows is 55 columns. When Winwidth is adjusted to 80, each time VIM moves the cursor to a window, the width of the window is automatically adjusted to 80 and the other window is 30. This behavior is very convenient to automatically increase the size of the window when switching windows and switching files.

Equalalways: Let vim resize the window to the same size after splitting or closing the window.

Eadirection: Define the direction of the equalalways, can use the value of Hor, Ver, both, respectively, in the horizontal, vertical, two directions are adjusted window dimensions equal.

Cmdheight: Sets the height of the command line. As already mentioned, reducing the height of a window increases the height of the command line in cases where only one window is open. Set this option to maintain the height of the command line.

Winminwidth,winminheight: Used to determine the minimum width and height when the window is resized. Vim treats these two option values as hard rules, so the window size never allows to be smaller than these two values.

Buffer and its interaction with the window:

Vim uses buffers as a container for working objects. There are many control buffers in vim and commands to move through the buffer. But first you need to learn the basics of buffers.

Use the Vim editor to divide three windows and open three separate files in three windows: Buffer_one.file , Buffer_two.file,buffer_three.file. Use the ": ls" or ": Files" or "buffers" commands to list the buffers as shown in:

each file corresponds to a buffer. Each buffer has a unique, unchanged number. If you add an exclamation mark after the above command, you can also list additional information for each buffer. in the buffer listed, the first is the buffer number, then the status flag. The code and description for the status flag are as follows:

U: Non-list buffer, this buffer is not listed unless used!.

% or #:% represents the buffer used by the current window, and # indicates the buffer to jump to using the ": E #" command (that is, the buffer area corresponding to the complement file).

A or H: a represents the buffer in the activity, that is, the buffer is already loaded and visible. H means to hide the buffer, although the hidden buffer exists but cannot be viewed in any window.

-or =:-indicates that the buffer closes the modifiable option. = indicates that the file is not able to modify the state to an adjustable read-only file.

+ or x:+ indicates that the buffer is adjustable and x indicates that the buffer has a read-in error.

Special buffers for VIM:

Some of the buffers used by VIM itself are called special buffers. Generally, these buffers cannot be edited.

Quickfix: contains a list of errors created because of our command or Location list.

Help: Contains vim helper files. These help files are placed in a special buffer when you use the ": Helps" command.

Directory: Contains the contents of a directory, that is, a list of files in a directory. It is a quick tool in Vim that allows us to move through the buffer and use the cursor plus the ENTER key to select the file you want to edit.

Scratch: These buffers contain general-purpose text.

Hide buffers:

The hidden buffer is a vim buffer that is not displayed in any of the current Windows. Hiding buffers makes it easier to edit multiple files. You need to set the hidden option to use a hidden buffer.

Buffer command:

VIM automatically manages buffers when multiple files or Windows are opened or closed. The buffer command can perform almost all operations on the buffer. The next step is to introduce two buffer commands, which can do a lot of work on many files at once.

: windo cmd: This command is the short name of "window do", this pseudo-buffer command (which is actually a window command) executes the specified command cmd in each window. It only moves in the current paging, and if an error occurs while executing the command, it stops at the window that produces the error, and the resulting error window becomes the new current window. CMD can concatenate multiple commands using the pipe symbol (|), and each of the concatenation commands executes sequentially in each window.

: bufdo[!] cmd: Similar to the Windo command, but the action object is all buffers in the edit session, not just the visible buffers in the current paging.

The following is a list of common buffer commands:

: ls[!],:files[!],:buffers[!] : Lists buffers with file names, if added!, includes non-list buffers;

: Ball,:sball: Edit all parameters or buffers, one window for each buffer;

: unhide,:sunhide: Edit all loading buffers, one window for each buffer;

: Badd File: Add file to the list;

: bunload[!] : Unloads the buffer from memory. If the buffer is not saved after modification, VIM does not let the buffer unload. Plus exclamation mark, will ignore Vim's warning, force unload buffer;

: bdelete[!] : Unloads the buffer and removes it from the buffer list, which acts as an exclamation mark;

: Buffer[n],:sbuffer[n]: Move to buffer N (sbuffer opens a new window);

: Bnext[n],:sbnext[n]: Moves to the next nth buffer (Sbnext opens a new window);

: Bnext[n], : Sbnext[n],: bprevious[n],: sbprevious[n] : Move to the previous nth buffer (Sbnext,sbprevious opens a new window);

: Bfirst,:sbfirst: Moves to the first buffer (Sbfirst opens a new window);

: Blast, : Sblast: Move to the last buffer (Sblast opens a new window);

: Bmod [N],:sbmod [n]: Move to Nth modified buffer (Sbmod opens a new window);

Follow the tabs in the window:

Vim extends the label function of vi into the window, providing a tag traversal mechanism for multiple windows. enables tracking of a tag to open the associated file in a new window.

Use ": stags[!] "To split the window to show the location of the found label. If the label is not found, the command fails and a new window is not created.

^W^] or ^w] command: The effect is equivalent to ": Stag".

^WG]: Similar to ^w], but in a new window, VIM executes ": tselect tag" command, where tag is the identifier under the cursor;

^wg^]: Similar to ^WG], but execute ": tjump" command in a new window;

^WF or ^w^f: Ability to split the window and edit the name of the file where the cursor is located;

^WGF: Opens the name of the file where the cursor is located in the new paging page. If the file does not exist, no new paging is created;

Pagination editing:

Vim allows the creation of new paging, each of which has its own behavior. In each pagination, you can split the screen, edit multiple files, and so on. You can use paging in vim and Gvim, and the commands associated with pagination editing are:

: tabnew filename: Opens a new page and edits the new file. If no file is specified, Vim opens only a new page and a buffer is attached;

: Tabclose: close the current paging;

: tabonly: close all pages except the current paging;

With Ctrl+pgup (one page to the right) and CTRL+PGDN (one page to the left), you can loop around the page (the actual test, which does not work in vim, is feasible in gvim).

With regard to pagination editing, there are too few commands on the book, here are a few additions, and a more detailed way to use ": Help Tab-page-commands".

: tabnext,gt: Moves to the next page, and moves for the loop (after moving to the last one, moving on will return to the first one);

: Tabnext [Count], [COUNT]GT: Moves to count pagination;

: Tabprevious, : Tabnext, GT: Moves to the previous page and moves for the loop;

: tabprevious [Count], : Tabnext [Count], [COUNT]GT: Moves the count of pages back;

: Tabfirst: Move to the first page;

: Tablast: Move to the last page;

Close and leave the window:

vim is like a command to close the window, these life There are a lot of details to note, in more detail you can refer to Vim's help documentation.

: Quit,^wq, ^W^ Q: Leave the current window, if it is the last window on the screen, leave Vim. If the hidden option is set and the window is the last window to open the file, the buffer is hidden. If the hidden option is not set, and the window is the last window to open the file, if the buffer has unsaved modifications, the command fails (you want to force the window to leave at this point, you can add it after the QUIT command!). , thereby discarding the modification of the buffer).

^WC: Closes the current window, if the current window is a unique window on the screen, the command failed to execute.

: Only,^wo, ^W^ O: Closes all windows except the current window.


This chapter VIM commands summary:

^w=, ^w-, ^w+,: Resize N,: Resize +n,: Resize-n, ^w<, ^w>, ^w|,: Vertical resize, winheight option, WinwidthOptions, EqualalwaysOptions, eadirectionOptions, CmdheightOptions, WINMINWIDHToptions,WinminheightOptions,: LS,: Files,: buffers,: Windo cmd,: bufdo[!] cmd,: Ball,: Sball,: Unhide,: sunhide,: Badd file,: bunload[!],: bdelete[!] ,: Buffer[n],: Sbuffer[n],: Bnext[n],: Sbnext[n],: Bnext[n],: Sbnext[n],: Bprevious[n],: Sbprevious[n],: Bfirst,: Sbfirst,: Blast,: Sblast,: Bmod[n],: Sbmod[n],: stags[!], ^w], ^W^], ^WG], ^wg^], ^WF, ^W^ F, ^WGF,: tabnew, filename,: tab Close,: Tabonly, ": Help Tab-page-commands",: Tabnext, GT,: Tabnext[count], [COUNT]GT,: tabprevious,: Tabnext, GT,: Tabpre Vious[count],: Tabnext[count], [COUNT]GT,: Tabfirst,: Tablast,: Quit, ^WQ, ^W^ Q, ^wc,:only, ^wo, ^W^ O.



Learning VI and VIM editor (+): Vim's multi-window function (2)

Related Article

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.