0

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 ?..

1
  • 1
    You may want to consider using Vim's multiple buffers, tabs, and Vim's ability to act as a 'server'.
    – demure
    May 15, 2013 at 11:25

1 Answer 1

0

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

You must log in to answer this question.

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