67
votes
Accepted
Dump the output of internal vim command into buffer
You can use :redir to redirect the output to a variable, register, or file. Example of redirecting to the unnamed register:
:redir @">|silent scriptnames|redir END|enew|put
Alternatively Tim Pope'...
48
votes
Accepted
How to go to previous open buffer from Vim command line?
The jumplist is not the best way to do buffer navigation. Vim has a great number of buffer navigation tools which are probably better used for this task.
<c-^>/<c-6> - jump to the ...
47
votes
Close and unload a buffer without exiting Vim
You can completely wipe out a buffer using the :bwipeout (or :bw) command. This completely removes the buffer from memory, including any marks, option settings, etc. that you have added to it. ...
42
votes
Accepted
A built-in way to make Vim open a new buffer with file?
I think you might be misunderstanding what you're seeing happen. :edit does not close your current buffer. It just replaces it in the current window. If you type :buffers your previous buffer ...
36
votes
Accepted
How do I open a new buffer without opening it in a split?
You can use :enew. See :h :enew:
Edit a new, unnamed buffer. This fails when changes
have been made to the current buffer, unless 'hidden'
is set or 'autowriteall' is ...
35
votes
Is there an easy way to close a scratch buffer/preview window?
For my specific case, the preview window was opened by plugins. So, I used plugin configuration to automatically close these windows.
Supertab
As suggested by Alex Kroll:
let g:...
25
votes
Accepted
BufWinLeave * mkview with unnamed file: Error 32
Switching to ?* as the regex will no longer match empty file names. I actually recommend you switch to the following, which is a corresponding block of .vimrc that has been tweaked to suppress many of ...
24
votes
Fastest way to switch to a buffer in Vim?
:CtrlPBuffer from plugin CtrlP (5k ★)
Main feature of this plugin is to provide a fuzzy matching to conveniently open a different buffer with visual feedback.
Open the fuzzy buffer listing with :...
21
votes
Accepted
How to iterate over buffers in Vimscript
You can iterate over buffers if you use :bnext and all. I highly advice against this method. It'll trigger autocommands, and you'll have to remember where you were. In other words, it can be damn slow,...
19
votes
Accepted
How to open same file in multiple buffers
I'm not sure about what you mean by buffer.
In Vim jargon, a buffer maps a file, or a file that could be saved later. If you really want independent buffers initialized with a same file, you'll need ...
18
votes
Renumbering buffer list
"the buffer numbers get crazy" Tell me about it! By the end of the day I'm easy over 100 buffers. But luckily, as you can see in this animation, you have tab completion for buffer names.
So, even ...
18
votes
What is the difference between a tab, viewport, window, split and buffer?
A buffer is the in-memory text of a file. It may differ from the saved version of the file.
A window is a view of a buffer. You can have two (or more) windows editing different parts of the same ...
18
votes
Accepted
What is a scratch window?
It is probably a scratch buffer, which can be named. From the help:
scratch
Contains text that can be discarded at any time. It is kept when closing the window, it must be deleted explicitly. ...
17
votes
How to go to previous open buffer from Vim command line?
You can also use ctrl + o to go to the previous jump list, which might be buffer, going backwards. You can keep pressing the same command to go to the previous, previous buffer/jump list.
You can also ...
16
votes
Using :Explore without closing current buffer
In :help netrw-explore they mention several other commands to explore your files.
Among them are :Texplore which opens the file explorer window in a new tab instead of using your current window.
...
16
votes
Accepted
Vim hide buffer like in emacs?
By default, Vim will refuse to replace the current buffer with another one if it contains unsaved changes. You'll need to add the option below to your vimrc if you don't want that behavior (and you ...
15
votes
Accepted
How should the option 'switchbuf' work?
'switchbuf' is only honored by quickfix commands (like :cc) and buffer-splitting commands (like :sb).
It doesn't affect :buffer and other "regular" buffer-related commands.
14
votes
Fastest way to switch to a buffer in Vim?
[b and ]b from plugin vim-unimpaired (> 3k ★)
If you happen to have installed vim-unimpaired, you can use
[b (:bp[revious]) and
]b (:bn[ext])
for cycling through open buffers. No need to define ...
13
votes
Accepted
What is a more efficient way to use buffers?
I've been noticing a flaw in my workflow when I'm editing a lot of buffers: I am on a buffer and I want to switch to another one of which I don't remember the name and which isn't the alternative ...
13
votes
Accepted
different search patterns per window / buffer
You can use :autocmds to switch the current search pattern (register /) as you move along windows and buffers, but Vim will never highlight different patterns at the same time, as this still is a ...
13
votes
Accepted
Can I use syntax highlighting on an unwritten buffer?
In addition to setting the syntax, setting the filetype brings indent options (if you have those on), mappings, and other filetype specific vimscript to bear on your code. So I recommend
:set ...
12
votes
Accepted
how to close tab and remove this file from buffers
:bd will do that.
From the documentation:
:[N]bd[elete][!] *:bd* *:bdel* *:bdelete* *E516*
:bd[elete][!] [N]
Unload buffer [N] (default: current buffer) and delete it from
...
12
votes
Accepted
Is it possible to obtain the displayable area, width and height of current buffer in Vim?
These are the different ways (that I know of) to get dimensional information from Vim.
Vim
&columns and &lines will give you the total width and height of the screen Vim is displayed in. ...
12
votes
Accepted
Reopen the most recently closed buffer
I played around with this a bit and the following seems to work for the cases I tested, including closing a window split and a tab with one window using :q.
augroup bufclosetrack
au!
autocmd ...
11
votes
Accepted
Changing between the active buffer and the alternate buffer
CTRL-6 can be used to edit the alternate file - tested on OS X by changing the input source from U.S. to Spanish ISO.
If you find yourself wanting to edit the alternate file often, you could consider ...
10
votes
What is the order of WinEnter, BufEnter, BufRead, Syntax, FileType events?
This is the first result show up on google search about 'Vim event order'. So, i think it's worth providing the actual answer.
Using the command from @nobe4 answer, this is the result:
Opening a new ...
10
votes
Accepted
What does the '+' symbol mean when opening a buffer?
Should have looked a bit harder before asking, I found my answer:
:help +cmd
*+cmd* *[+cmd]*
The [+cmd] argument can be used to position the cursor in the newly opened
...
10
votes
Accepted
Using :Explore without closing current buffer
I usually use a following flow when I want to open the file (while keeping the current file):
Make a new vertical / horizontal split
Open netrw from in the new split
Select another file
As mentioned ...
10
votes
How to clear all contents of a file
Fastest is
:%delete
Which can be abbreviated to
:%d
The % is a range standing for “whole file.”
If you want to use a particular register (e.g., black hole):
:%d_
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
buffers × 428vim-windows × 44
vimscript × 40
autocmd × 33
neovim × 31
vimrc × 21
split × 21
key-bindings × 17
hidden-buffers × 17
tabbed-user-interface × 16
netrw × 15
save × 14
command-line × 13
multiple-files × 13
plugin-nerdtree × 12
sessions × 12
terminal-buffer × 11
search × 9
terminal × 9
functions × 9
statusline × 9
argument-list × 9
quickfix × 8
quit × 8
syntax-highlighting × 6