Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When i work on many files with screen and vim, often i try to open a file already open..

I must switch manually between screen windows witch ctrl-space and press ctrl-g until i find the right window.

Is it possible to switch automatically to the right window ?..

share|improve this question
1  
You may want to consider using Vim's multiple buffers, tabs, and Vim's ability to act as a 'server'. – demure May 15 '13 at 11:25

Use this /usr/local/bin/vi:

#!/bin/sh
VIM_PPID=$(ps -Af | grep " vim $1\$" | head -n 1 | awk '{print $3}')
if [ -n "$VIM_PPID" ] ; then
  _WINDOW=$(tr '\0' '\n' < /proc/$VIM_PPID/environ | grep ^WINDOW= | cut -f 2 -d '=')
  VIMSHELL_PPID=$(ps -Af | awk '/^[^ ]+ +'$VIM_PPID' +/{print $3}')
  MYSHELL_PPID=$(ps -Af | awk '/^[^ ]+ +'$PPID' +/{print $3}')
  if [ "$MYSHELL_PPID" = "$VIMSHELL_PPID" ] ; then
    screen -X select $_WINDOW
    exit
  fi
fi
exec /usr/bin/vim $@

Thanks to this reply

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .