iTerm integration

202 views
Skip to first unread message

Jeff Zemla

unread,
Jan 26, 2015, 12:19:39 PM1/26/15
to vim-r-...@googlegroups.com
I just installed the plugin and am trying to get it working with iTerm2. I would like to do split-pane in iTerm and have vim on one side and R on the other.

By default, \rf is opening in Terminal. I have tried all of these in my ~/.vimrc with no luck:

let vimrplugin_term = "iterm"
let vimrplugin_term = "/Applications/iTerm.app/Contents/MacOS/iTerm"
let vimrplugin_term_cmd = "/Applications/iTerm.app/Contents/MacOS/iTerm -t R"

It still opens up R in a new Terminal window. Additionally, when the Terminal does start, it says:

vimcom: Did you pass the --servername argument to Vim?

I don't know if this is related, though I would like to fix both issues. I am starting vim with "vim --servername VIM script.r" and have compiled vimcom with "enable-clientserver" (5.9 in FAQ). If I open my file in mvim, I *do not* get the vimcom error (but it still opens in Terminal).

Any idea what's causing trouble?

Thanks!

Details:
mac os x 10.9.5
vim 7.4
macvim installed, but +clientserver, +conceal, +libcall
iTerm 2.0.0.20141103

Jeff Zemla

unread,
Jan 26, 2015, 1:45:48 PM1/26/15
to vim-r-...@googlegroups.com
I was able to fix the latter problem by compiling vim with X11 support (sudo port install vim +x11, re-direct "vim" command to this binary)

Still opening in Terminal though...

Jakson Alves de Aquino

unread,
Jan 26, 2015, 2:16:38 PM1/26/15
to vim-r-...@googlegroups.com
HI,

On OS X, the plugin writes a shell script called "openR" that runs Tmux which runs R. The script is generated at runtime and looks like this:

#!/bin/sh
tmux
-2 -f /path/to/tmux.conf new-session -s Vim-R R --no-save

Then, the plugin runs the following command:

open openR

That is, OS X chooses what terminal emulator it will run openR in. Can you set iTerm as the default terminal emulator? I guess that if you can do this, the "open" command will open iTerm instead of Terminal.

I added the following note to section 6.1 of the plugin's documentation (Vim-R-plugin version 1.2):

Note: The options of this section are ignored on Mac OS X, where the command
open is called to run the default application used to run shell scripts.

Jakson Alves de Aquino

unread,
Jan 26, 2015, 2:55:32 PM1/26/15
to vim-r-...@googlegroups.com
If you want R and Vim in the same window, do this in iTerm:

tmux
vim
--servername VIM script.R


Then, start R with <LocalLeader>rf.

Jeff Zemla

unread,
Jan 26, 2015, 3:12:49 PM1/26/15
to vim-r-...@googlegroups.com
Got it working, thanks Jakson! This plugin looks great!

I had already set tmux and ".sh" files to open in iTerm-- I didn't realize, but it's also possible to set iTerm as the default app for files with no extension. (For future readers-- Go to Default Apps in System Preferences, find iTerm under Apps, and check "public.unix-executable" under UTIs and hit "Set As Default").

I had already tried your other solution-- start tmux before vim-- but unfortunately that's not quite ideal. Among other things, the panes do not operate the same way as iTerm panes, and it completely ignores my vim color preferences. It is functional though.

Cheers

Jakson Alves de Aquino

unread,
Jan 26, 2015, 3:33:00 PM1/26/15
to vim-r-...@googlegroups.com
About the colors, the problem is that the following happens:
  1. When you start an terminal emulator, the TERM environment variable usually is "xterm", and Vim uses this value to enable 256 colors.
  2. When you start Tmux, the TERM environment variable becomes "screen", and Vim does not know whether the terminal is capable of displaying 256 colors or not and it defaults to use only 16 colors.
The solution is to somewhat set the value TERM=screen-256color. I do this with the following code in my ~/.bashrc:

if [ "$TERM" = "xterm" ] || [ "$TERM" = "xterm-256color" ]
then
   
export TERM=xterm-256color
   
export HAS_256_COLORS=yes
fi
if [ "$TERM" = "screen" ] && [ "$HAS_256_COLORS" = "yes" ]
then
   
export TERM=screen-256color
fi

What the code above does is:
  1. If TERM is xterm, it sets the value of HAS_256_COLORS to "yes".
  2. If TERM is "screen" and HAS_256_COLORS is "yes", it sets the value of TERM to "screen-256color"
Reply all
Reply to author
Forward
0 new messages