Questions tagged [buffers]

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

Filter by
Sorted by
Tagged with
2
votes
1answer
146 views

Session - start with buffer 1

Note: Possible fixed bug. See comments. A somewhat minor nuisance, but as the pedantic for these things :P When saving and opening a Session file the Session.vim file does: badd +1 file1 badd +1 ...
23
votes
3answers
7k 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 -...
2
votes
1answer
897 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
3answers
351 views

Write buffer list to file

I would like to have a file that contains all files that I opened with vim in the past. I know that there is the viminfo file but I want to have just a file with the filenames. For this I would like ...
5
votes
3answers
922 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 ...
1
vote
0answers
17 views

How to customize how neovims "shell command buffer" is shown?

I am wondering about the behavior of the buffer that appears in the bottom of the terminal when running a shell command in neovim. How can I make it appear the right side instead? How can I make the ...
1
vote
2answers
33 views

How can I open python output in a editable buffer?

I am using this in my vimrc, to get output of current script printed on the screen when I click enter. autocmd FileType python map <buffer> <CR> :w<CR>:!python3 %<CR> How can ...
1
vote
1answer
29 views

Run autocommand only after all buffers have been written using :wa

I use an autocmd to copy a directory using rsync when saving a file with BufWritePost. When I save multiple files at once (using :wa), it runs rsync after every buffer save. How can I run rsync or the ...
0
votes
1answer
80 views

Useful script to manage buffer and window?

I want to create a vertical split from current buffer for reference another file/the same file. After I've done with this split I don't want to see this buffer-for-reference in the split, but: If ...
4
votes
2answers
109 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? ...
1
vote
1answer
116 views

What's the difference between `BufWinEnter` and `BufEnter`?

I need an example to differentiate the two events in Vim, as I'm having a hard time understanding them.
1
vote
1answer
28 views

BufDelete running after window is closed

For some reason, the BufDelete autocommand is being executed right after a window is created, instead before, and i think it shouldn't be like that, according to the docs: Before deleting a buffer ...
0
votes
1answer
290 views

In Vim, how to tag/enrich buffers with custom information (that persist naturally)

Gday, I am trying to persist some state about my buffers, specifically terminal buffers, over vim sessions with :mksession through the plugin 'vim-session' by xolox. The goal is to assign labels to ...
1
vote
1answer
109 views

VIM error: WARNING: The file has been changed since reading it!!! How to view the changes VIM is complaining about?

Is there a quick way to see the differences VIM is describing?
3
votes
1answer
83 views

How to use NerdTree to automatic focus on the current opened file position when toggle it on?

When use vim with nerdtree, I opened a file in a project. Press <Leader> key to trigger NERDTreeToggle. On the left side it will list the whole project directory by default. I want to let it ...
1
vote
1answer
206 views

Buffer list per window

How could I get something like a buffer/argument list or a filter for individual windows, with a chosen subset of the buffers? So I could have a window just for header files in C (files ending in .h)...
3
votes
1answer
871 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 ...
0
votes
0answers
17 views

How to add new command to a buffer by buffer number

-buffer flag in :command adds a command to the current buffer but how can I add command to a buffer by a given buffer number.
1
vote
1answer
23 views

Tab page is closing when deleting buffer

I'm using bufferline.nvim in order to display both buffers and tab pages on the tabline, whenever i delete a buffer with bd, all the buffers on that tab page are deleted as well, alongisde with the ...
0
votes
1answer
50 views

Call range argument to execute in python terminal embeded in vim

Initial window: My expectation: to copy whole or a part of python code in the right window into the left window's python terminal and execute. My .vimrc setting: function! CopyPasteBuffer() ...
1
vote
1answer
43 views

Echo filename before deleting buffer

I would like to echo the filename before deleting any buffer (:bd, :q). I wanted to achieve this by using auto-commands like this: augroup DummyCodeGroup autocmd! autocmd BufDelete * lua print(...
31
votes
1answer
9k 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 ...
2
votes
2answers
534 views

Save buffer before opening new file

When I'm in a modified buffer and try to open a file using :e otherFile I get E37: No write since last change (add ! to override) Since this happens fairly often, I'd like to automatically save the ...
1
vote
0answers
13 views

Macro doesn't run properly when executed with :bufdo or :argdo

I have a macro that looks like: :reg a Type Name Content c "a /^where^MkV%yGo^M-- Some typing...:^[pVG:!/tmp/t.sh^M It works fine from any starting position in the file when I replay it ...
17
votes
5answers
13k 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.
3
votes
1answer
64 views

Can not move to other buffers unless I save the current one

I launch vim with two files. I can move from one file to the other by :bp or :bn quite happily. But as soon as I make a change to file1 it won't allow me to move to the other buffer unless I save the ...
0
votes
1answer
65 views

Vim - mapping a text string to specific buffer

I like to know how I can connect/map a specific string to a desired buffer. Let's say I have the following text files: file1: Dog Cat file2: Milk Now, the 2 files are located at different dirs, and ...
0
votes
0answers
20 views

After opening all args with :ba, go back to a single split

Generally when opening more than two or three files in vim, I use a single split, navigating between the files/buffers with :n/:N. Sometimes, however, I want to open all of them in visible splits at ...
0
votes
0answers
22 views

What is happening that the cursor is moved back to line 1 when my first line starts with a number?

Once in a while, I have a file which somehow forces the cursor to line 1 when I switch back to it with Ctrl-^. So, I load 2 or more files, and one of the file starts with the following: 1. blah ...
3
votes
2answers
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 ...
1
vote
1answer
26 views

How to glob the buffer-list?

Having a command: command! -nargs=+ Foo call s:my_fun(<f-args>) How can I get a glob-match when user say: Foo *met*.c ?
1
vote
1answer
47 views

Vim splits the window horizontally whenever i switch between buffers if i didn't get the data written to the disk first

I currently use ctrlp to navigate between buffers in vim , but whenever i try to switch to another buffer it automatically splits the current window horizontally into two windows . In order to avoid ...
1
vote
2answers
53 views

Way to open the list of buffers to easily prune (delete) many buffers at once?

:files is nice, but I want to delete a bunch of buffers at once. I know about :bd n1 n2 ... and :m,nbd, but it'd be nice to manipulate the list (e.g. to delete buffers) in a 'regular' window. Is there ...
5
votes
2answers
245 views

Closing all buffers that represent .js files?

Can I close all buffers by regex, for instance all buffers that hold open .js files? Effectively what I want is :bd *.js But even with ! if more than one .js is open I get, E93: More than one ...
1
vote
1answer
65 views

argdo vs bufdo for project-wide search and replace in specific folders

I have the following structure: myproject ----src file1.cpp, ..., file10.cpp ----include incl1.h, ..., incl10.h ----data data1.txt, ..., data10.txt I would like to ...
67
votes
8answers
46k 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 ...
15
votes
7answers
3k 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 ...
0
votes
2answers
43 views

VI - Insert buffer before

I've recently begun using buffers, rather than tabs, to sort files in vi. My question is, can I create a buffer such that, instead of getting this: [:enew] [:ls] 1 main.c 2 foo.txt 3 [No Name] I got ...
0
votes
1answer
12 views

Sort quickfix entries by most relevant files?

I have a project that has a lot of warnings. I'm wondering (until I fix all the errors) how I can make my quickfix results more relevant? My compiler script uses %t so it can differentiate errors from ...
0
votes
0answers
16 views

GoToDefinition used to show result in a split window, but now uses buffer

I have this mapping in my .vimrc: nnoremap gd :YcmCompleter GoToDefinitionElseDeclaration nnoremap gf :tab split \| YcmCompleter GoToDefinition<CR> When I press gd, it writes the command :...
1
vote
3answers
218 views

Can I open a file using the index shown by ":scriptnames"?

I am wondering how to open a file or load it into a buffer using the index shown by :scriptnames? 23: /usr/share/vim/vim80/plugin/tarPlugin.vim 24: /usr/share/vim/vim80/plugin/tohtml.vim 25: /usr/...
1
vote
1answer
51 views

Character level buffer modification

It is possible to modify buffer at the line granularity. E.g. :py3 vim.current.buffer[0] = "abc". But it deletes the attached marks even if a single character is replaced. Is it possible to ...
7
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 ...
1
vote
0answers
37 views

How can I track the event of opening a file in netrw in an autocommand?

I'm trying to solve this problem by creating an autocommand which will track when a new buffer is opened through netrw, and will then immediately close netrw once the buffer is closed. How can I track ...
1
vote
1answer
188 views

Periodic W11 "File has changed" warnings when reading file

I'm on Archlinux with vim 8.2.2380. Since running updates yesterday, I'm getting W11 warnings periodically just by having a file open in a buffer which has changed on the FS (e.g. when opening log ...
1
vote
0answers
63 views

How to sort the list of buffers

How to sort the list of buffers Vim displays on entering :b <Tab> by most recent? I'm used to the Spacemacs ordering, which displays buffer filenames in separate rows (vertically) in the order ...
0
votes
1answer
43 views

Automatically save deleted lines to a new file?

I have a to do list that I manage in vim. I want to keep track of things I remove from the list. After I type dd to delete a line, I want to write this line to a different file. I only want this ...
0
votes
0answers
56 views

Display all the buffers in all the open vim Windows?

There's this really great feature in Firefox, where you can search all the open tabs by typing % and then typing what open tab you are searching for. Is it possible to do something similar to this ...
2
votes
2answers
69 views

Making functions react to keypress

Im very new to vim scripting. I have the following script in my .vimrc: If there is no user input aka I press <CR> => go to recent buffer If input is 'd' => delete all buffers except for ...
1
vote
1answer
130 views

Can you turn a popup into a regular buffer?

I have a popup / floating window open which is normally used for temporary jobs, like searching the code or opening a quick REPL. Is it possible to turn that into a regular buffer? While I have it ...

1
2 3 4 5
8