diff --git a/zsh_custom/plugins/vim-interaction/README.md b/zsh_custom/plugins/vim-interaction/README.md index 6816480..68be753 100644 --- a/zsh_custom/plugins/vim-interaction/README.md +++ b/zsh_custom/plugins/vim-interaction/README.md @@ -25,19 +25,31 @@ There are a few aliases presented as well: * `vvsp` Edits the passed in file but first makes a vertical split * `vhsp` Edits the passed in file but first makes a horizontal split +## Pre Callout ## + +At the start of the `callvim` function we invoke the `preCallVim` function if it +exists. You could define a function that starts GVim/MacVim if not started yet + + function preCallVim + { + PID=`ps -A | grep gvim` + if [ -z $PID ]; then + gvim + # wait until gvim starts so --remote-send works + while [ -z "`ps -A | grep gvim`" ]; do; done; + fi + } + ## Post Callout ## At the end of the `callvim` function we invoke the `postCallVim` function if it -exists. If you're using MacVim, for example, you could define a function that -brings window focus to it after the file is loaded: +exists. You could define a function that brings window focus after the file is loaded: function postCallVim { - osascript -e 'tell application "MacVim" to activate' + gvim --remote-send ":call foreground()" } -This'll be different depending on your OS / Window Manager. - ## Examples ## This will load `/tmp/myfile.scala` into the running GVim session: diff --git a/zsh_custom/plugins/vim-interaction/vim-interaction.plugin.zsh b/zsh_custom/plugins/vim-interaction/vim-interaction.plugin.zsh index 3785d3b..7b6c427 100644 --- a/zsh_custom/plugins/vim-interaction/vim-interaction.plugin.zsh +++ b/zsh_custom/plugins/vim-interaction/vim-interaction.plugin.zsh @@ -28,7 +28,9 @@ usage: callvim [-b cmd] [-a cmd] [file ... fileN] EOH return 0 fi - + if typeset -f preCallVim > /dev/null; then + preCallVim + fi local cmd="" local toNormal="" local before=""