Windows and buffers

    Tabs appeared in vim 7 - a common way to navigate files. When I worked in eclipse, I noticed more than once that it is often not convenient to jump between tabs, and familiarity with the buffers in emacs prompted me to read the documentation on windows / buffers in vim.



    And so, a buffer is a certain editing session for a specific file. For example, if you opened .vimrc and in the running wime did: e .bashrc, then .bashrc opens. However, the buffer with .vimrc will remain open and editable. Here are the basic commands for working with buffers::
    bn next buffer
    : bp previous
    : ls view open buffers
    : b buffer_nameswitch to the buffer, it is very convenient to combine with the tab, for example, write: b domain, press the tab and open iis_domain.cpp is substituted for us
    : bd delete the current buffer, it’s worth noting that if this buffer is the only window then vim will close
    : bd buffer_name delete the buffer by name

    What are the good buffers compared to tabs? Firstly, in vim, tabs are the same buffers, only navigation on them is different. The problem with the tabs is that they are aimed at visual navigation, and when you are enthusiastically programming in vim, you, like me, are too lazy to reach for the mouse and you know exactly which file you want to edit, write: b the name is all! Well this is of course my IMHO :)

    We sorted out the buffers and drove on. As I said in the first paragraph, sometimes you need to often jump between files, and not tabs or buffers just do not solve the problem. It would be much more convenient to split the window into two vertically or horizontally. Right from the place to the quarry, a combat example: you need to find out the definition of a function, if the tags are generated, then just press Ctrl-] to go to it. But a new buffer will open, which is not very convenient. If you press Ctrl-w], the window will be split vertically, and a new window will be defined.
    Conveniently? Yes, for me. You can close the window with the good old: q or delete the buffer: bd. To make the window the only one (read maximize), we execute the combination Ctrl-w o. A brief description of working with windows:
    Ctrl-w arrows :) - move to the window left / right / up / down

    Ctrl -w o - expand the window Ctrl-w c - close
    Ctrl-w s - split the window horizontally
    Ctrl-w v - also, only vertically
    Ctrl-w] - split and go to the definition of something under the cursor
    Ctrl -w f - split and in a new window open the file the path to which is under the cursor, it is very convenient to do it on inclusions
    Commands
    :: split - split, if the file is specified then open it
    : vsplit - also only vertically
    : sb [uffer] - split and edit the buffer. An important point: if you reopen the file (for example, via: split), the buffer is reset, along with the history of cancellation and the cursor position

    Actually about navigation in vim he told everything that he wanted, for help, please contact: help window. I just want to add about the addition of text.

    Addition in vim is done by Ctrl-n, Ctrl-p. But we can indicate what type of add-ons we want to see:
    Ctrl-x Ctrl-f - files, they are searched in the current directory
    Ctrl-x Ctrl-d - defines
    Ctrl-x Ctrl-i - words from the current and open files
    Ctrl-x Ctrl- k - from the dictionary
    Ctrl-x Ctrl-] - all tags
    Ctrl-x Ctrl-o - omni completion, a kind of intellisense that works great with C, Python, etc. but C ++ needs a third-party plugin to work. Recommend.

    I hope it was useful.

    Also popular now: