cknadler / vim-anywhere

Use Vim everywhere you've always wanted to
MIT License
3.65k stars 147 forks source link

Support without gvim. #89

Open hobbestigrou opened 6 years ago

hobbestigrou commented 6 years ago

First thanks for your project it's great. Just know if it possible to add a support without gvim. I don't want to need install gvim for use your project.

austinglaser commented 6 years ago

Totally on the same page.

What about a .vim-anywhere/config file which allows you to specify the command to start vim, among other future things? This could default to just gvim, but could also be set to something like (in my case), termite -e nvim.

Other things that would have to change:

I may have some time to open a pull request this weekend...

hobbestigrou commented 6 years ago

I'm happy to see I'm not alone. If you have the time to make that is awesome, I have not the time at the moment.

malob commented 6 years ago

@austinglaser, that would be great since that would allow me to easily use nvim.

Dbz commented 6 years ago

And regular vim for folks like me

austinglaser commented 6 years ago

Never got around to adding features properly. However, I've been using the following patch, which seems to work reasonably:

 bin/run | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/bin/run b/bin/run
index 804a137037a3..2c5abf1f77ec 100755
--- a/bin/run
+++ b/bin/run
@@ -38,7 +38,7 @@ done
 AW_PATH=$HOME/.vim-anywhere
 TMPFILE_DIR=/tmp/vim-anywhere
 TMPFILE=$TMPFILE_DIR/doc-$(date +"%y%m%d%H%M%S")
-VIM_OPTS=--nofork
+#VIM_OPTS=--nofork

 # Use ~/.gvimrc.min or ~/.vimrc.min if one exists
 VIMRC_PATH=($HOME/.gvimrc.min $HOME/.vimrc.min)
@@ -56,7 +56,7 @@ touch $TMPFILE
 # Linux
 if [[ $OSTYPE == "linux-gnu" ]]; then
   chmod o-r $TMPFILE # Make file only readable by you
-  gvim $VIM_OPTS $TMPFILE
+  termite -e "nvim $TMPFILE"
   cat $TMPFILE | xclip -selection clipboard

 # OSX
Dbz commented 6 years ago

Do you have an idea on how to do this with OSX+iterm2?. I've been experimenting with osascript, and I have a workable solution:

bin/run

  frontmost_app="~/.vim-anywhere/script/set_frontmost_app.scpt"
  osascript <<EOF
    tell application "iTerm"
        create window with default profile
        tell current session of current window
               activate
                        write text "vim -c 'execute \"au VimLeave * !pbcopy < \" . expand(\"%\") | execute \"au VimLeave * !osascript $frontmost_app $app\"' $TMPFILE"
        end tell
    end tell
EOF

script/set_frontmost_app.scpt

on run argv
  tell application "System Events"
    set frontmost of the first process whose unix id is (item 1 of argv) to true
  end tell
end run

script/current_app.scpt

-- vim-anywhere - use Vim whenever, wherever
-- Author: Chris Knadler
-- Homepage: https://www.github.com/cknadler/vim-anywhere
--
-- Get the current application's name

tell application "System Events"
  copy (unix id of application processes whose frontmost is true) to stdout
end tell
Dbz commented 6 years ago

I updated the above script to work fully. I also forked and committed it here: https://github.com/Dbz/vim-anywhere

tthkbw commented 2 years ago

When I use these scripts, the iterm window is left open after running vim (or nvim, which I use). Is there a way to close the iterm window when vim is done?

nnnell commented 12 months ago

@tthkbw I ran into the same thing, and setting up one last VimLeave autocommand to exit the window does the trick!

write text "xnvim -c 'execute \"au VimLeave * !pbcopy < \" . expand(\"%\") | execute \"au VimLeave * !osascript $frontmost_app $app\" | execute \"au VimLeave * !exit\"' $TMPFILE"

(it kind of feels like one of those things that shouldn't work, and yet)

Edit: The feeling was true. This no longer works for me.