7

Cut out the middle man. If you want to edit a file in a split, use :split file.txt. It is the very nature of using <C-W>n that creates these new buffers. It's like using the :new command, which is wasteful if you plan to immediately edit some other file. If you like the visual confirmation of seeing the new window before editing the file, you could ...


6

Your function returns nothing, but you call it expecting the buffer number. This should work: function! ScratchBuffer() vnew setlocal nobuflisted buftype=nofile bufhidden=wipe noswapfile return bufnr('%') endfunction


5

I'm not aware that you can create a hidden unnamed buffer. But you can create a hidden (even unlisted) buffer with some fancy name and use that. In VimScript: let g:myscratch = bufnr("my-fancy-name", 1) call setbufvar(g:myscratch, "&buftype", "nofile") The first line returns the buffer number for the buffer named "my-fancy-name". If the buffer does ...


3

As of 7.4.1802, Vim is supposed to quickfix lines up to 4096 bytes long instead of truncating them.


3

The 'hidden' setting The 'hidden'/'nohidden' setting tells Vim what to do about buffers that are "abandoned". 'hidden' means an abandoned buffer becomes hidden (similar :hide). 'nohidden' (the default) means the buffer is unloaded (:bunload). Both :bunload and :hide do not remove a buffer from the buffer list. Therefore 'hidden' setting will not affect ...


2

You want to add the following line to your vimrc: set hidden From :h 'hidden': 'hidden' 'hid' boolean (default off) global {not in Vi} When off a buffer is unloaded when it is abandoned. When on a buffer becomes hidden when it is abandoned. This option allows you to change of buffer even if the modifications were not ...


2

Use :h :wincmd to manipulate window in script, it follow the same rule as :h CTRL-W . e.g. If you want to jump to window 3, you can do it by 3<c-w><c-w> in normal mode, or :3wincmd w in script. Use :h bufwinnr() to get window number for a specific buffer. Use :h :execute to combine them together: :execute bufwinnr(bufnr) 'wincmd w' Use :h window-...


2

With vim only There's a few options to make navigation between files less tedious in vanilla vim. First, you need set switchbuf=useopen in your vimrc (:h 'switchbuf') to reuse a split (if it exists, else it will create it), instead of opening the buffer in the current split. If you have the buffer number in 'statusline' (i.e %n), you can then easily switch ...


1

Netrw already includes code that attempts to reuse buffers but, as you have discovered, this code currently appears not to handle tree listings and ends up creating many buffers. So the first thing to try is to make sure you are using the latest version of netrw. It looks like the code has changed as recently as July 2019, so it's possible this is something ...


Only top voted, non community-wiki answers of a minimum length are eligible