16 ms·
Vim Anywhere
- moistoreos 9y agowhile I love Vim and enjoy using Vim..... facepalm
- aidos 9y agoWhy?
- leephillips 9y agoI 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.
- mistahchris 9y agoAgreed. 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.
- grifball 9y agoWhat 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.
- leephillips 9y agoLinux (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.
- lphnull 9y agoi3 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.
- eadmund 9y ago> 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 …
- super_mario 9y agoYou 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.
- leephillips 9y agoBoth 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.
- myrandomcomment 9y agotesting that this works as comment....cool!
- simplify 9y agoIt'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/10fdd692799fc7269b50abbcfb2ea410 https://gist.github.com/gilbert/10fdd692799fc7269b50abbcfb2e...
- egwynn 9y ago1. 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-Line-Editing.html#Command-Line-Editing https://www.gnu.org/software/bash/manual/html_node/Command-L...
- smaddox 9y agoI'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.
- ivarv 9y agoThere's an outstanding PR that does precisely that - https://github.com/cknadler/vim-anywhere/pull/52 https://github.com/cknadler/vim-anywhere/pull/52
- deecewan 9y agoIt'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.
- nastygibbon 9y ago> ... 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.
- greatamerican 9y agovim needs to be used in fewer places, not more.
- ibejoeb 9y agoWhy? 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?
- nategri 9y agoExactly why I switched to vim from emacs. I also never let my bashrc or vimrc files grow too baroque.
- gkya 9y agoKnowing 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)
- middleclick 9y agoSome context to the statement would be great.
- staticvar 9y agoClever architecture! Loving it!
- jxy 9y agoI 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") ec=/Applications/MacPorts/EmacsMac.app/Contents/MacOS/bin/emacsclient cat > "$tmp" until [ $($ec -q -e '(server-running-p)' 2>/dev/null) == t ]; do sleep 1 done $ec -q -c "$tmp" rv="$?" cat "$tmp" if [ $rv -ne 0 ]; then echo "Something went wrong. Please find your text in" echo "$tmp" else rm "$tmp" fi Getting it to work with any editor should be straightforward.
- d1egoaz 9y agoWow, 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") ec=/usr/local/bin/emacsclient cat > "$tmp" until [ $($ec -q -e '(server-running-p)' 2>/dev/null) == t ]; do sleep 1 done $ec -q -c "$tmp" rv="$?" cat "$tmp" if [ $rv -ne 0 ]; then echo "Something went wrong. Please find your text in" echo "$tmp" else rm "$tmp" fi
- sevensor 9y agoPerhaps I've missed the point here. Couldn't you set VISUAL to your editor of choice?
- throw_away 9y agoIt's for things like web forms or other GUI apps, for whom $VISUAL is not meaningful.
- bch 9y agoA 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 https://en.wikipedia.org/wiki/ELinks [1] https://en.wikipedia.org/wiki/Nvi https://en.wikipedia.org/wiki/Nvi
- jamesgeck0 9y agoI 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.
- bch 9y agoHuh, 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!
- shakna 9y agoLynx 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 http://invisible-island.net/lynx/lynx-develop.html
- dbolgheroni 9y agoVimperator did that. Just miss it.
- orliesaurus 9y agoAs someone who recently switched to vim and neovim - wow that's badass!
- amelius 9y agoMeanwhile, the Escape key on popular keyboards is getting smaller and smaller :(
- platinumrad 9y agoYou can rebind caps lock to escape.
- tetraodonpuffer 9y agoor rebind it to ctrl if held, escape if tapped, making it even better for RSI purposes
- amelius 9y agoThat's a good one!
- mkl 9y agoWhat do you use to do this? On what operating systems?
- farresito 9y agoIf you are on Linux, try xcape; on Windows, you can do it with autohotkey.
- fencepost 9y agoRemapping 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.
- 9y ago
- numbers 9y agodoes 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 :/
- Theodores 9y agoNo 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.
- marcoperaza 9y agoThere are vim builds for Windows, both graphical and terminal. You don't need to use the linux subsystem for that.
- tyingq 9y agoSomewhat related for vi enthusiasts: https://news.ycombinator.com/item?id=9055523 https://news.ycombinator.com/item?id=9055523 The comment about rlwrap is especially handy.
- mikerathbun 9y agoVery cool. I am using it now to write this comment! exit quit exit() ctrlC ctrlx stop please exit help exit
- applecrazy 9y agoESC :wq should do the trick. (Yes, I know it's a joke)
- ufo 9y agoIs 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.
- wfriesen 9y agoZZ will save and exit, or ZQ to exit without saving.
- deleted 9y ago[deleted]
- gowld 9y agoCtrl-Z to suspend and then you can kill the job
- adtac 9y agoYanking the power cord usually does the trick for me too.
- vram22 9y agoHa 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 :)
- jcranberry 9y ago.
- yjftsjthsd-h 9y agoDoes 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.
- fao_ 9y agoI wrote a five line script for it here >> https://news.ycombinator.com/item?id=16398356 https://news.ycombinator.com/item?id=16398356
- yjftsjthsd-h 9y agoNot what I was thinking, but that works. Thanks
- fao_ 9y agoOk, but you can do this with a simple shell script without the reliance on Gnome/GTK: #!/bin/bash dir="/tmp/vim-anywhere/" 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.
- deleted 9y ago[deleted]
- zipperhead 9y agoI 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.
- ulkesh 9y agoMaybe 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.
- eadmund 9y agoI 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.
- Lio 9y agoI’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.
- gschier 9y agoIf 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.
- lucb1e 9y agoAnd 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).
- michaelsbradley 9y agoA 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.
- bfred_it 9y agoRelevant self-plug: I co-wrote an extension that does this between browsers and several text editors, it’s called GhostText https://github.com/GhostText/GhostText https://github.com/GhostText/GhostText
- rpdillon 9y agoIt's fantastic! I use this every day and it works great. Thanks for the effort you put into it!
- weinzierl 9y agoSimilar 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.
- lucb1e 9y agoThis 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.
- rpdillon 9y agoCheck out GhostText: https://addons.mozilla.org/en-US/firefox/addon/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.
- kilon 9y agoLooks like a title of a horror movie
- davidbanham 9y agoI 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: #!/bin/bash vim /tmp/everyvim && cat /tmp/everyvim | xclip -sel clip -i
- humbly 9y agoHere 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 https://github.com/zachcurry/emacs-anywhere