Questions tagged [buffers]

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

Filter by
Sorted by
Tagged with
3
votes
2answers
410 views

How to split view multiple buffers in vim

Working with big projects, I often find myself needing to view/edit several files at once. If I have multiple buffers open, is there a way to split the window to view multiple files in one command? E....
3
votes
1answer
448 views

Is it possible to simultaneously edit one file in two views?

I've been using Vim regularly for a decade, but still feel rather inexperienced because there is so much of Vim that I am not aware of and do not use. I sometimes want to see two different parts of ...
3
votes
2answers
1k views

Make Vim sessions save the content of unnamed buffers

When saving a session with :mksession and :sourceing it back, the content of [No Name] unnamed buffers is lost. I like to sometimes write temporary throwaway code or notes on a unnamed or scratch ...
3
votes
2answers
726 views

Efficient way of cleaning up the buffer list

Very often, after days and days of coding, opening vim -S session everytime, I end up with a fair long buffer list that I want to clean. Therefore I use :ls to list all buffers, and then :bdelete ...
3
votes
2answers
307 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 ...
3
votes
1answer
292 views

Run macro between buffers

I know there is a possibility to run a macro in multiple buffers using bufdo. However, what I'm not aware, if there is somehow to use a "intercommunicated macro", e.g: File 1: foo bar bun File 2: ...
3
votes
2answers
752 views

How do I properly manage a directory listing within a buffer?

I use a mix of buffers and split panes to manage my workflow. Sometimes, I (perhaps accidentally) open a directory listing instead of a file. My buffers may look like this then: At this point, I can :...
3
votes
2answers
1k views

autocmd for the event: "the first time a buffer is entered"

I know that the autocommand autocmd BufEnter will be triggered every time a buffer is entered. Is there a way to define an autocmd that will be triggered only the first time a buffer is entered?
3
votes
1answer
511 views

How to keep the screen position from "zt" after switching buffer

When I use zt to scroll the screen relative to the cursor and then switch buffers with, say, :bn followed by :bN, the screen jumps back to the position before executing zt. Using for example ctrl-d ...
3
votes
1answer
682 views

How can I remove the argslist files from the buffer list?

When using the args list, Vim adds those arglist files to the buffer list. Once I'm finished with the argslist, I then have many unwanted argslist files in the bufferlist. They don't have a contiguous ...
3
votes
1answer
635 views

How to detect the buffer number of new buffer

I would like to create a new scratch buffer in vim script. I would like to use this buffer to output the result of the execution of a scala script. I am creating the buffer with this function: ...
3
votes
2answers
172 views

How to open two new empty buffers in two separate windows?

This is a follow-up question from this Question and Answer. Is it possible, and if so how, to open two (or more) new empty buffers in Vim (without associating them to a file), such that they both take ...
3
votes
1answer
1k views

Close multiple buffers interactively

Is there a way to view a list of open buffers and close several buffers without leaving that list? The best I know of for closing multiple buffers is using :ls to get a list of buffers, memorizing ...
3
votes
1answer
1k views

How to put the difference of two files in another file

I have two files in two different buffers and I want to get the difference between these two files in another file How can I do this with Vim? Example: BUFFER1 rtl.de sat1.de pro7.de spiegel.de ...
3
votes
1answer
86 views

How to make gf behave like :drop

When I'm in a python file and I go to the imports, put the cursor on one of them, and type gf, it opens the corresponding file in a new buffer in the same window, even if the file is already open in ...
3
votes
1answer
1k views

How can I open a temporary file so that I don't get E37: No write since last change?

I have a script which performs some action and then pipes the stdout to Neovim so that I can look at it with syntax highlighting and do all the other nice things I can do with vim. However, as this ...
3
votes
1answer
184 views

How to `unlet` a variable using from a `argdo` statement in VIM

I do have a bunch of XHTML files and I need to put an @id for all the p elements inside all those files. I have tried the following argdo approach in the following way: :cd d:\testfiles\ :args *....
3
votes
1answer
1k views

How can I append text to another buffer?

While editing buffer A, I would like to append some text to buffer B without leaving buffer A. How can I achieve that? My ultimate goal is to form a collection of words that I cherry-pick from the ...
3
votes
1answer
43 views

Buffers that are neither active nor hidden

Both :ls and :buffers display a list with buffer information, giving indicators for each buffer. For example, # means the alternate buffer, and % means the current buffer. The meaning of each ...
3
votes
1answer
1k views

autocmd BufAdd/BufCreate/BufNew aren't triggered for new, unnamed buffers (`:enew`)?

I'm trying to set up an autocommand so that new, unnamed buffers are created with ft=markdown. Someone on SO suggested the following: autocmd BufEnter * if &filetype == "" | setlocal ft=markdown |...
3
votes
1answer
246 views

How to feed visual selection into ex?

Is it possible to select the text of a command from a buffer in visual mode and then feed it to ex? Like so I can modify the text of the command in the buffer and then after I press some keys have it ...
3
votes
2answers
2k views

set backupcopy=yes doesn't still writes the file twice

I'm trying to understand and eventually fix the following behavior: when I save a file using VIM, it triggers the change/write event twice. I'm using Ubuntu 16.10, and I created an empty .vimrc file ...
3
votes
1answer
723 views

Manipulate content of background (non-current) buffers from vimscript

Given some text stored in a variable, is it possible to write this text to an arbitrary buffer in the background? I ask about buffers specifically because I'm aware of writefile(), but I want to write ...
3
votes
1answer
382 views

Externally query a vim server to list the open buffers in it

I'm on linux and I'm querying the list of files open in a gvim server so I can pull it up with gvim --servername <name> --remote <file> To do so, I wrote a helper function that returns ...
3
votes
1answer
112 views

Can I open a group of buffers at once? [duplicate]

When I need to reopen vim for some reason (vim updated, reboot, etc), I need to manually open a bunch of buffers when I start up. Is there some way I can save the current set of buffers open in some ...
3
votes
1answer
101 views

add buffer to vim from the shell command line

I am currently trying to externally add a new buffer to a vim instance from the command line. That means I have already opened vim and I modify the files of interest to me. Then I want to go back to ...
3
votes
1answer
61 views

bufnr return unexpected number

from neovim help: bufnr([{expr} [, {create}]]) The result is the number of a buffer, as it is displayed by the ":ls" command. For the use of {expr}, see |bufname()| But it ...
3
votes
1answer
388 views

search highlighting only in the current buffer

I know that I can run a search in vim using /. I prefer having search highlighting turned on, but if I have a two splits with different files open, and I search for a term in one, they get highlighted ...
3
votes
1answer
330 views

What is the point of <buffer> in autocmds?

I know that the buffer is the window you're currently working in (or at least that's what I think it is), but why should I use buffer when scripting :autocmd? For example: autocmd FileType cpp,...
3
votes
0answers
62 views

Persisting unsaved changes to untitled buffers in a session [duplicate]

Sublime Text has a killer feature I'd really like to get working in Vim. It's pretty much the only reason why I can't drop it in favor of Vim yet. The feature is that Sublime remembers unsaved ...
3
votes
1answer
844 views

Toggle fzf.vim if already open

I am trying to write a vim function to toggle the fzf window if it is already open using fzf.vim. The use case is if I am in the :Buffers view and I want to change to the :Files view if I try to ...
3
votes
0answers
58 views

Why do Powerline colors dim and stay dimmed when switching buffers?

When I first open vim, the Powerline plugin works as expected: If I then switch to another buffer, the coloring of powerline's status bar is gone and it remains that way even if switching back to the ...
2
votes
2answers
1k views

Filtering text out to new tab with custom command

I would like to add to my vimrc a custom command (:customFilter {pattern}) for filtering text and placing result in a new tab. I tried using :global or :vimgrep /{pattern}/ % but the problem is that ...
2
votes
2answers
440 views

What is the difference between loaded and unloaded buffers?

I was looking at the documentation for the 'complete' option, and I found it a bit confusing: . scan the current buffer ('wrapscan' is ignored) w scan buffers from other windows b scan other ...
2
votes
2answers
216 views

How do I list only modified buffers in vim?

Sometimes when there are a lot of buffers, it becomes hard to see which buffers have been modified using :ls.
2
votes
1answer
856 views

Copy output of bash command to system clipboard?

If I run: :w !node It will take my current buffer and send it to stdin and run the code in node. If I run: :redir @+ | echo "bob" | redir END It ends up on the system clipboard. But if I want to ...
2
votes
2answers
617 views

How to create a new tab or window from a buffer?

I have several open buffers and want to open a buffer in :ls in a new tab or window. I have found a way to do accomplish this, either by first executing tabnew or C-w v and then selecting the buffer ...
2
votes
3answers
303 views

How can substitute() operate on a whole buffer?

In normal usage :%s/A/B/g is a simple way to substitute a pattern across the entire buffer. However the command mode implementation of :substitute is subject to many user configurable variables and as ...
2
votes
2answers
2k views

Can I open other files without closing the file I'm editing?

I'm new to vi/vim. I learned that I can close a file I'm editing and open the another file at once by typing :vi filename But I sometimes want to open other files without closing the file I'm ...
2
votes
1answer
2k views

"set hidden" leaves many *empty* buffers. Can I automatically get rid of them?

I recently added set hidden to my vimrc script because I didn't always want to :write a file before :editing another file. (With set nohidden, which is the default, this resulted in a E37: No write ...
2
votes
1answer
661 views

Vimscript: How to check if a buffer is modified

Given a buffer number i, I want to check if the buffer has been modified after the last save. How do I do that in vimscript? I tried to use getbufvar() like the following: if getbufvar(i, "&...
2
votes
1answer
464 views

Making terminal buffer unlisted

I'm configuring my scripts to work with terminal in VIM and have a question regarding :h special-buffers. Among mentioned kinds there were the following: unlisted The buffer is not in the buffer ...
2
votes
3answers
97 views

How can I prevent Vim from centering the line under the cursor on `:edit`

Each time I want to save my work while editing a text file, I enter :write to save the file, and :edit to reload the file, with the side effect of resetting the undo/redo buffer. However, an unwanted ...
2
votes
1answer
160 views

How can I conveniently close all read-only buffers?

For a longer running vim session, the number of buffers increases. However, often $VIMRUNTIME files, system files and netrw buffers can usually be closed with “closed” eyes. These are typically read-...
2
votes
2answers
67 views

Get first and last visible line from other buffer than current

I know that I can get the first and last visible lines in the current buffer by using line('w0') and line('w$'), but is there a way to do it for other buffers that are visible but not active as well? ...
2
votes
2answers
136 views

Move to window if specified buffer is opened

I am currently trying to write myself a function the will let me show or hide (toggle) the :terminal window. The only way to hide it, as far as I currently know, is to just navigate to that window and ...
2
votes
1answer
99 views

How can I access buffer variables from BufUnload/BufDelete?

vimdoc says: BufUnload Before unloading a buffer. ... NOTE: When this autocommand is executed, the current buffer "%" may be different from the buffer being unloaded "<afile>". Don't change ...
2
votes
2answers
467 views

Switching buffers in VI while skipping any terminal in VI 8.1

I am using multiple files within the same tab and when I switch buffers using :bn I reach the terminal, at which point I have to issue the command again to move. Here is the catch, I am using keymaps ...
2
votes
1answer
26 views

Options readonly vs nowrite

Apologies if this is duplicate. I have searched and haven't found any related questions. What is the difference between the options readonly and nowrite? The reference manual says: readonly: If on, ...
2
votes
1answer
87 views

Use cases of ":rewind"? How does it differ from ":b1"?

After reading :help :rewind :rew[ind] [++opt] [+cmd] Start editing the first file in the argument list. This fails when changes have been made and Vim does not want to |abandon| the ...

1 2
3
4 5
8