Hacker News new | past | comments | ask | show | jobs | submit login
Vim Anywhere (github.com/cknadler)
368 points by jstrieb on Feb 16, 2018 | hide | past | favorite | 156 comments

I have an Automator workflow script, which uses emacsclient to edit any text, in my `~/Library/Services`. The service receives selected text in any application and output replaces the selected text. It consists of two parts: Run AppleScript, and Run Shell Script.

The AppleScript part is:

    on run {input, parameters}	
    	tell application "EmacsMac" to activate
    	tell application "System Events"
    		repeat until visible of process "Emacs" is true
    			delay 0.5
    		end repeat
    	end tell
    	return input
    end run
and the Shell Script part (pass input to stdin) is:

    tmp=$(mktemp "$HOME/tmp/EditTextinEmacsXXXXXXXX")
    cat > "$tmp"
    until [ $($ec -q -e '(server-running-p)' 2>/dev/null) == t ]; do
      sleep 1
    $ec -q -c "$tmp"
    cat "$tmp"
    if [ $rv -ne 0 ]; then
      echo "Something went wrong.  Please find your text in"
      echo "$tmp"
      rm "$tmp"
Getting it to work with any editor should be straightforward.

Wow, this is awesome!

Is there any way to make it work without selecting text? (default to all available text on the textarea)

BTW, I changed a few things: emacsclient path and the tmp folder:

  tmp=$(mktemp "/tmp/EditTextinEmacsXXXXXXXX")
  cat > "$tmp"
  until [ $($ec -q -e '(server-running-p)' 2>/dev/null) == t ]; do
    sleep 1
  $ec -q -c "$tmp"
  cat "$tmp"
  if [ $rv -ne 0 ]; then
    echo "Something went wrong.  Please find your text in"
    echo "$tmp"
    rm "$tmp"

I ended forking and creating this https://github.com/d1egoaz/vim-anywhere WIP

Hmm... I'm not very familiar with this, but couldn't you send a key command to select the entire text (CMD A)?

I'm not very familiar either. But the Automator workflow starts with "receives selected text", so I'm not sure it has access to the current text field

Did not know that. I've used HammerSpoon on Mac, and you can send key shortcuts with that... you could probably glue them together easily

osascript is our friend

    osascript -e 'tell application "System Events" to keystroke "a" using command down'

why not "mktemp -t EditTextinEmacs". This will touch a file in $TMPDIR which is more safe than /tmp.

Maybe I'm just not _getting it_ and am too old for this, but why would I ever want to have my computer open a completely different program simply to input text into a text box when it already has focus and I can simply type at that point?

I understand using vim for development, or editing files while already at a command prompt; I just don't see the point in this use case other than to feel clever.

I am willing to be enlightened if I'm missing something.

I don't know if it's as applicable for a vim user, but as an emacs user I really appreciate having access to the same tools I use to edit all of my other text: the same search, the same dictionary, the same completion engine, the same Org-mode keybindings (so that I can save myself a note or TODO as I'm in the middle of writing), the same … everything.

Honestly, every programme other than emacs is a distraction.

I’m a Vim user but this exactly nails the point. I mostly use the terminal for everything I can because I know the shortcuts and they’re consistent across operating systems.

For all its faults, readline is a godsend for Vi users.

If you're not a heavy Vim user you may not understand but the only way I can describe it is that Vim is different enough that it makes you forget how to edit text the "normal" way. One example is that Vim doesn't require arrow keys, so having to use arrows to navigate text in a normal editor is a huge pain.

And hjkl is not the arrow keys' replacement, as many non-users think.

There are a hundred other ways to move around a file, each of which are more efficient than hitting a button ten times. Those kinds of things are what makes Vim convenient (though not having to move your hand to the arrow keys for going one line down is pretty convenient, too).

I'm a Vim fan, but that's a little disingenuous.

Ordinary text editors have ctrl-left and ctrl-right, which are equivalent to Vim's w and b. They also have Home/End and ctrl-f.

But w and b are not the end of vi's (let alone vim's/neovim's + plugins') motions.

Sure, but it's not often I win big by using Vim's advanced movement commands.

One of the most useful Vim motions for me has been repeating j / k for n times, e.g using 12j to jump down 12 lines.

Combined with relative line numbers (to show how many lines to jump up / down) this has been a really big win for me to navigate around text.

Shift-G / gg are “big” wins for me on a fairly regular basis.

That's a good example, but I suspect most editors/IDEs have their own equivalent shortcuts.

Apparently in Visual Studio it's SHIFT+CTRL+HOME.

Not all keyboards have a home key and the vast majority have a shift/g key, but yes, i agree.

you don't use `)` or any other object motion? You should (consider)! `:help object-motions`

I probably wouldn't use this either, but I can see how it can be helpful. If you do a lot of posts on Stackoverflow, you can get some markdown+code highlighting. People use to Vim can use all it's fancy searching and jumping to specific points of text. You can do regex replaces.

Basically if you want a powerful editor just in case when you're filling out a form or something else, here you go?

I'm a sublime user but I find myself accidentally using keyboard shortcuts when doing things such as:

- Writing emails in gmail

- Replying to instant messages

- Writing answers on stack overflow

- Filling out web forms

This is mostly for multiple cursors which are now ingrained in how I type. I'll often copy text to sublime and then copy it back so having a automated way of doing this doesn't seem crazy to me anymore (it would have done 5 years ago).

Some keybindings are ingrained. I use Quail and Electric quotes all the time in Emacs (modes which modify the letters you input), and I write lots of prose in Emacs, so using Ctrl-q <char> to "quote" a character to input it literally is something I frequently do. It happens that sometimes I do that out of muscle memory in Firefox, and Ctrl-q quits in Firefox. Or you press Ctrl-n for next line a couple times but you get some new blank windows instead. I confuse Ctrl-f and Ctrl-s all the time. Many other bindings are easily confusable.

I'd actually like Firefox to be customisable instead of a hack like this. I'll probably just switch to the Next browser [1] in the future though.

[1] https://github.com/nEXT-Browser/nEXT

It makes a lot of sense for big pieces of text. Heavy vim users are super fast navigating trough text.

I can easily see the benefits of using this to write a long blog/fb post.

The reason I don't see the benefit is that, if a piece of text is long enough that I prefer using vim over just typing in the text box, then I probably want to actually save a copy to disk in case clicking "submit" doesn't go through. So I might as well actually use vim at that point.

That's how it works (worked) with It's All Text! extension for Firefox: you set an editor (`gvim -f' in my case) and on a keybinding it's started with a file as its argument. Text area gets updated on write to the file.

Normally you don't need to see or worry about the intermediate files, but in case anything goes awry, you still have the option.

I'm looking forward to using this for writing JIRA tickets. Their text boxes override some mac key bindings that are deep in my muscle memory. Want move back a space? Oops, ctrl-b in this text box makes text bold. Jump to the start of the line, well ctrl-a now inserts a link. There's something just so annoying about that, it makes me bristle at using jira in general.

>... simply to input text into a text box ...

Vim (and other editors) offer powerful editing macros that ease bulk text operations. Simple things like text substitution across hundreds of lines save so much time. I still use https://github.com/docwhat/itsalltext running on https://www.waterfoxproject.org/ which allows textarea editing from the terminal.

It's not vim, but many terminal-based keyboard shortcuts are already available across OS X without installing anything. For example:

    - ctrl+p - move cursor up one line
    - ctrl+n - move cursor down one line
    - ctrl+f - move cursor forward one character
    - ctrl+b - move cursor back one character

    - ctrl+a - move cursor to beginning of line
    - ctrl+e - move cursor to end of line
    - ctrl+k - delete all characters from cursor to end of line
There are a few missing useful ones (such as move by word), but you can fill them in by creating this file[1] in a specific place on your machine.

[1] https://gist.github.com/gilbert/10fdd692799fc7269b50abbcfb2e...

These are Emacs shortcuts, not Vim. They're available in bash (the default MacOS shell) because bash uses the readline library. You can also put readline into Vi mode and use Vi/Vim shortcuts, but none of this has anything to do with editing files.

> but none of this has anything to do with editing files.

Why not? You can use these shortcuts across OS X. That includes your web browser and any other GUI you have on your machine (I use them heavily in notational velocity).

They work anywhere there's a system-provided text field.

fish shell has a vim mode for anyone interested

This is actually a readline thing, so you can edit your $HOME/.inputrc with

   set editing-mode vi
and get the vi bindings in everything that supports readline, e.g. the Python shell etc. There's tons more that can be customized here. You can even have it put the current vi mode in your prompt and stuff like that.


Bash and zsh also have vim mode. The bash mode is more like vi though.

Indeed, it’s in fact called “vi mode” in the bash/readline docs.

1. I think this is for the people who want more than just a couple vi-like motion keys.

2. Five of your seven shortcuts are for emacs[0], not vim.

[0]: https://www.gnu.org/software/bash/manual/html_node/Command-L...

Right, I just thought it was interesting enough to point out how there are many navigation shortcuts that are built into OS X. Useful even when you're using someone else's computer.

All seven are default keybindings in Emacs. Which two did you believe weren't?

I believe ctrl-n and ctrl-p work in vim

Oh, I see. I had forgotten that. They do also work in Emacs and I wouldn't be surprised to learn that their use in Emacs predates Vim.

I’m not sure when Vi[m] got ctrl n/p, but it looks like emacs got it WAY early on: http://ergoemacs.org/emacs/emacs_kb_shortcuts_pain.html

I've been using those commands in Emacs since the late 70s

Those are emacs-based shortcuts.

They are also the default in most shells (bash/zsh), which also have optional vi-based bindings.

Those OS X keybindings come from Emacs! I bet some vimmers would refuse to use them just on principle. :)

I'm a vimmer and always use readline bindings in "insert" mode context. I find using vim bindings on the commandline to be infuriating.

On macOS, you need to add the following to $HOME/Library/KeyBindings/DefaultKeyBinding.dict to get ctrl-w and ctrl-u to work everywhere in macOS.

{ "^w" = "deleteWordBackward:"; "^u" = "deleteToBeginningOfLine:"; }

> I find using vim bindings on the commandline to be infuriating.

Some folks find vim bindings to be just as bad to edit text grin

I don't actually agree: I think that vim's text-editing language is actually nicer than emacs's is. But I use emacs — with its bindings, not vim's — because after almost thirty years it's what I'm used to.

Haha, I've never been interested in the whole vim vs. emacs thing. I just started with vim and a little too invested in it now. It definitely drives me nuts that it loads entire files into memory and that is the one thing that has made me tempted to switch. It rarely affects me but every once in a while when I accidentally open a massive file in vim and have to wait, I dream of emacs. I would use evil mode, OF COURSE :)

Oh, if you like those bindings in insert mode, you are probably already aware of Tim Pope's vim-rsi [1] plugin. If not, check it out, it might have some interesting bindings you aren't using yet.

[1] https://github.com/tpope/vim-rsi

I'm absolutely aware of it and was gonna mention it but figured I'd said enough :)

When I said "insert" I meant like, "insert mode" everywhere else but vim :)

But yes, RSI is a great plugin (as are most of tpope's plugins)

Also, you mentioning it made me realize I never starred the repo, so thanks, haha!

Thanks so much for this. I usually use Karabiner for the same thing.

Do you know anyway to get the same behaviour on Linux and Gnome at all?

I’m a heavy vim user and yet I add bindings to vim for Control-A and Control-E.

now that’s funny

Doesn’t Option-(Arrow Left|Arrow Right) move around per word?

You're right, but option+(f/b) is handier when combined with ctrl+(f/b)

Ok, but you can do this with a simple shell script without the reliance on Gnome/GTK:

  fn="$(date -Iseconds)"
  [ ! -d $dir ] && mkdir $dir
  vim $dir$fn && cat $dir$fn | xsel -b -i
Then you just need to bind the script to a key inside your window manager.

Bonus: This works anywhere xorg is available.

I use something like this but I initialize the file with the contents of the clipboard. I use xclip but I think xsel can do the same. Here's a snippet:

    xclip -o > "$tmpfile"    # initialize file with clipboard contents
    gvim --nofork "$tmpfile"
    xclip -i "$tmpfile"      # push file to clipboard
Bind it to a global hotkey and you can use it from anywhere.

Relevant self-plug: I co-wrote an extension that does this between browsers and several text editors, it’s called GhostText


It's fantastic! I use this every day and it works great. Thanks for the effort you put into it!

I love the idea! I often open up vim to edit some stuff, save it in a temp file, then copy it. I never realised I needed a more streamlined version but after seeing this it hit me like a brick.

I don't think I need that much scaffolding, though. I just knocked this together:

    vim /tmp/everyvim && cat /tmp/everyvim | xclip -sel clip -i

No Windows version, where I need it.

If you are used to Vim then regular editors are dangerous, you find things like '=aB' or 'jjjjj' or 'ZZ' or ':w!' embedded in one's files, breaking everythng.

On Windows you can't just copy and paste from something edited in a terminal, or copy paste to a terminal to do your editing/saving as there is no 'vi'.

I note this software could be upgraded to work with Windows now there is that Ubuntu subsystem in there somewhere. Perhaps a better way would be to modify the accessibility tools - StickyKeys etc. - to have vim be the universal text entry arrangement even for things like username text boxes, you ':wn' to get to the password field and then type 'i' to start entering a password. Much easier.

There are vim builds for Windows, both graphical and terminal. You don't need to use the linux subsystem for that.

Meanwhile, the Escape key on popular keyboards is getting smaller and smaller :(

Fun fact, Ctrl+[ also escapes. Had to retrain my muscle memory to use Ctrl+[ when I got my Touch Bar mac, but I think I actually prefer it to ESC. It's guaranteed to work on vim on any system (unlike caps lock), and it keeps my fingers closer to home row.

Hm... I was able to 'feel' the ESC key on my touch bar. But I then remapped it to Caps Lock using Karabiner. I also remapped it on my Ubuntu laptop (with Xmodmap) since it's so nice. What systems have you not been able to get it to work on?

Other people's (when pair programming)

The best line in my whole vimrc is this https://github.com/k0nserv/dotfiles/blob/master/files/vimrc..... It rebinds jk to ESC. This has the nice property of being a NOP if you happen do do it in normal mode

But what would it do in visual mode?

Nothing, but you could add a `vnoremap jk <Esc>` line as well to have it leave visual mode if you wanted.

I stil use ESC for visual mode, but as @Pete_D points out you could use jk there too, however it's a much more common input in visual mode so it would probably not work as well.

You can rebind caps lock to escape.

or rebind it to ctrl if held, escape if tapped, making it even better for RSI purposes

and enter to ctrl if held and enter if tapped ;) (macbooks don't have a right ctrl key).

Personally I prefer to use Karabiner-Elements to remap the right alt-key to ctrl. Been doing that since the first MacBook Pro when the key in that position was “Enter”.

I find I don’t really miss the right alt key at all.

And what a nightmare it is to jump on a macbook because of that. I go crazy when I need to use an Apple keyboard. I can't begin to understand that particular ui choice.

What do you use to do this? On what operating systems?

as the two other sibling posters said, I use karabiner elements when on os/x and xcape+xmodmap on Linux with this in my .xsession

  xcape -e 'Control_L=Escape'
which is run after remapping caps lock to Control_L via xmodmap (just xmodmap -pke to create your xmodmap file, xev to figure out which keycode your caps is, and edit the file after to make that keycode Control_L.

For example my xmodmap file, which also sets up meta/super and other overrides is

  ! Clear the modifiers
  clear    lock
  clear    shift
  clear    control
  clear    mod1
  clear    mod2
  clear    mod3
  clear    mod4
  clear    mod5
  ! Remapping
  keycode  37 = F17 NoSymbol F17
  keycode  64 = Alt_L NoSymbol Alt_L
  keycode  66 = Control_L NoSymbol Control_L
  keycode  90 = Multi_key NoSymbol Multi_key
  keycode  91 = Mode_switch NoSymbol Mode_switch
  keycode 105 = Meta_R NoSymbol Meta_R
  keycode 107 = Menu Sys_Req Menu Sys_Req
  keycode 108 = Control_R NoSymbol Control_R
  keycode 127 = Redo Undo Redo Undo
  keycode 134 = Alt_R NoSymbol Alt_R
  keycode 135 = Control_R NoSymbol Control_R
  keycode 164 = Undo Redo Undo
  keycode 166 = Super_L NoSymbol Super_L
  keycode 167 = Control_L NoSymbol Control_L
  ! Set the modifiers
  add shift   = Shift_L Shift_R
  add control = Control_L Control_R
  add mod1    = Alt_L Alt_R
  add mod2    = Num_Lock
  add mod3    = Super_L
  add mod4    = Meta_R
  add mod5    = Mode_switch

I use this app on Mac for the exact key mentioned above Caps -> Ctrl/Esc


If you are on Linux, try xcape; on Windows, you can do it with autohotkey.

Remapping CapsLock to Ctrl on Windows is easy with KeyTweak (what I have is 2.3.0 by Travis Krumsick), though I had to select the CapsLock key from the displayed keyboard rather than simply hitting the key. All it appears to be doing is updating the Registry's key mapping values based on the keyboard scan codes. Easily found with a simple search, and it does work on Windows 10 even though it hasn't been updated for 8+ years.

I suspect you'd have to switch to something like Autohotkey for the Esc/Ctrl mapping.

That's a good one!

Oh that’s interesting!

I already bound it to Ctrl.

I bound caps lock to ctrl. I use it with ctrl-[ to escape in vim. Does everything I need.

I've heard of some people rebinding Ctrl to Esc after doing that.

Or there's always dual binding Caps Lock (tapped vs held) as tetraodonpuffer suggested but I've never been able to get used to that.

I've gotten used to typing CTRL-[ instead of reaching for the Escape key because of the inconsistencies in its size and placement on various keyboards I use. Yes it's two fingers but you have to use CTRL in vim to get any benefit anyway.

Quite difficult to type CTRL-[ for me, as it's actually CTRL+ALT+8 on a german layout keyboard :/

Oh, and on Mac CTRL+ALT+5 if I remember correctly.

Have been using a US keyboard and never looked back to the Swiss one. Much better for programming and accents and umlauts are still easy to type. As I also occasionally type in Portuguese, German, Spanish, and French, I find the US keyboard to be the neutral middle ground.

On linux, I don't use ESC at all anymore, I just press alt + [a normal mode key], while in insert mode. Like `alt + j`, which will leave insert mode and move one line down.

Some alt based sequences are really useful:

* alt + e, a : leave current parenthesis and continue inserting (eg, while typing parameters for a function)

* alt + shift + a : insert mode at the end of current line

* alt + shift + i : insert mode at the beginning of current line, with indentation

* alt + p, a : paste before current position, and continue inserting

Maybe there's a modifier key with a similar behavior on macosx?

>On linux, I don't use ESC at all anymore, I just press alt + [a normal mode key], while in insert mode. Like `alt + j`, which will leave insert mode and move one line down.

Why does that work? Is it because Alt + some_key combos generate an escape sequence starting with the actual ESC character? I know that happens with many function key combos, don't remember or not sure about Alt combos.

This sounds plausible, but I have really no idea of why it works :) I found it by doing a mistype (like it often happens in vim), and didn't see it mentioned in any article that would try to get to the bottom of it yet.

>I found it by doing a mistype (like it often happens in vim)

Ha, I probably found it by some similar way, maybe in vim or maybe in DOS / Windows / Linux at the command prompt or in some curses or terminal application.

>* alt + shift + a : insert mode at the end of current line

Is that different from just Shift-a or capital A, which puts you into append mode at the end of the current line (no matter where you are on the line when you press it)?

yep, it does a 'A' in normal mode, after leaving the insert mode (thanks to alt). The different thing is that you do it (alt+shift+a) in insert mode. So the equivalent would be `ESC, A`.

Then I guess that the Alt key generates an ESC char (ASCII code 27 [1]). Seems to tie in with the fact that Emacs docs say that you can use either Alt or ESC for the Meta key - which is used a lot in Emacs commands (IIRC - I am not an Emacs user, just had tried it out earlier and think I remember reading read that).


I see. thanks for sharing!

Just use Ctrl-C instead of Escape. Often less hand-motion than going all the way to the upper-left, and it works everywhere, without custom remapping of Caps Lock, etc.

Here's one way to mitigate that: use a less popular keyboard. I suggest evaluating https://shop.keyboard.io/ for starters.

I love the idea of a mechanical keyboard but I worry about productivity when I’m on the move.

I find it easier to stick to the laptop keyboard and trackpad even when at a desk plugged into a big monitor.

Everytime I try to switch to a mechanical keyboard and mouse my wrists start hurting. I guess this would go if I got used to the position but then what would happen when I have to use the laptop keyboard?

(So far I’ve tried an IBM model-m and a Pok3r keyboard).

From my experience, my wrists start hurting if I don't use any wrist rests (despite the name, you're supposed to rest your palms on them) Also, tilted or high profile keyboards are less ergonomic IMHO.

Don't worry about switching back to the laptop keyboard on the go. You won't be less productive, you will just enjoy it less :)

On some laptops too :(

Very cool. I am using it now to write this comment!







please exit

help exit

ESC :wq should do the trick. (Yes, I know it's a joke)

Is there a way to exit without using the ":" key?

I ask because the other day I saw a friend of mine legitimately get stuck inside vim because he coundn't type ":". The keyboard language was set to the wrong language and none of the keys would output ":" when pressed. We had to reboot the machine and find a different keyboard.

ZZ will save and exit, or ZQ to exit without saving.

Ha ha, I don't know about nowadays on Windows/Linux/MacOS (maybe someone else can comment for that), but on DOS, you could get around such issues (like a key damaged or not present) by holding down the Alt key while entering the 1- to 3-digit ASCII code for the key you wanted to enter (0-255). That was used for all kinds of tricks and jokes in those days, like entering a fake space kind of key - some ASCII code while pressing Alt - I forget which one, maybe 255. It would look like the space char on the screen - a blank - but was not the same char. Could be used to create "hidden" files that those not in the know could not access, although the file was otherwise in plain sight in DIR listings and so on :)

Ctrl-Z to suspend and then you can kill the job

Yanking the power cord usually does the trick for me too.

Even after 1.5 years of using vi at work, I still constantly get stuck trying to exit. Like I hit Ctrl+C or something, or ZZ with caps lock off, I don't even know. Then it's like "Type :quit to exit" or "Entering video mode" or "Press Shift-something to capture" and I do this random button mashing of Escape and q and ZZ that eventually gets me out, but I never know what I did.

:x is a shortcut for :wq. I wonder why nobody knows it.

:x is not only a short for :wq - the latter saves (unconditionally, even if you have saved earlier and not edited since), and then quits (the file). I was going to say that :x is also a shortcut for :q (just quit) but it is of course not a shortcut for that, since it is the same length :)

I can better describe it like this:

:x is a shortcut for telling vi/vim: save the file if not saved after last change, then quit (in either case, whether a save was needed and done just now or not) - IIRC.

Also, as others said, Shift-ZZ (when Caps Lock is off), also saves and quits (and saves one keystroke over :x - because you have to hit Enter after :x, but not after Shift-ZZ :) It is also (slightly) faster to type, since the (left) Shift key is just next to the Z key (at least on some keyboards, like mine at present).

I've never used :wq, always :x. And I've been using vim for roughly 3 years.

Sorry, I’m pretty new to vim (switched from ST this week and loving it so far). Thanks for the advice though

Vimperator did that. Just miss it.

I like the idea, as I also want to write everything in Vim. But I (obviously) always have Vim running, and can get to it from anywhere with one keystroke. Once there, opening a buffer and copying its contents after writing stuff is just a few more keystrokes; so I don't see the need for this, at least for my setup--and I'm thinking that other hardcore Vim lovers have things set up similarly.

> But I (obviously) always have Vim running, and can get to it from anywhere with one keystroke. Once there, opening a buffer and copying its contents after writing stuff is just a few more keystrokes …

As an emacs user, I just love seeing vim-users discover the utility of an always-there, complete text-editing environment. If only theirs had an extension language worth its salt …

You can write vim extensions in python, Perl, ruby, lua and of course viml.

And vim launches in milliseconds, so no need to keep it running in the background as some text editing server.

Both true, but since I'm always editing something, I have it open in server mode so I can send a file to it for editing from the terminal.

i3 and ratpoison are tiled window managers for Linux that make your whole computer behave like vim does. If you really are interested in simplifying the amount of work you do- you should consider abandoning the normal "stacked cluttered windows" paradigm in exchange for something that requires less pointless mouse work to achieve the same amount of work faster.

Most monitors have enough real estate to where alt-tabbing is not only unecessary, but counter productive and distracting. Its like using your foot to operate the gas pedal 100% of the time instead of using cruise control to drive hours in a straight line.

What system? After writing to tmp, I pipe to pbcopy on Mac and pipe to xclip on Linux. I do this enough that installing this might be worth it.

Linux (ubuntu) using xfce. Always have one workspace devoted to a full-screen Vim window, so can get there with a keyboard shortcut. In my .vimrc, I have

    set clipboard=unnamedplus
so that yanked text is copied to the X11 clipboard. Yank buffer, switch back to browser (or what have you), paste. With Vimium, the whole procedure is mouseless.

pbcopy on Mac brings back memories.

Agreed. This is a clever little hack that I never would have thought of. But I usually have a "temp" or "scratch" buffer running for this kind of thing anyways.

It is cool that apple has the ability to script like this though. It's pretty handy.

Similar but only for the browser there is the "It's All Text!" Firefox Add-on. I used it for years, but unfortunately it stopped working recently when I upgraded to Firefox Quantum, so "Vim Anywhere" is a welcome alternative. Certainly will try it.

Check out GhostText: https://addons.mozilla.org/en-US/firefox/addon/ghosttext/

I use it with Atomic Chrome for Emacs, but it supports Vim, Sublime, and Atom as well.

This is why I'm still on Firefox 55. Fuck quantum. I used it a little on a different system and the slight speedup (main bottleneck is still WiFi/uplink) is nowhere near worth breaking all addons without even providing APIs to make replacements.

Here is the Emacs version for OS X (Emacs Anywhere, if you will). Just made it. Check it out at https://github.com/zachcurry/emacs-anywhere

A sort of similar effect can be achieved with iTerm's hotkey window.

I usually run an emacsclient inside tmux inside the hotkey window, with a scratch text-mode buffer active.

If I want to use emacs to work on some text from a non-emacs app, the steps are something like: select text, cmd-c, press hotkey (mine is option+space), ctrl-y, edit the text, select what I need, opt-w, press hotkey to switch back to the app, then cmd-v.

Since the hotkey window is running tmux, it's easy to create or switch to another tmux window and operate on the text with the help of pbpaste/pbcopy and good old pipe.

Does anybody know of a way to do something like this in X11? I appreciate that macs have very nice built-in automation framework, but I'm not abandoning Linux just for that. There's xdotool for typing, but I don't know of any way to grab text boxes.

I wrote a five line script for it here >> https://news.ycombinator.com/item?id=16398356

Not what I was thinking, but that works. Thanks

Perhaps I've missed the point here. Couldn't you set VISUAL to your editor of choice?

It's for things like web forms or other GUI apps, for whom $VISUAL is not meaningful.

A different tact (for some cases) to the same end: use elinks[0] and in an active <textarea>, press shift-ctrl-T to pop up your favourite editor[1]. This works for gmail, for example.

[0] https://en.wikipedia.org/wiki/ELinks

[1] https://en.wikipedia.org/wiki/Nvi

I can't recommend that. Elinks doesn't verify SSL certs when connecting to HTTPS sites. It hasn't had a release in five years. It also has worse support for web standards than IE6.

Huh, TIL. I think I actually don’t care about any of that except for the cert verification, which is a Big Deal. Thx for the reply!

Lynx doesn't have as good standard support, but it is still semi-active (2017-07-10 (2.8.9dev.16)) over at InvisibleIsland[0], and can be compiled with OpenSSL support. (Windows installers require OpenSSL by default).

[0] http://invisible-island.net/lynx/lynx-develop.html

I'm on mobile right now, so not able to test it, but if you start with selected text, does it fill the buffer with it? If not, perhaps this feature could be added? It would be helpful for quickly dropping into to vim for advanced editing.

There's an outstanding PR that does precisely that - https://github.com/cknadler/vim-anywhere/pull/52

It's just become apparent to me that outstanding has two very different meanings depending on context, and this is one of the first times I've seen it used where it could be ambiguous.

> ... if you start with selected text, does it fill the buffer with it

> There's an outstanding PR that does preciesly that

Just to be clear, I believe that PR will fill the newly-opened Vim buffer with text from the clipboard - not selected text.

Somewhat related for vi enthusiasts: https://news.ycombinator.com/item?id=9055523

The comment about rlwrap is especially handy.

does this work on High Sierra for anyone? I'm having trouble getting the shortcut to trigger when in a text input on Chrome. I tried a couple different shortcuts already :/

Clever architecture! Loving it!

As someone who recently switched to vim and neovim - wow that's badass!


vim needs to be used in fewer places, not more.

Why? I use vi/vim for its ubiquity. Isn't it nice knowing you can show up at practically any terminal and have it at your disposal?

Exactly why I switched to vim from emacs. I also never let my bashrc or vimrc files grow too baroque.

Knowing both is not hard. Also if you don't change too much defaults it's not hard to downgrade to vanilla programs. My init.el is above 3000 lines, but I can easily use vanilla Emacs any time if I need to (or vi/vim/ex/ed for that matter). Same for bash, my .profile and .bashrc combined count ~300 lines, both POSIX compatible, and I'd hardly have a hard time at a foreign shell prompt. That's because I use configuration to extend, configure and personalise a program, instead of trying to recreate it.

(Edit: 300 not 900)

Some context to the statement would be great.

while I love Vim and enjoy using Vim..... facepalm


testing that this works as comment....cool!

Looks like a title of a horror movie

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact