Vim编辑器-Windows

5 Windows

  • How to open a new window
  • Window selection
  • Editing two files at once
  • Controlling the size of a window
  • Basic buffer usage

  • Opening a New Window
    :split This command splits the screen into two windows(and leaves the cursor in the top one).
    If you are at the bottom window, the CTRL-Ww command moves the cursor to the top window. If you are at the top window, the editor jumps to the bottom one on the screen.
    To change windows, use CTRL-Wj to go down a window and CTRL-Wk to go up a window.

To close a window, use ZZ or :q or CTRL-Wc.

  • Opening Another Window with Another File
    :split file

The :split command can also execute an initial command using the +command convention.
:split +/printf three.c

  • Controlling Window Size
    The :split command can take a number argument. If specified, this will be the num- ber of lines in the new window. For example, the following opens a new window three lines high and starts editing the file alpha.c:
    :3 split alpha.c

  • The :new Command
    The :new command works just like the :split command except that the :split command splits the current window and displays the current file in both windows.
    The following command splits the current window and starts a new file in the other window:
    :new

  • Split and View
    The :sview command acts like a combination of :split and :view.This command
    proves useful if you want to look at, but not edit, a file in another window.

  • Changing Window Size
    Changing window size when you are using gvim is easy.To change the size of a win- dow, use the mouse to drag the separator up or down.
    If you are using the terminal version of Vim, you need to type in some commands.
    countCTRL-W+ increases the window size by count (default = 1).
    CTRL-W- decreases the window’s size by count (default = 1).
    CTRL-W= makes all the windows the same size (or as close as possible).
    countCTRL-W_ makes the current window count lines high. If no count is specified, the window is increased to its maximum size.

  • Buffers
    The Vim editor uses the term buffer to describe a file being edited. Actually, a buffer is a copy of the file that you edit.When you finish changing the buffer and exit, the contents of the buffer are written to the file. Buffers not only contain file contents, but also all the marks, settings, and other stuff that go with it.
    Normally it is pretty easy to tell what buffers you have: If it has a window on the screen, it is a buffer; if it is not on the screen, it is not a buffer.
    :hide command, This causes the current buffer to become “hidden.”This causes it to disappear from the screen. But
    Vim still knows that you are editing this buffer, so it keeps all the settings, marks, and
    other stuff around.
    Actually, a buffer can have three states:
    Active Appears onscreen.
    Hidden A file is being edited, but does not appear onscreen.
    Inactive The file is not being edited, but keep the information about it anyway.
    To find a list of buffers, use the following command: :buffers

    * *
    - Inactive buffer.
    h Buffer is hidden.
    % Current buffer.
    # Alternate buffer.
    + File has been modified.
  • Selecting a Buffer
    :buffer number number is the buffer number. If you do not know the number of the buffer, but you do know the filename, you can use this command:
    :buffer file
    The following command splits the window and starts editing the buffer:
    :sbuffer number
    Other buffer-related commands include the following:
    :bnext Go to the next buffer.
    :count bnext Go to the next buffer count times.
    :count sbnext Shorthand for :split followed by :count bnext.
    :count bprevious Go to previous buffer. If a count is specified, go to the count previous buffer.
    :count sbprevious Shorthand for :split and :count bprevious.
    :count bNext Alias for :bprevious.
    :count sbNext Alias for :sbprevious.
    :blast Go to the last buffer in the list.
    :sblast Shorthand for :split and :blast.
    :brewind Go to the first buffer in the list.
    :sbrewind Shorthand for :split and :rewind.
    :bmodified count Go to count modified buffer on the list.
    :sbmodified count Shorthand for :split and :bmodified.

  • Buffer Options
    Usually when the last window of a file is closed, the buffer associated with the file becomes inactive. If the option hidden is set, files that leave the screen do not become inactive; instead they automatically become hidden.Therefore if you want to keep the contents of all your old buffers around while editing, use the following command
    :set hidden

The :hide command always hides the current file no matter what the “hidden” option is set to.

Normally, the split/buffer related commands split the current window. If the “switch-
buf ” is set to “useopen” and there is a window displaying the buffer you want to
display already on the screen, the Vim will just make that window the current one instead of performing the split.

上一篇:Python的split()函数在切割时遇到的问题


下一篇:记一次GDB调试