Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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