Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: import selected text #78

Open
nvk opened this issue Feb 20, 2018 · 12 comments
Open

Feature Request: import selected text #78

nvk opened this issue Feb 20, 2018 · 12 comments

Comments

@nvk
Copy link

nvk commented Feb 20, 2018

I'm not sure if Automator can do this. But would be great if there was a condition for any selected text to be brought in to vim for editing.

@99arobe
Copy link

99arobe commented Feb 20, 2018

I'd love this too.

@d1egoaz
Copy link

d1egoaz commented Feb 21, 2018

I did something on my branch, not sure if it will worth it to bring it here, as it'll affect the clipboard contents. (you'll lose your current clipboard content). I haven't found an easy way to do this (I could temporarily copy the current clipboard content to a file and restore it at the end.... <- I might try this idea later)
anyways, this is what I did:

https://github.com/d1egoaz/vim-anywhere/blob/634c9d58bb9c524cf5cf7376a583c25b77207875/bin/run#L90-L92

you could see it in action on the demo gif here: https://github.com/d1egoaz/vim-anywhere/

  osascript -e 'tell application "System Events" to set the clipboard to ""'
  osascript -e 'tell application "System Events" to keystroke "c" using command down'
  pbpaste >> $TMPFILE

@balta2ar
Copy link

I'm interested in Linux version of this.

@99arobe
Copy link

99arobe commented Feb 24, 2018

@d1egoaz Thanks for this!

You mention that you thought about saving the clipboard contents to a file temporarily. Would it also be feasible in AppleScript to just store them in a variable and then copy them back to the clipboard once the selected contents have been pasted?

@cspeterson
Copy link

@balta2ar I was too, but realized that with all the different manners of interaction with text selections and different window managers, etc that stepping it back to just using clipboard contents was the more reasonable solution not only for Linux but across platforms

I submitted a pull request to do this:
#99

@d1egoaz
Copy link

d1egoaz commented Aug 1, 2019

@99arobe yeah, that will work! that's a better idea actually

@st-schneider
Copy link

I did something on my branch, not sure if it will worth it to bring it here, as it'll affect the clipboard contents. (you'll lose your current clipboard content). I haven't found an easy way to do this (I could temporarily copy the current clipboard content to a file and restore it at the end.... <- I might try this idea later)
anyways, this is what I did:

d1egoaz/vim-anywhere:bin/run@634c9d5#L90-L92

you could see it in action on the demo gif here: d1egoaz/vim-anywhere

  osascript -e 'tell application "System Events" to set the clipboard to ""'
  osascript -e 'tell application "System Events" to keystroke "c" using command down'
  pbpaste >> $TMPFILE

That did the trick for me.
😨 you, you used emacs in your link 😜

@d1egoaz
Copy link

d1egoaz commented Sep 3, 2019

😨 you, you used emacs in your link 😜

lol 😈

@rwmitchell
Copy link

I had used Vim-Anywhere some time ago and then kinda forgot about it. When trying it again now, was disappointed vim was opening with an empty buffer (OS X). I made a simple change to bin/run and now get the current clipboard:

` *** bin/run.1586528512 2020-04-10 10:21:52.000000000 -0400
--- bin/run 2020-06-18 10:54:18.000000000 -0400
*************** elif [[ $OSTYPE == "arwin" ]]; then
*** 72,77 ****
--- 72,79 ----
"mvim must have been moved or uninstalled.\nPlease make sure it is"
"available in your path and then reinstall vim-anywhere."

  • pbpaste >> $TMPFILE
  • $mvim_path $VIM_OPTS $TMPFILE`

Is there a better/more clever way to do this?

[ my pasted code is getting munged, I only inserted the pbpaste line just before invoking mvim]

@cspeterson
Copy link

@rwmitchell

that's v close to what I did in PR #99 🙂

been a minute though, and still no movement 😞

@rwmitchell
Copy link

To be clear, with my one line change, prior to using:
v to invoke vim-anywhere,

I first use c to copy the highlighted text into the paste buffer.

Every place I use this, I initially get a pop-up window asking if
I want to allow this. Sometimes 2. Safari, then iTerm2.

The other fix I saw for this required using newer/different version of
emacsclient than is found in /usr/bin

Ideally it would be great to not need to manually copy the highlighted
text into the paste buffer. Certainly there is a way to combine two
keyboard shortcuts?

@cspeterson
Copy link

I have no familiarity with MacOS, so I have no idea what one might do about clipboard permissions or what any of that really even means.

But if I understand you correctly at the end there, you're wondering how to automagically pull a GUI text selection?

I think that would likely be beyond the scope of vim-anywhere and I expect would not even be practically possible to do well across all the supported operating systems.

The ugly duct tape way that comes to mind though on Linux would be to wrap vim-anywhere to use xdotool or equivalent to send ctrl+c (or whatever combo will copy things) as key events before launching vim-anywhere with clipboard reading functionality. Maybe there is an xdotool-equivalentish utility on Mac?

It's an inelegant and fragile solution, and I wouldn't bother with it, but if you're really hurting for that behavior you might give something like it a go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants