Vim Anywhere
github.com
github.com
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.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 osascript -e 'tell application "System Events" to keystroke "a" using command down'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.
Honestly, every programme other than emacs is a distraction.
For all its faults, readline is a godsend for Vi users.
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).
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.
Apparently in Visual Studio it's SHIFT+CTRL+HOME.
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.
- 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).
Basically if you want a powerful editor just in case when you're filling out a form or something else, here you go?
I can easily see the benefits of using this to write a long blog/fb post.
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'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.
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.
- 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...
2. Five of your seven shortcuts are for emacs[0], not vim.
[0]: https://www.gnu.org/software/bash/manual/html_node/Command-L...
They are also the default in most shells (bash/zsh), which also have optional vi-based bindings.
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).
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.https://www.gnu.org/software/bash/manual/html_node/Readline-...
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:"; }
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)
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.
Do you know anyway to get the same behaviour on Linux and Gnome at all?
#!/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.
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.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 -iIf 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.
I suspect you'd have to switch to something like Autohotkey for the Esc/Ctrl mapping.
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_switchI find I don’t really miss the right alt key at all.
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.
Oh, and on Mac CTRL+ALT+5 if I remember correctly.
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).
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 :)
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?
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)?
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.
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.
exit
quit
exit()
ctrlC
ctrlx
stop
please exit
help exit
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.
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).
It is cool that apple has the ability to script like this though. It's pretty handy.
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.
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.
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 …
And vim launches in milliseconds, so no need to keep it running in the background as some text editing server.
I use it with Atomic Chrome for Emacs, but it supports Vim, Sublime, and Atom as well.
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.
> 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.
The comment about rlwrap is especially handy.
(Edit: 300 not 900)