Open files in existing Gvim in multiple (new) tabs

gvim open multiple files
open file in new tab gvim
vi multiple files
gvim open tabs
how to open file in gvim
gvim open new window
vim command to open multiple files in tabs
neovim open new tab

I have put some aliases in my .bashrc to open a group of project files in gvim, each in their own tab:

gvim -p <list of file names using absolute paths>

This is all well and good, except there are several groups of files I might want to move between at any given time (my current project uses Ruby on Rails, so that explains that). What would be really awesome is if I could append the new tabs to an existing instance of gvim. In my last position I worked on Vista; I got around this by opening a bunch of empty tabs in gvim, which allowed me to right-click on a filename and choose "Open in existing No-Name gvim." Now I use Ubuntu and there's no such thing on the context menu. Is there any way to do this from the command line?

If vim is compiled with the clientserver option, you can do it. Start your vim instance with the following flag:

$ gvim --servername GVIM  # GVIM is the server name. It can be anything.

To open more tabs in this instance, you can run the command:

$ gvim --servername GVIM --remote-tab file1 file2 file3 ...

The clientserver feature in vim is very handy. It's not limited to opening files; it can be used to send any command to vim using the command-line. For example, to close a vim instance remotely, you can use:

$ gvim --servername GVIM --remote-send '<Esc>:wqa<CR>'

Open files in existing Gvim in multiple (new) tabs, Easy: gvim -p file1.c file3.c or: gvim -p *.c. You can open multiple files in gvim. After you've selected the files you want to open, right-click and select "Edit with single Vim". Vim will initially display only the first file, but all the file names are in Vim's argument list.

From inside of Gvim, type :tabe {file_name}. This opens the named file in a new tab. If you aren't fond of typing long filenames, try this:

:e .

This will open a new, blank tab page and open a file browser. You can mouse click your way around or use the keyboard. Click or hit the enter key on the file you want to open it. Try using the keyboard to position the cursor over the file you want to open and then hit 't'. This opens the selected file in a new tab, keeping the file browser open in the first tab. This might be a fast way to open a bunch of files.

There are a whole lot of things you can do with tab pages that might make life easier. To get to the relevant section in Vim's on line help manual, type :h tabpage.

gVim: How to open multiple files in its own tab at once?, :tab all. will open all the files in Vim's argument list in individual tabs. The argument list is initially set to the list of file names given on the command line when Vim� With vim, you can use tabs also, just like you would in gvim or any other GUI editor. You can open files in multiple tabs in two ways. The first is to execute vim with each file specified: $ vim

Want your Windows context menu to allow you to open files in a new tab of the currently open gvim window?

Save this as as a file called temp.reg and double-click it to add the settings to your registry. Be sure to modify the path to vim if yours is different.

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\Shell\Open with &Vim]
[HKEY_CLASSES_ROOT\*\Shell\Open with &Vim\command]
@="\"C:\\Program Files (x86)\\Vim\\vim73\\gvim.exe\" -p --remote-tab-silent \"%1\" \"%*\""

You will now have a context menu like this:

How to get vim to open multiple files into tabs at once, By default gVim for Windows adds an option to the Explorer right-click menu that contains That doesn't handle pressing Enter with multiple files selected though. "Edit with Vim VSplit" (vertically split the existing tab for each). "Edit with Vim Split". "Edit with Vim VSplit Tab" (open a new tab first, then open all the files you� if you want file to open in new tab C:\Program Files\Vim\vim72\gvim.exe --remote-silent "%1" if you want to open file in new buffer The path might need to be modified for the location of gvim on your machine. In Windows Explorer, double-click one or more files and they should open in tabs in gvim!

Linux users may use this kind of script:


ANS=`pgrep -fx "gvim --servername GVIM"`

echo $@

if [[ ! $ANS ]]; then
    gvim --servername GVIM

if [[ $1 ]]; then
    gvim --servername GVIM --remote-tab "${@}"

And then edit gvim.desktop file for using this script:

Exec=/home/user/bin/ %F

Gvim how to open several files in different buffers from MS Windows , Many text editors automatically launch new files in tabs, rather than use a You can repeat this to open other files in new tabs in the same Vim instance. So let’s stick to the last example, but this time we want to open the 3 files in separate tabs by using the -p CLI flag: vim -p /path/to/file1 /path/to/file2 /path/to/file3 Vim is launched as before, but this time all files will be opened in tabs instead of hidden buffers. The tab bar is displayed on the top of the editor / window.

There is a way:

n*.cpp|tab ba

or if you like to split:


If you wish to know more:

:help ba

and I don't know what is n , but it would not work without it.

Launch files in new tabs under Windows | Vim Tips Wiki, The second way to open files is to create new tabs within vim and open files using :tabnew file.txt in command mode, which opens a new tab and� If the file you are editing contains the name of another file, you can put the cursor on the name and type gf to edit the file ( goto file ). If you type Ctrl-W gf the file is displayed in a new tab. In gvim, you can right click the tab label bar for a popup menu with Close, New Tab, and Open Tab items.

Use tabs to open multiple files in vim, - If you select multiple files and use the Windows context menu, each file gets its own invocation of the command. gvim does not handle several simultaneous --� :tabnew filename to open a file in a new tab. From the terminal, you can do vim -p filename1 filename2 to open the two files in tabs. I have added the following lines to my.vimrc that allow me to switch between tabs easily.

gvimt, Of course you can also open a new tab when you're already in Vim in the normal mode: :tabe [/path/to/file] (command-line command). When you run this script it will open a file in a new tab in an existing gvim window on the current desktop, or open new one if no gvim window exists on the current desktop, using --servername in both cases to specify a name for the new Vim instance which is specific to the current desktop.

Mastering Vim: Working with multiple files – confirm blog, We know that gvim -p can be used to open multiple files together in different tabs in gvim. However if you want to open a file in a new tab in the� If the -t option is specified, then files are opened in separate tab pages in an existing instance of GVim or MacVim if it exists. If no instance of GVim or MacVim already exists, the files are opened in separate tabs in a new instance of the editor. vimer -t foo.txt bar.txt baz.txt

  • see vim -h for other remote options
  • I added my -geom option to the initial command to start gvim. I also had to remove the -p option (for tabs) from all the aliases. Then it worked great!
  • Well, it works great except for one thing: if I have more than one instance of gvim, the first being the server one and the second (or more) created from the CL or by clicking on an icon or by selecting a file to open with gvim, then I attempt to open a tab in the server one (I have aliases set up as mentioned), the new tabs always go in the second instance, no matter how it was created or which instance was last active. Any ideas?
  •… keeps it to one instance.
  • This is also a great trick for opening a file in an existing instance of gvim. I use it for things that I don't need often enough to make an alias for, and when I just want one file rather than a whole slew of them.
  • Wait, there's more! You can do this with just one command: :tabnew %
  • Given command :tabnew %, Gvim opened a new tab containing the buffer (filename) from the previous tab from which I entered the command. Is this the correct behaviour?
  • @DerekMahar Yes, % refers to the filepath of the file you're currently working on. You might be able to navigate to another file from that, but I don't know enough about vim to tell you how to do that.
  • You can shorten that to :tabe .. If you want to open another file from the same directory, you can try :tabe %:h
  • The question was asking how to do this on Ubuntu.
  • if Ubuntu user is smart enough to pick up the command line form the answer it would work for him as well. (Checked on Arch Linux :))