Tuesday, May 21, 2013

vim taking focus

This happens on quite a few linux windows managers but I'm not
discounting something outside of vim being at fault here - vim is the
only place I've experienced this.

I have a gvim session with:
gvim --servername $USER
and then I load new files with:
vim --servername $USER
and gvim will pop up into focus but generally my cursor will stay on
the command line.

I thought I had asked this before, so I googled and found quite a few
(not my) posts:
http://objectmix.com/editors/149356-gvim-window-not-given-focus-when-loading-file.html
http://vim.1045645.n5.nabble.com/raising-gvim-window-to-front-td1169442.html
https://groups.google.com/forum/#!msg/vim_use/r4NKUumRrqE/rZN3U-Xv5ZsJ
http://mail.xfce.org/pipermail/xfce/2006-January/016091.html
--remote-tab <file>

Also (might be a different issue) - when I open a file and a file has
changed (the one I'm opening or one in another tab) like after a git
checkout and vim is confused and asks me what to do, vim won't
maintain focus after I deal with the dialog.

If none of this is clear or reproducable, I'll look into a perltk test case.

I have a script in my zshrc to automate this:
# make vim use or initialize a session with a new tab unless...
# alias this so that we can do \vim to get to the exe
vimfunc () {
local cmd
local servername
local remote
local misc
local version

local username=$(echo $USER | tr "[:lower:]" "[:upper:]")

local opt_ex="^-"

while [ $# -gt 0 ] ; do
case "$1" in
--servername)
if [[ $2 =~ $opt_ex ]] ; then
echo "Servername option without a parameter. Doing nothing."
return
else
servername="$2"
shift
fi
;;
--remote*)
if [ -z $remote ] ; then
if [[ $2 =~ $opt_ex ]] ; then
remote="$1"
else
remote="$1 $2"
shift
fi
else
# I'll deal with this properly if it is reasonable
to take multiple --remote* things
echo "Should not call two remote options at once.
Doing nothing."
return
fi
;;
--version*)
version="1"
;;
*)
misc="$misc $1"
;;
esac
shift
done

cmd="vim"

if [ ! -z $servername ] ; then
cmd="$cmd --servername $servername"
else
cmd="$cmd --servername $username"
fi

if [ -z $misc ] && [ -z $remote ] ; then
# list version if we asked for that
if [ ! -z version ] ; then
cmd="$cmd --version"
fi

${=cmd}
return
fi

if [ ! -z $remote ] ; then
cmd="$cmd $remote $misc"
else
cmd="$cmd --remote-tab $misc"
fi

echo $cmd
${=cmd}
return
}

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment