3

I currently open my text files with GVim by double-clicking them in my file manager (Thunar, in Xubuntu 16.04). However, when opening a new file, I want GVim to open it as a new tab rather than a new window, pretty much as in other text editors like Sublime Text or Notepad. I have seen posts here or online that relate to open files as tab when opening files via command line (or inside vim). I want to open the files externally.

I cannot figure how to do this. Below are the list of settings that GVim offers me related windows and tabs, but I cannot see which one is relevant here.

6 multiple windows

laststatus  0, 1 or 2; when to use a status line for the last window
    set ls=1
statusline  alternate format to be used for a status line
    set stl=
equalalways make all windows the same size when adding/removing windows
    set ea  noea
eadirection in which direction 'equalalways' works: "ver", "hor" or "both"
    set ead=both
winheight   minimal number of lines used for the current window
    set wh=1
winminheight    minimal number of lines used for any window
    set wmh=1
winfixheight    keep the height of the window
    (local to window)
    set nowfh   wfh
winfixwidth keep the width of the window
    (local to window)
    set nowfw   wfw
winwidth    minimal number of columns used for the current window
    set wiw=20
winminwidth minimal number of columns used for any window
    set wmw=1
helpheight  initial height of the help window
    set hh=20
previewheight   default height for the preview window
    set pvh=12
previewwindow   identifies the preview window
    (local to window)
    set nopvw   pvw
hidden  don't unload a buffer when no longer shown in a window
    set nohid   hid
switchbuf   "useopen" and/or "split"; which window to use when jumping
    to a buffer
    set swb=
splitbelow  a new window is put below the current one
    set nosb    sb
splitright  a new window is put right of the current one
    set nospr   spr
scrollbind  this window scrolls together with other bound windows
    (local to window)
    set noscb   scb
scrollopt   "ver", "hor" and/or "jump"; list of options for 'scrollbind'
    set sbo=ver,jump
cursorbind  this window's cursor moves together with other bound windows
    (local to window)
    set nocrb   crb

 7 multiple tab pages

showtabline 0, 1 or 2; when to use a tab pages line
    set stal=1
tabpagemax  maximum number of tab pages to open for -p and "tab all"
    set tpm=10
tabline custom tab pages line
    set tal=
guitablabel custom tab page label for the GUI
    set gtl=
guitabtooltip   custom tab page tooltip for the GUI
    set gtt=

Any idea how to do this? I don't want to have 5 Vim instances open when dealing with many editing simultaneously.

2
  • 3
    I think this is related vi.stackexchange.com/q/3681/1841
    – statox
    Commented Sep 20, 2017 at 15:53
  • @statox I'm not so sure, as that question is about Windows & Explorer, where the solution involves a registry hack. I suspect the solution to this one would involve a setting in the particular file manager.
    – Herb
    Commented Sep 20, 2017 at 17:41

1 Answer 1

3

You could try the command gvim --remote-tab-silent %F. Thunar should substitute %F with the paths of all selected files.

--remote-tab-silent is a variant of --remote. For more info about it, see :h --remote, :h --remote-silent and :h --remote-tab-silent.

There are various ways to tell Thunar to use this command when you double-click on a file.


In the settings menu of Xubuntu, there's a section called System. Inside this section, there's an entry called MIME Type Editor. If you click on it, you will be presented with a window where you can choose the default applications that the OS should use to open various types of files.

You can restrict the MIME Types to the ones prefixed with text/, since they are the most relevant for gVim. Then, you can look for a type of file you want to open with your custom command gvim --remote-tab-silent %F.

As an example, suppose you are only interested in log files, you could improve the filtering by writing in the filter field text/x-log.

Click on the default application. It should be gVim, mousepad or some other editor. Then, click on Choose Application..., and on Use a custom command:. In the new field, you could type your gvim --remote-tab-silent %F command. Finally, validate with Open.


You could achieve the same result by:

  • doing a right-click on a text file
  • clicking on Properties
  • opening the Open With menu
  • clicking on the Use a custom command: entry
  • entering gvim --remote-tab-silent %F in the field which has just been opened

In Thunar's toolbar, you could also:

  • click on Edit
  • click on Configure custom actions...
  • click on the + button (whose tooltip reads Add a new custom action.)
  • in the Name: field, give a name to the new entry you want to add in Thunar's contextual menu; example my_gvim
  • in the Command: field, insert the command gvim --remote-tab-silent %F
  • validate with OK

After this, when you right-click on a file, or a set of selected files, the contextual menu should contain the entry my_gvim. If you click on it, it should open the selected files in gVim, one tabpage per file.

If you don't see the my_gvim entry, go back to the menu where you created the entry, click on the edit button (right below the +), select the 2nd tab (its title is Appearance Conditions), and make sure that the box Text Files is ticked (and that the filename pattern is not too restrictive).


If you want to edit multiple MIME types, you can try the following method, but I'm not sure it will work for you.

Inside ~/.local/share/applications/, create a file named my_gvim.desktop (or however else you want). In this file, import the contents of another .desktop file, and edit it so that it contains your custom command. As an example, I wrote this:

[Desktop Entry]
Version=1.0
Type=Application
Name=MyGvim
Icon=
Exec=gvim --remote-tab-silent %F
NoDisplay=
Categories=
StartupNotify=false
Terminal=false

The important line is the one prefixed by Exec=.

Then, you need to find a mimeapps.list file in your home directory. I used ~/.config/mimeapps.list (you may also try ~/.local/share/applications/mimeapps.list).

In this file, write your MIME types, using the desktop file you created earlier. For example:

text/markdown=my_gvim.desktop;
text/x-log=my_gvim.desktop;

Add one line per MIME type.

If you want to find all the MIME types relative to text files, you could have a look at the list of .xml files inside /usr/share/mime/text/. On my system, I found this list of MIME types:

text/cache-manifest
text/calendar
text/css
text/csv-schema
text/csv
text/enriched
text/html
text/htmlh
text/markdown
text/plain
text/rfc822-headers
text/richtext
text/rust
text/sgml
text/spreadsheet
text/tab-separated-values
text/troff
text/turtle
text/vcard
text/vnd.graphviz
text/vnd.rn-realtext
text/vnd.sun.j2me.app-descriptor
text/vnd.trolltech.linguist
text/vnd.wap.wml
text/vnd.wap.wmlscript
text/vtt
text/x-adasrc
text/x-apt-sources-list
text/x-authors
text/x-bibtex
text/x-c++hdr
text/x-c++src
text/x-changelog
text/x-chdr
text/x-cmake
text/x-cobol
text/x-copying
text/x-credits
text/x-csharp
text/x-csrc
text/x-dcl
text/x-dsl
text/x-dsrc
text/x-eiffel
text/x-emacs-lisp
text/x-erlang
text/x-fortran
text/x-genie
text/x-gettext-translation-template
text/x-gettext-translation
text/x-go
text/x-google-video-pointer
text/x-haskell
text/x-idl
text/x-imelody
text/x-install
text/x-iptables
text/x-java
text/x-ldif
text/x-lilypond
text/x-literate-haskell
text/x-log
text/x-lua
text/x-makefile
text/x-matlab
text/x-meson
text/x-microdvd
text/x-moc
text/x-modelica
text/x-mof
text/x-mpsub
text/x-mrml
text/x-ms-regedit
text/x-mup
text/x-nfo
text/x-objcsrc
text/x-ocaml
text/x-ocl
text/x-ooc
text/x-opml+xml
text/x-pascal
text/x-patch
text/x-python
text/x-qml
text/x-readme
text/x-reject
text/x-rpm-spec
text/x-scala
text/x-scheme
text/x-scons
text/x-setext
text/x-ssa
text/x-subviewer
text/x-svhdr
text/x-svsrc
text/x-tcl
text/x-tex
text/x-texinfo
text/x-troff-me
text/x-troff-mm
text/x-troff-ms
text/x-txt2tags
text/x-uil
text/x-uri
text/x-uuencode
text/x-vala
text/x-verilog
text/x-vhdl
text/x-xmi
text/x-xslfo
text/x-zim-wiki
text/xmcd

If you used this list, after editing it, you should get something looking like this:

text/cache-manifest=my_gvim.desktop;
text/calendar=my_gvim.desktop;
text/css=my_gvim.desktop;
text/csv-schema=my_gvim.desktop;
text/csv=my_gvim.desktop;
text/enriched=my_gvim.desktop;
text/html=my_gvim.desktop;
text/htmlh=my_gvim.desktop;
text/markdown=my_gvim.desktop;
text/plain=my_gvim.desktop;
text/rfc822-headers=my_gvim.desktop;
text/richtext=my_gvim.desktop;
text/rust=my_gvim.desktop;
text/sgml=my_gvim.desktop;
text/spreadsheet=my_gvim.desktop;
text/tab-separated-values=my_gvim.desktop;
text/troff=my_gvim.desktop;
text/turtle=my_gvim.desktop;
text/vcard=my_gvim.desktop;
text/vnd.graphviz=my_gvim.desktop;
text/vnd.rn-realtext=my_gvim.desktop;
text/vnd.sun.j2me.app-descriptor=my_gvim.desktop;
text/vnd.trolltech.linguist=my_gvim.desktop;
text/vnd.wap.wml=my_gvim.desktop;
text/vnd.wap.wmlscript=my_gvim.desktop;
text/vtt=my_gvim.desktop;
text/x-adasrc=my_gvim.desktop;
text/x-apt-sources-list=my_gvim.desktop;
text/x-authors=my_gvim.desktop;
text/x-bibtex=my_gvim.desktop;
text/x-c++hdr=my_gvim.desktop;
text/x-c++src=my_gvim.desktop;
text/x-changelog=my_gvim.desktop;
text/x-chdr=my_gvim.desktop;
text/x-cmake=my_gvim.desktop;
text/x-cobol=my_gvim.desktop;
text/x-copying=my_gvim.desktop;
text/x-credits=my_gvim.desktop;
text/x-csharp=my_gvim.desktop;
text/x-csrc=my_gvim.desktop;
text/x-dcl=my_gvim.desktop;
text/x-dsl=my_gvim.desktop;
text/x-dsrc=my_gvim.desktop;
text/x-eiffel=my_gvim.desktop;
text/x-emacs-lisp=my_gvim.desktop;
text/x-erlang=my_gvim.desktop;
text/x-fortran=my_gvim.desktop;
text/x-genie=my_gvim.desktop;
text/x-gettext-translation-template=my_gvim.desktop;
text/x-gettext-translation=my_gvim.desktop;
text/x-go=my_gvim.desktop;
text/x-google-video-pointer=my_gvim.desktop;
text/x-haskell=my_gvim.desktop;
text/x-idl=my_gvim.desktop;
text/x-imelody=my_gvim.desktop;
text/x-install=my_gvim.desktop;
text/x-iptables=my_gvim.desktop;
text/x-java=my_gvim.desktop;
text/x-ldif=my_gvim.desktop;
text/x-lilypond=my_gvim.desktop;
text/x-literate-haskell=my_gvim.desktop;
text/x-log=my_gvim.desktop;
text/x-lua=my_gvim.desktop;
text/x-makefile=my_gvim.desktop;
text/x-matlab=my_gvim.desktop;
text/x-meson=my_gvim.desktop;
text/x-microdvd=my_gvim.desktop;
text/x-moc=my_gvim.desktop;
text/x-modelica=my_gvim.desktop;
text/x-mof=my_gvim.desktop;
text/x-mpsub=my_gvim.desktop;
text/x-mrml=my_gvim.desktop;
text/x-ms-regedit=my_gvim.desktop;
text/x-mup=my_gvim.desktop;
text/x-nfo=my_gvim.desktop;
text/x-objcsrc=my_gvim.desktop;
text/x-ocaml=my_gvim.desktop;
text/x-ocl=my_gvim.desktop;
text/x-ooc=my_gvim.desktop;
text/x-opml+xml=my_gvim.desktop;
text/x-pascal=my_gvim.desktop;
text/x-patch=my_gvim.desktop;
text/x-python=my_gvim.desktop;
text/x-qml=my_gvim.desktop;
text/x-readme=my_gvim.desktop;
text/x-reject=my_gvim.desktop;
text/x-rpm-spec=my_gvim.desktop;
text/x-scala=my_gvim.desktop;
text/x-scheme=my_gvim.desktop;
text/x-scons=my_gvim.desktop;
text/x-setext=my_gvim.desktop;
text/x-ssa=my_gvim.desktop;
text/x-subviewer=my_gvim.desktop;
text/x-svhdr=my_gvim.desktop;
text/x-svsrc=my_gvim.desktop;
text/x-tcl=my_gvim.desktop;
text/x-tex=my_gvim.desktop;
text/x-texinfo=my_gvim.desktop;
text/x-troff-me=my_gvim.desktop;
text/x-troff-mm=my_gvim.desktop;
text/x-troff-ms=my_gvim.desktop;
text/x-txt2tags=my_gvim.desktop;
text/x-uil=my_gvim.desktop;
text/x-uri=my_gvim.desktop;
text/x-uuencode=my_gvim.desktop;
text/x-vala=my_gvim.desktop;
text/x-verilog=my_gvim.desktop;
text/x-vhdl=my_gvim.desktop;
text/x-xmi=my_gvim.desktop;
text/x-xslfo=my_gvim.desktop;
text/x-zim-wiki=my_gvim.desktop;
text/xmcd=my_gvim.desktop;
2
  • Thanks! Ok, so I made it work for a given file type by changing MIME types of that type adding the remote-tab-silent option. Do you know how to make this change to work for every MIME type opened with vim? Changing one by one is a daunting task! I opened /etc/mime.types but I see no vim in there (to do some sort of find and replace). I see a lot of mime named files all over the system and not sure which ones are relevant.
    – luchonacho
    Commented Sep 21, 2017 at 10:18
  • @luchonacho You may try to create a custom .desktop file for Vim (maybe in ~/.local/share/applications/my_gvim.desktop). Then find and edit a mimeapps.list file in your home directory (maybe ~/.config/mimeapps.list). I edited the answer to suggest a method, but I don't know if it will work for you.
    – user852573
    Commented Sep 21, 2017 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.