JohnBeckett (talk | contribs) (Clarify wording and fix typos) |
(Change <tt> to <code>, perhaps also minor tweak.) |
||
(6 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{TipNew |
||
− | {{TipProposed |
||
− | |id= |
+ | |id=1552 |
− | |previous= |
+ | |previous=1551 |
− | |next= |
+ | |next=1553 |
− | |created= |
+ | |created=2008 |
|complexity=basic |
|complexity=basic |
||
|author=MagnusBerg |
|author=MagnusBerg |
||
|version=7.0 |
|version=7.0 |
||
|subpage=/200804 |
|subpage=/200804 |
||
⚫ | |||
+ | |category2=Tabs |
||
}} |
}} |
||
Here is how to open files in new tabs, instead of new instances of gvim, under Unix. It works even when you mouse click to open files in a file manager. |
Here is how to open files in new tabs, instead of new instances of gvim, under Unix. It works even when you mouse click to open files in a file manager. |
||
+ | ==Desktop entry== |
||
− | In the < |
+ | In the <code>gvim.desktop</code> desktop file (<code>/usr/share/applications/</code> for most GNU/Linux systems) look for the "Exec" line. It will probably be like this: |
<pre>Exec=gvim -f %F</pre> |
<pre>Exec=gvim -f %F</pre> |
||
− | |||
⚫ | |||
Change the Exec line to: |
Change the Exec line to: |
||
<pre>Exec=gvim -p --remote-tab-silent %F</pre> |
<pre>Exec=gvim -p --remote-tab-silent %F</pre> |
||
+ | You may also need to change the StartupNotify value to "false" if it is currently set "true", or your [http://groups.google.com/group/vim_use/browse_thread/thread/900bd471bc11a423 Vim may not respond properly when the file is already open in a tab]. |
||
− | And in your [[vimrc]] add: |
||
+ | |||
− | <pre>tab all</pre> |
||
⚫ | |||
+ | |||
+ | ==alias== |
||
+ | You can of course also use an <code>alias</code>: |
||
+ | <pre>% alias gvim 'gvim -p --remote-tab-silent'</pre> |
||
+ | |||
+ | Most GUI programs don't read aliases, but it is useful if you start gvim from the shell. |
||
+ | |||
+ | ==Automatic desktop identification using shell script== |
||
+ | |||
+ | If you want to automatically open into the gvim window on the current desktop, use the following bash script: |
||
+ | |||
+ | <pre> |
||
+ | #!/bin/bash |
||
+ | |||
+ | this=$(basename $0); # vim|gvim|rvim etc... |
||
+ | desktop=desktop_$(xprop -root -notype _NET_CURRENT_DESKTOP | perl -pe 's/.*?= (\d+)/$1/') |
||
+ | |||
+ | if [ $# != 0 ]; then |
||
+ | exec /usr/bin/$this --servername $desktop --remote-tab-silent "$@" |
||
+ | elif ! vim --serverlist | grep -iq $desktop; then |
||
+ | exec /usr/bin/$this --servername $desktop |
||
+ | fi |
||
+ | </pre> |
||
+ | |||
+ | (script originally from https://gist.github.com/966205) |
||
+ | |||
+ | Save this bash script as /usr/local/bin/gvim to override the global Vim installation, which it will call into (assuming your global installation is in /usr/bin). |
||
+ | |||
+ | The script queries the X server for the current desktop, queries Vim for running Vim instances with --serverlist. 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. If no file was given and gvim is already running on the desktop, the script does nothing. |
||
+ | |||
==See also== |
==See also== |
||
Line 26: | Line 58: | ||
==Comments== |
==Comments== |
||
− | [[Category:Tabs]] |
||
⚫ |
Revision as of 06:32, 13 July 2012
created 2008 · complexity basic · author MagnusBerg · version 7.0
Here is how to open files in new tabs, instead of new instances of gvim, under Unix. It works even when you mouse click to open files in a file manager.
Desktop entry
In the gvim.desktop
desktop file (/usr/share/applications/
for most GNU/Linux systems) look for the "Exec" line. It will probably be like this:
Exec=gvim -f %F
Change the Exec line to:
Exec=gvim -p --remote-tab-silent %F
You may also need to change the StartupNotify value to "false" if it is currently set "true", or your Vim may not respond properly when the file is already open in a tab.
Note: Be aware that the desktop file is changed when you install a new version of gvim, so you may need to repeat the following change after an update.
alias
You can of course also use an alias
:
% alias gvim 'gvim -p --remote-tab-silent'
Most GUI programs don't read aliases, but it is useful if you start gvim from the shell.
Automatic desktop identification using shell script
If you want to automatically open into the gvim window on the current desktop, use the following bash script:
#!/bin/bash this=$(basename $0); # vim|gvim|rvim etc... desktop=desktop_$(xprop -root -notype _NET_CURRENT_DESKTOP | perl -pe 's/.*?= (\d+)/$1/') if [ $# != 0 ]; then exec /usr/bin/$this --servername $desktop --remote-tab-silent "$@" elif ! vim --serverlist | grep -iq $desktop; then exec /usr/bin/$this --servername $desktop fi
(script originally from https://gist.github.com/966205)
Save this bash script as /usr/local/bin/gvim to override the global Vim installation, which it will call into (assuming your global installation is in /usr/bin).
The script queries the X server for the current desktop, queries Vim for running Vim instances with --serverlist. 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. If no file was given and gvim is already running on the desktop, the script does nothing.