Questions tagged [buffers]
The representation of a file loaded into memory. Edits are performed on buffers.
428
questions
98
votes
2
answers
68k
views
Close and unload a buffer without exiting Vim
Often, I'll load some information into a temporary buffer, and then close it with :clo!. But this hides the buffer rather than unloading it entirely, even though I have nohidden set. I find this ...
89
votes
6
answers
49k
views
Is there an easy way to close a scratch buffer/preview window?
One of the plugins I have installed (probably Supertab) provides a nice view of documentation for the currently highlighted item in the completion menu:
The (apparently) scratch buffer remains open ...
84
votes
8
answers
72k
views
Fastest way to switch to a buffer in Vim?
One way to select a buffer in Vim could be to browse the buffers list, using standard commands as :ls, or with some external plugin / vimscript code to browse a list in a window.
Let's say I want to ...
77
votes
4
answers
27k
views
How to save window, split, and buffer layout?
I have several tasks I am working on in one repository. I would like to create "workspaces" for working on them.
One "workspace" or "buffer layout" would have all files I need to work on open in the ...
58
votes
3
answers
20k
views
How can I reload all buffers at once?
When working on a feature branch in git, I frequently need to stash my changes to commit a bug fix to the main branch. When I'm done working on the changes, I git stash pop, which updates the ...
54
votes
5
answers
25k
views
Dump the output of internal vim command into buffer
How do I dump an internal vim command (not shell command) into a new buffer?
For example, I want to dump a listing of all plugins into :enew from :scriptnames so that I can search it.
46
votes
2
answers
23k
views
Can I open a new vim split from an existing buffer?
I know it's possible to open a new file in a split, with :split or :vsplit, but is it possible to open a new split with an existing buffer, potentially leveraging autocomplete?
40
votes
6
answers
8k
views
Renumbering buffer list
After I've been working on a project for a while, I start to see large gaps between consecutive buffer numbers. This is because the buffers in between them were wiped out for various reasons. ...
35
votes
1
answer
11k
views
How do you open a new buffer in the current window?
I've got a few tabs open with different window setups.
I'd like to open a new blank buffer in the current window, without having any more splits/windows or tabs
Is there any way to do this?
I know ...
32
votes
8
answers
25k
views
How to go to previous open buffer from Vim command line?
I am trying to write a Vim function which should make the window go to the previous open buffer.
How can I do it from the command line? My first idea was to find out some Ctrl-O command line ...
30
votes
3
answers
10k
views
What is the order of WinEnter, BufEnter, BufRead, Syntax, FileType events?
I've gone through the autocmd.txt help, but the information about this is scattered and not always present (eg. with BufRead).
Could someone who understands this well list the order of these events -...
29
votes
2
answers
11k
views
How do I open a new buffer without opening it in a split?
I know I can use :new to open a new buffer in a split window (defined by set splitbelow and set splitright).
But how can I just open a new, empty buffer without opening it in a split?
23
votes
2
answers
46k
views
A built-in way to make Vim open a new buffer with file?
Is there a built-in way to make Vim open a new buffer with file?
I want open a file. :enew doesn't take any arguments and opens a blank buffer.
:edit closes my existing buffer.
Related (about :enew):...
22
votes
4
answers
8k
views
Is there a way to reliably go back and forth in file history
I would like to go to the file I just edited last and next kind of like MRU plugins do.
:bnext and :bprev works sometimes, but more often than not I just end up in some obscure file I don't remember ...
21
votes
5
answers
20k
views
What is a scratch window?
Sometimes I see a window open with name scratch.
I know it is some kind of temporary buffer/window.
How can I create one?
:h scratch returns nothing.
21
votes
3
answers
7k
views
How to return to netrw from a file
Suppose that I'm editing a file, then I press :w to store it. And then I use :e. to navigate its containing folder in the netrw. Suppose its containing folder is ./A/B/. In netrw, I open a file with ...
18
votes
4
answers
5k
views
How do I have buffers listed in a quickfix window in Vim?
Using vim editor, a common task is to browse buffers.
I now use standard commands like :ls or a :bnext. In fact I set in my .vimrc:
"move amongs buffers with CTRL
map <C-J> :bnext<CR>
map ...
17
votes
6
answers
13k
views
Using :Explore without closing current buffer
If I open the file explorer with :Explore and choose a file, it replaces the buffer I had open before and I have to open it again. How do I avoid this?
17
votes
1
answer
2k
views
What bad things can happen if I use :bwipeout?
I have just discovered the :bwipeout command, for which the :help states:
Like :bdelete, but really delete the buffer. Everything
related to the buffer is lost. All marks in this buffer
...
17
votes
7
answers
4k
views
How to bind a set of buffers to a tab?
When I need to work on different projects at the same time I have the folowing workflow:
I create one tab for each project.
In each tab I open the files that I want to edit, which makes several ...
17
votes
1
answer
2k
views
What is the difference between a tab, viewport, window, split and buffer?
What is the difference between the following in vim:
buffer
window
viewport
split
tab
16
votes
3
answers
3k
views
What is a more efficient way to use buffers?
Lately I've been drastically reducing the number of plugins I'm using so I'm
looking for answers using only built-in Vim features.
I've been noticing a flaw in my workflow when I'm editing a lot of ...
14
votes
2
answers
5k
views
How to iterate over buffers in Vimscript
How can I iterate over the current open buffers and say, load the buffer numbers into an array in vimscript?
I know there exists arrays or similar data structures in vimscript.
I know that every ...
13
votes
1
answer
3k
views
How should the option 'switchbuf' work?
I recently discovered the option switchbuf and tried to use it but I can't say if I don't understand how it should work or if it actually doesn't work on my Vim.
About the different possible values, ...
13
votes
1
answer
2k
views
Execute content of buffer as vimscript
I have a nofile buffer that contains vimscript, and I want to execute it. However, :so % will not work because it requires a saved file, not a buffer. Is there a vim command to do this by default? ...
13
votes
2
answers
1k
views
different search patterns per window / buffer
Is it somehow possible to have different search patterns per window or buffer, ie. I want to search for term A in window/buffer A and term B in window/buffer B so that using hlsearch, highlights ...
12
votes
3
answers
8k
views
Reopen the most recently closed buffer
When writing to a file, I often accidentally type :wq instead of :w since the two keys are right next to each other. But since I almost always have more than one buffer open, Vim stays up and whatever ...
12
votes
3
answers
2k
views
Syntax highlighting is gone after :bufdo :e
I'm using console vim within a tmux window, therefore occasionally vim doesn't recognize that files have been modified (gvim does it on a focus change AFAIK) and in order to avoid getting inconsistent ...
11
votes
1
answer
8k
views
How to open same file in multiple buffers
Is it possible, in one instance of VIM, to open one file in few buffers and edit them independently?
11
votes
3
answers
4k
views
How do I add skeleton text to new vim files?
I use Vim for writing C++, and I have quite a few #include<> statements, comments, etc. that I must include in each new file I create. I've added
autocmd BufNewFile *.cpp r C:\(full file path ...
11
votes
3
answers
1k
views
Preserve creation time stamp after modification
I want to modify files with vim without changing the creation time stamps.
The docs doesn't seem to mention anything about such possibility.
I'd like to achieve this without turning off the swap/...
10
votes
2
answers
6k
views
Vim hide buffer like in emacs?
I'm trying to figure out how the vim concept of buffers, windows, and tabs maps onto emacs.
It seems to me that <c-w>s and <c-w>v are roughly equivalent to Emacs C-x 2 and C-x 3. They're ...
10
votes
2
answers
2k
views
Can I use syntax highlighting on an unwritten buffer?
I pasted some code into a new, unwritten buffer in Vim. I'd like to do some quick edits on the code without saving it to a file, but it hurts my eyes to look at code without syntax highlighting. Can ...
10
votes
1
answer
1k
views
Why does :bd # delete the current buffer when no alternate buffer exists?
Here is how I reproduce the behavior I am observing.
First, I enter this command:
echo aaaaa > a
vim a
In Vim, I enter these commands:
:ls
:e #
:echo bufname('#')
Here is the output of the ...
10
votes
3
answers
3k
views
Is there a way to list recent buffer history?
I just started using buffers in Vim and I couldn't figure out how to list recent closed buffers. Is there a simple way (like :ls) to list those? Are they actually stored by Vim?
Maybe I'm misusing ...
10
votes
1
answer
706
views
Multiple buffers, same file, different settings
Is it possible to edit a file under different settings at the same time? More precisely, I'd like to have multiple buffers in the same instance of Vim which have the same content (changing one buffer ...
10
votes
1
answer
1k
views
Buffers vs tabs vs arglist vs windows
So many choices! So confusing!
When should one be used in preference to another?
How do these relate to each other?
What are the differences between them, anyway?
How do they affect commands you ...
10
votes
2
answers
989
views
Most efficient way to replace the entire buffer?
Currently, I have two similar methods to replace the entire buffer with some other text (say in clipboard).
Method #1:
delete all lines: :%d.
paste text: "+P ( or similar: :put+).
Method #2:
...
10
votes
0
answers
657
views
Persistently fix the height of a split in vim
So I searched the web far and wide and I can not for the life of me figure out how to do this.
I have the following key binding:
nnoremap <leader>o :below 10sp term://.//$SHELL <cr> :set ...
9
votes
1
answer
2k
views
BufWinLeave * mkview with unnamed file: Error 32
Following this good piece of advice, I have added these lines to my .vimrc.
augroup AutoSaveFolds
autocmd!
autocmd BufWinLeave * mkview
autocmd BufWinEnter * silent loadview
augroup END
It ...
9
votes
3
answers
2k
views
Automatically close oldest buffers?
I needed to edit a lot of files recently for a small change in each file. To get to each file, I browsed through NERDtree and opened one file after another. As I opened more and more files, I ...
9
votes
2
answers
1k
views
Force buffers to always open with vertical split
When I open a new buffer I usually just do :vsp something which allows me to open a new buffer with a vertical split. However, when I don't control how the buffer should be opened (e.g. when typing :...
9
votes
1
answer
399
views
What does the '+' symbol mean when opening a buffer?
I want to open a terminal buffer in a vertical split.
If i try :vertical split terminal I get a buffer named 'terminal', not a terminal buffer.
I recently learned I could do :vertical split +...
9
votes
1
answer
473
views
Is there a way to write out the results of ":ls" to a file?
I have a bunch of splits up right now, and it took me a while to find these files (basically I'm chasing down a bug through 50 interconnected files).
Is there a command like :ls > /tmp/filelist ...
9
votes
2
answers
3k
views
How to share the same buffer between multiple vim instances
I work with two displays.
I usually open one instance of Vim in display #1 (let's call it Vim #1), which over time ends up having an open buffer for nearly every file in a project.
Now I want to ...
8
votes
2
answers
158
views
Can I cycle through buffers while skipping ones I've opened?
Let's say I have a vertical split, and four buffers open.
I'd like to be able to have one buffer open on the left, and cycle through just the other three on the right. Something like :bnext but ...
8
votes
1
answer
294
views
How can I view the name of the swapfile being used for the current buffer?
Let's say I recovered a bunch of swapfiles in quick succession:
gvim -r .swv
gvim -r .swu
gvim -r .swt
And then cycled through them all a few times before finding that one of them was nonsense. I ...
8
votes
2
answers
1k
views
Limit buffer list to current tab
Is there a way to list the buffers specific to the tab that is open currently in vim or macvim?
8
votes
1
answer
381
views
Improving alternate-file behavior to avoid reopening deleted buffers?
Lured in by the promise of evil-mode, I've been moonlighting in Emacs. It's a wild world with a mix of hairy lose-ends and astoundingly smart features. One feature I really like is a command called ...
8
votes
1
answer
1k
views
Why can't I execute write command on all buffers with :bufdo?
I have multiple buffers open, some currently visible, some not. I know I can write all of them with :wa. However, I am curious, why :bufdo w does not work. When I try it in a buffer with unsaved ...