In vim 7 appeared tabs - the usual way to navigate through files. When I was working in eclipse, I often noticed that often jumping between tabs was not convenient, and familiarity with the buffers in emacs prompted me to read the documentation on windows / buffers in vim.
And so, the buffer is a kind of editing session for a specific file. For example, if you opened .vimrc and in the running Vime executed: e .bashrc, then .bashrc will open. 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_name to switch to the buffer, it is very convenient to combine with the tab, for example, we write: b domain, press the tab and we open the open iis_domain.cpp
: bd delete the current buffer, though it’s worth noting that if this buffer is the only window, then vim will close
: bd buffer_name remove buffer by name
')
What are good buffers compared to tabs? First of all, vim tabs are the same buffers, only navigation through them is different. The problem with tabs is that they are aimed at visual navigation, and when you program with vim with enthusiasm, you, like me, are probably too lazy to reach for the mouse and you know exactly what file you want to edit, write: b name - that's all! Well this is of course my IMHO :)
With the buffers figured out, let's go further. As I said in the first paragraph - sometimes you often need to jump between files, and not tabs are not buffers just do not solve the problem. It would be much more convenient to split the window in two vertically or horizontally. Right from the quarry, a combat example: you need to know 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], then the window will be split vertically, and the definition will appear in the new window.
Conveniently? Yes, for me. The window can be closed with the good old ones: q or delete the buffer: bd. To make the window unique (read expand), then we execute the Ctrl-w o combination. Brief description of working with windows:
Ctrl-w arrows :) - move to the window left / right / up / down
trl-w o - maximize the window
Ctrl-w c - close
Ctrl-w s - split the window horizontally
Ctrl-w v - the same, only vertically
Ctrl-w] - split and go to the definition of something under the cursor
Ctrl-w f - it is very convenient to do a split on the new window and in the new window open the file the path to which is under the cursor;
Commands:
: split - split, if a file is specified, open it
: vsplit - also only vertically
: sb [uffer] - split and edit the buffer. Important point: if you re-open the file (for example, through: split), then the buffer is reset, along with the history of undoes and the position of the cursor
Actually about the navigation in vim told everything that I wanted, for help, contact: help window. I just want to add about the addition of the 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 that 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 for C ++ to work, a third-party plugin is needed. Recommend.
Hope was helpful.