I want to write all open buffers in current tab only, without touching buffers of other tabs.
Sth like :wa command but for only one or current tab.
I guess you want sort of
:windo update
Related
I open a bunch of files by vim *.html *.css *.js, and I want to know how to open those targeted files in background buffers without mess up current window?
I tried to use vsplit, then "buf <buffer-number-I-want-to-open>, then C-w T. But I found it's way to tedious.
So is there a clear way to do that? thanks!
When you launch vim by vim *.html *.css *.js, the argument would be loaded into your vim argument list.
you can get the list it by args:.
And you can use :next, :previous, first, last, to traverse them.
if you want to open them all as tab?
you can use argdo: argdo tab split. this will dispatch a tab split command to each element in the arglist.
see:
:help :args
:help :argdo
:help :tab
you can :tabnew then use :next or buffer + <num> to open background buffers. but it will introduce a NO NAME buffer.
a neater way is to use CtrlP's buffer view, then press <Ctrl-t> and you will have it.
--
plugin Ctrl-P can perfectly achieve this, if you want to save your time, you can stick with it.
For example, suppose you have 3 buffers, where you are in buffer 1 and 2 more buffers are in background.
:ls
1 %a index.html
2 style.css
3 h script.js
Assume that you want to open buffer 3 script.js
open CtrlP,
switch to buf view, and choose the buffer your want to open
then press <C-t>, you would be able to open the buffers in new tab
Cheers!
is there any way I can have multiple windows in a terminal based vim, without splitting the window? so I could just switch to the other file by hitting a key ?
if "window" you meant is vim-window, the answer is no.
In vim, a window is a viewport onto a buffer. You can use multiple windows on one
buffer, or several windows on different buffers.
So window is viewport, if you there is no splitting you are watching on single window, no multiple.
I guess what you meant is buffer: A buffer is a file loaded into memory for editing. The original file remains unchanged until you write the buffer to the file.
You can have one window (without splitting) and 10 files(buffers). You could :ls to see the buffer list, and also by command to switch among those buffers/files. display them in single window.
you can get more info about switching files/buffers by:
:h buffer
You could use tabs.
To open a new tab you can use :tabe <file>. After that you can use gt or gT to move to the next or previous tab.
If you are opening a bunch of files from the command line you can use vim -p <files> to open them all in tabs.
Take a look at :h tab-page-commands
Is there a function in Vim which will switch to a buffer? For example, if I know that I have the TODO.txt file open in some window in some tab, I’d like to jump to that tab and focus that window. Is that possible?
set swb=useopen,usetabe will set make :sb [number] or :sb [pattern] switch to an open window in whichever tab.
I believe it's :drop filename
I use
:buf TODO
you need a unique identifiying piece of the buffers filename. You can use tab-completion, though :)
Oh IC, just noted that you want to activate the corresponding tab. Sry
I’d like to save the files opened in all vertical/horizontal windows? Is it possible without going to each window and executing the :w! command?
To save only those buffers that opened in the current tab page and not
those that are hidden, run the :write command for every open window:
:windo w!
In order to save all open buffers regardless of the corresponding
windows’ locations, run the :wall command:
:wa!
There is also a similar command
:bufdo w!
but it does not behave in quite the same fashion. Both commands affect
hidden buffers, but :wall does not attempt to write the buffers
that do not have a file name set.
Yes, you can do this with :wa.
Use :wall
It writes all changed buffers (but it will also save the hidden one).
I open several files in Vim by, for example, running
vim a/*.php
which opens 23 files.
I then make my edit and run the following twice
:q
which closes all my buffers.
How can you close only one buffer in Vim?
A word of caution: “the w in bw does not stand for write but for wipeout!”
More from manuals:
:bd
Unload buffer [N] (default: current
buffer) and delete it from
the buffer list. If the buffer was changed, this fails,
unless when [!] is specified, in which case changes are
lost.
The file remains unaffected.
If you know what you’re doing, you can also use :bw
:bw
Like |:bdelete|, but really delete the
buffer.
If this isn't made obvious by the the previous answers:
:bd will close the current buffer. If you don't want to grab the buffer list.
Check your buffer id using
:buffers
you will see list of buffers there like
1 a.php
2 b.php
3 c.php
if you want to remove b.php from buffer
:2bw
if you want to remove/close all from buffers
:1,3bw
Rather than browse the ouput of the :ls command and delete (unload, wipe..) a buffer by specifying its number, I find that using file names is often more effective.
For instance, after I opened a couple of .txt file to refresh my memories of some fine point.. copy and paste a few lines of text to use as a template of sorts.. etc. I would type the following:
:bd txt <Tab>
Note that the matching string does not have to be at the start of the file name.
The above displays the list of file names that match 'txt' at the bottom of the screen and keeps the :bd command I initially typed untouched, ready to be completed.
Here's an example:
doc1.txt doc2.txt
:bd txt
I could backspace over the 'txt' bit and type in the file name I wish to delete, but where this becomes really convenient is that I don't have to: if I hit the Tab key a second time, Vim automatically completes my command with the first match:
:bd doc1.txt
If I want to get rid of this particular buffer I just need to hit Enter.
And if the buffer I want to delete happens to be the second (third.. etc.) match, I only need to keep hitting the Tab key to make my :bd command cycle through the list of matches.
Naturally, this method can also be used to switch to a given buffer via such commands as :b.. :sb.. etc.
This approach is particularly useful when the 'hidden' Vim option is set, because the buffer list can quickly become quite large, covering several screens, and making it difficult to spot the particular buffer I am looking for.
To make the most of this feature, it's probably best to read the following Vim help file and tweak the behavior of Tab command-line completion accordingly so that it best suits your workflow:
:help wildmode
The behavior I described above results from the following setting, which I chose for consistency's sake in order to emulate bash completion:
:set wildmode=list:longest,full
As opposed to using buffer numbers, the merit of this approach is that I usually remember at least part of a given file name letting me target the buffer directly rather than having to first look up its number via the :ls command.
Use:
:ls - to list buffers
:bd#n - to close buffer where #n is the buffer number (use ls to get it)
Examples:
to delete buffer 2:
:bd2
You can map next and previous to function keys too, making cycling through buffers a breeze
map <F2> :bprevious<CR>
map <F3> :bnext<CR>
from my vimrc
Close buffer without closing the window
If you want to close a buffer without destroying your window layout (current layout based on splits), you can use a Plugin like bbye. Based on this, you can just use
:Bdelete (instead of :bdelete)
:Bwipeout (instead of :bwipeout)
Or just create a mapping in your .vimrc for easier access like
:nnoremap <Leader>q :Bdelete<CR>
Advantage over vim's :bdelete and :bwipeout
From the plugin's documentation:
Close and remove the buffer.
Show another file in that window.
Show an empty file if you've got no other files open.
Do not leave useless [no file] buffers if you decide to edit another file in that window.
Work even if a file's open in multiple windows.
Work a-okay with various buffer explorers and tabbars.
:bdelete vs :bwipeout
From the plugin's documentation:
Vim has two commands for closing a buffer: :bdelete and :bwipeout. The former removes the file from the buffer list, clears its options, variables and mappings. However, it remains in the jumplist, so Ctrl-o takes you back and reopens the file. If that's not what you want, use :bwipeout or Bbye's equivalent :Bwipeout where you would've used :bdelete.
How about
vim -O a a
That way you can edit a single file on your left and navigate the whole dir on your right...
Just a thought, not the solution...
[EDIT: this was a stupid suggestion from a time I did not know Vim well enough. Please don't use tabs instead of buffers; tabs are Vim's "window layouts"]
Maybe switch to using tabs?
vim -p a/*.php opens the same files in tabs
gt and gT switch tabs back and forth
:q closes only the current tab
:qa closes everything and exits
:tabo closes everything but the current tab
Those using a buffer or tree navigation plugin, like Buffergator or NERDTree, will need to toggle these splits before destroying the current buffer - else you'll send your splits into wonkyville
I use:
"" Buffer Navigation
" Toggle left sidebar: NERDTree and BufferGator
fu! UiToggle()
let b = bufnr("%")
execute "NERDTreeToggle | BuffergatorToggle"
execute ( bufwinnr(b) . "wincmd w" )
execute ":set number!"
endf
map <silent> <Leader>w <esc>:call UiToggle()<cr>
Where "NERDTreeToggle" in that list is the same as typing :NERDTreeToggle. You can modify this function to integrate with your own configuration.