Questions tagged [buffers]

The representation of a file loaded into memory. Edits are performed on buffers.

Filter by
Sorted by
Tagged with
80
votes
2answers
52k 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 ...
80
votes
6answers
41k 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 ...
71
votes
4answers
20k 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 ...
65
votes
8answers
40k 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 ...
40
votes
5answers
13k 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.
40
votes
2answers
16k 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?
39
votes
2answers
14k 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 ...
38
votes
5answers
6k 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. ...
29
votes
1answer
8k 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 ...
24
votes
2answers
6k 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?
21
votes
2answers
6k 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 -...
18
votes
4answers
5k 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 ...
17
votes
6answers
10k 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 ...
17
votes
2answers
24k 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):...
16
votes
4answers
11k 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.
15
votes
6answers
10k 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?
15
votes
3answers
3k 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 ...
15
votes
6answers
2k 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 ...
14
votes
3answers
2k 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
1answer
1k 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
13
votes
1answer
1k 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 ...
13
votes
1answer
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? ...
12
votes
1answer
955 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 ...
11
votes
2answers
3k 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 ...
11
votes
1answer
2k 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, ...
10
votes
1answer
7k 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?
10
votes
1answer
809 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
1answer
589 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
1answer
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
2answers
535 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: ...
9
votes
3answers
1k 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
2answers
947 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
3answers
3k 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 ...
9
votes
1answer
352 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
3answers
3k 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 ...
9
votes
1answer
391 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
2answers
1k 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 ...
9
votes
3answers
757 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/...
8
votes
2answers
4k 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 ...
8
votes
3answers
5k 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 ...
8
votes
0answers
496 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 ...
7
votes
2answers
141 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 ...
7
votes
1answer
500 views

Can you reference buffers in command mode?

I know about % and #, which reference the filenames of the current and previous buffers in command-line mode. Is there any way to similarly reference other buffers? For example, let's say that :ls ...
7
votes
1answer
616 views

What is an abandoned buffer in vim?

I've been using vim for more than 5 years now, and I was surprised when I didn't know what an abandoned buffer was. The closest answer I found was in this SO answer. So is an abandoned buffer one ...
7
votes
1answer
274 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 ...
7
votes
1answer
2k 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 ...
6
votes
1answer
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 ...
6
votes
1answer
4k views

how to close tab and remove this file from buffers

I often use :tab sball to open all buffers as tabs, but sometimes after doing so I would like to close the tab and remove file from buffers at the same time. How can I achieve that? I know already ...
6
votes
2answers
488 views

Keep windows reference in memory

I am writing a plugin which needs to have two windows displayed at the same time: _______ | | | | A | B | |___|___| I need to keep in memory a reference to those windows as I execute my plugin. ...
6
votes
1answer
776 views

diffoff on all buffers

Occasionally I have a stray forgotten buffer in which I ran :diffthis. Later when I run :diffthis on some unrelated buffer that second buffer is immediately and unintentionally highlighted with the ...

1
2 3 4 5
8