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
Related
When I use :Ex to open a new file, Vim sometimes decides to split the window horizontally. I don't like that behavior. I prefer what Vim usually does, which is to open the file in its own... window, I guess it's called in Vim? Anyway, when it doesn't split the window horizontally. How can I control what behavior is trigger by an :Ex?
Well :h is your friend. :h :Ex shows you the following:
:Explore will open the local-directory browser on the current file's
directory (or on directory [dir] if specified). The window will be split only if the file has been modified and |'hidden'| is
not set, otherwise the browsing window will take over that window.
Normally the splitting is taken horizontally. Also see:
|netrw-:Rexplore|
So vim will split the window, if you haven't saved your changes. This is to ensure, that you don't lose anything. I am not aware of any possibility to turn it off. You could of course redefine :Ex to just discard or save changes.
Usually when I open a file in Vim when there's already one open Vim opens the file in a whole new... buffer? Screen thing? In other words, it takes up the full vim client area so that I have to :bn through to see the next file, which I prefer. But sometimes when I open a file Vim decides to split the window horizontally and put it in one of those horizontal buffer things.
When does it decide to split the window as opposed to giving me the whole thing? How can I prevent that behavior? And perhaps most important, what is the name for that kind of behavior so I can do better searches in the future?
Quoting from :help window:
A buffer is an in-memory text of a file
A window is a viewport of a buffer
Buffers are enumerated. When you run :bufnext or :bn, you go to the next buffer; you can also use :b<num> to go to a specific buffer, say :b2 to go to buffer 2. You can get the list of buffers with :ls.
When you :split or :vsplit, you open a new window, i.e. a new viewport for a buffer. You can have two windows show the same buffer, and so on.
Also, a tabpage is a collection of buffers; open a new tab with :tabnew and cycle through them with gt and gT to go forward and backward respectively.
I highly recommend you read the helpfile; it's all there.
The opposite question seems to be asked a lot: how to move a window into a new tab in an existing window. What I'm hoping is that a tab that I have open in gvim can be moved out into its own window or into another existing window.
Is this possible?
Thanks!
Same Vim instance
If that tab shows just a single window, you just have to note its buffer number (e.g. via :ls or :echo bufnr(''), or by including it in the statusline), and then close the tab via :close (:set hidden helps with modified buffers), then going to the target tab / window, and re-opening the buffer there via :buf N or :sbuf N.
If you need to support multiple windows in a tab page, you'd have to write a custom command / mapping that first remembers the buffers, and then applies the above steps for all of them.
Different Vim instances
Edit: The above is for movement within a single Vim instance. If you want to move a buffer to another GVIM instance, you first have to :bdelete it in the current Vim, to avoid swap file messages. Launching in new instances is easy:
:execute 'bdelete | !start gvim' shellescape(expand('%:p'), 1)
This passes the (full absolute) path of the current file to a fresh GVIM.
To move a file to an existing GVIM (you need to know its v:servername), you need to use the remote client-server communication (:help remote.txt), e.g. by sending a similar :drop command via remote_send(), like this:
:execute 'bdelete | call remote_send("GVIM1", ":drop " . ' . string(fnameescape(expand('%:p'))) . '. "\<CR>")'
Here is how you can "move" the current buffer to a second GVim instance:
:!gvim --remote %
:bw
Note that Vim must be built with the +clientserver option.
No, it is not possible.
You cannot move a vim tab into a window, no matter new or existing. Because a vim tab page is a collection of windows. You cannot move a collection of windows into one single window.
I often edit long files in vim that have blocks of code in multiple disparate places in the file that I need to be constantly going back and forth between. Obviously, one way of solving this is to split the window with :split and edit each portion in a different split window, and a :w in either window will save the whole file. This is well and good if you have a large enough screen but sometimes I have to use vim on a low-resolution laptop and I don't want to reduce my screen space further by splitting the window.
In this case, what I'd really like to do is edit the file in multiple tabs, and treat each separate tab exactly like a separate view split. I can sort of mimic this by using :tabopen <the same filename> once I have one copy of the file open, but this is sort of hacky — it doesn't work if I've already made changes to the file because vim thinks I'm just opening the file a second time.
Is there a good way to get the behavior I want with tabs in vim?
The :tab command takes a command as argument.
So you can do this:
:tab split
This will work even if the buffer is modified, and a save in either tab saves the file, updating the saved state in both.
You can use the :tab command:
:[count]tab {cmd}`
Execute {cmd} and when it opens a new window open a new tab page instead. [...] When [count] is omitted the tab page appears after the current one. When [count] is specified the new tab page comes after tab page [count]. Use :0tab cmd to get the new tab page as the first one.
Examples:
:tab split " opens the current buffer in new tab page
:tab help gt " opens tab page with help for "gt"
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).