News for hackers. Stuff that matters.
Re:Vim Anywhere by jxy on Friday February 16, 2018 @03:52PM (#16396090)
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")
    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.
Re:Vim Anywhere by d1egoaz on Friday February 16, 2018 @05:14PM (#16396951)
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")
  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
Re:Vim Anywhere by d1egoaz on Tuesday February 20, 2018 @07:30PM (#16425705)
I ended forking and creating this https://github.com/d1egoaz/vim-anywhere WIP
Re:Vim Anywhere by swsieber on Friday February 16, 2018 @06:36PM (#16397606)
Hmm... I'm not very familiar with this, but couldn't you send a key command to select the entire text (CMD A)?
Re:Vim Anywhere by d1egoaz on Friday February 16, 2018 @06:42PM (#16397646)
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
Re:Vim Anywhere by swsieber on Saturday February 17, 2018 @02:40AM (#16399566)
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
Re:Vim Anywhere by d1egoaz on Tuesday February 20, 2018 @07:31PM (#16425709)
osascript is our friend

    osascript -e 'tell application "System Events" to keystroke "a" using command down'
Re:Vim Anywhere by jiqiren on Saturday February 17, 2018 @01:16AM (#16399349)
why not "mktemp -t EditTextinEmacs". This will touch a file in $TMPDIR which is more safe than /tmp.
Re:Vim Anywhere by ulkesh on Friday February 16, 2018 @10:39PM (#16398819)
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.

Re:Vim Anywhere by eadmund on Friday February 16, 2018 @11:16PM (#16398962)
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.

Re:Vim Anywhere by Lio on Saturday February 17, 2018 @05:10AM (#16400003)
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.

Re:Vim Anywhere by gschier on Saturday February 17, 2018 @12:30AM (#16399233)
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.
Re:Vim Anywhere by lucb1e on Saturday February 17, 2018 @07:23AM (#16400377)
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).

Re:Vim Anywhere by MaxBarraclough on Saturday February 17, 2018 @04:06PM (#16402697)
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.

Re:Vim Anywhere by ibotty on Sunday February 18, 2018 @05:38AM (#16405393)
But w and b are not the end of vi's (let alone vim's/neovim's + plugins') motions.
Re:Vim Anywhere by MaxBarraclough on Sunday February 18, 2018 @06:16AM (#16405517)
Sure, but it's not often I win big by using Vim's advanced movement commands.
Re:Vim Anywhere by zweicoder on Monday February 19, 2018 @04:01AM (#16411653)
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.

Re:Vim Anywhere by jsjohnst on Sunday February 18, 2018 @12:41PM (#16407140)
Shift-G / gg are “big” wins for me on a fairly regular basis.
Re:Vim Anywhere by MaxBarraclough on Sunday February 18, 2018 @01:20PM (#16407323)
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.

Re:Vim Anywhere by jsjohnst on Sunday February 18, 2018 @01:48PM (#16407471)
Not all keyboards have a home key and the vast majority have a shift/g key, but yes, i agree.
Re:Vim Anywhere by ibotty on Monday February 19, 2018 @05:30AM (#16412008)
you don't use `)` or any other object motion? You should (consider)! `:help object-motions`
Re:Vim Anywhere by djsumdog on Saturday February 17, 2018 @02:02AM (#16399456)
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?

Re:Vim Anywhere by tempay on Saturday February 17, 2018 @01:59AM (#16399450)
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).

Re:Vim Anywhere by gkya on Saturday February 17, 2018 @05:32AM (#16400064)
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

Re:Vim Anywhere by danilocesar on Saturday February 17, 2018 @02:38AM (#16399561)
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.

Re:Vim Anywhere by bo1024 on Saturday February 17, 2018 @08:18AM (#16400541)
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.
Re:Vim Anywhere by dozzie on Saturday February 17, 2018 @09:31AM (#16400797)
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.

Re:Vim Anywhere by jacobmoe on Saturday February 17, 2018 @08:43AM (#16400623)
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.
Re:Vim Anywhere by rasengan0 on Saturday February 17, 2018 @10:44PM (#16404329)
>... 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.

Re:Vim Anywhere by simplify on Friday February 16, 2018 @03:39PM (#16395941)
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...

Re:Vim Anywhere by caymanjim on Friday February 16, 2018 @04:57PM (#16396831)
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.
Re:Vim Anywhere by simplify on Friday February 16, 2018 @05:15PM (#16396955)
> 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).

Re:Vim Anywhere by saagarjha on Saturday February 17, 2018 @01:37AM (#16399396)
They work anywhere there's a system-provided text field.
Re:Vim Anywhere by fimdomeio on Friday February 16, 2018 @06:19PM (#16397483)
fish shell has a vim mode for anyone interested
Re:Vim Anywhere by xelxebar on Saturday February 17, 2018 @02:01AM (#16399451)
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.

https://www.gnu.org/software/bash/manual/html_node/Readline-...

Re:Vim Anywhere by hnzix on Friday February 16, 2018 @07:31PM (#16397972)
Bash and zsh also have vim mode. The bash mode is more like vi though.
Re:Vim Anywhere by egwynn on Friday February 16, 2018 @07:39PM (#16398028)
Indeed, it’s in fact called “vi mode” in the bash/readline docs.
Re:Vim Anywhere by egwynn on Friday February 16, 2018 @03:46PM (#16396017)
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...

Re:Vim Anywhere by simplify on Friday February 16, 2018 @03:57PM (#16396151)
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.
Re:Vim Anywhere by omaranto on Friday February 16, 2018 @05:38PM (#16397161)
All seven are default keybindings in Emacs. Which two did you believe weren't?
Re:Vim Anywhere by egwynn on Friday February 16, 2018 @05:57PM (#16397316)
I believe ctrl-n and ctrl-p work in vim
Re:Vim Anywhere by omaranto on Friday February 16, 2018 @06:03PM (#16397360)
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.
Re:Vim Anywhere by egwynn on Friday February 16, 2018 @07:38PM (#16398020)
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
Re:Vim Anywhere by gumby on Saturday February 17, 2018 @11:26AM (#16401329)
I've been using those commands in Emacs since the late 70s
Re:Vim Anywhere by thomastjeffery on Friday February 16, 2018 @04:50PM (#16396751)
Those are emacs-based shortcuts.

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

Re:Vim Anywhere by omaranto on Friday February 16, 2018 @05:00PM (#16396865)
Those OS X keybindings come from Emacs! I bet some vimmers would refuse to use them just on principle. :)
Re:Vim Anywhere by sodapopcan on Friday February 16, 2018 @05:45PM (#16397217)
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:"; }

Re:Vim Anywhere by eadmund on Friday February 16, 2018 @11:18PM (#16398967)
> 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.

Re:Vim Anywhere by sodapopcan on Friday February 16, 2018 @11:34PM (#16399030)
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 :)
Re:Vim Anywhere by omaranto on Friday February 16, 2018 @05:58PM (#16397327)
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

Re:Vim Anywhere by sodapopcan on Friday February 16, 2018 @06:04PM (#16397369)
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)

Re:Vim Anywhere by sodapopcan on Friday February 16, 2018 @06:09PM (#16397406)
Also, you mentioning it made me realize I never starred the repo, so thanks, haha!
Re:Vim Anywhere by Lio on Saturday February 17, 2018 @05:20AM (#16400029)
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?

Re:Vim Anywhere by jsjohnst on Sunday February 18, 2018 @12:45PM (#16407154)
I’m a heavy vim user and yet I add bindings to vim for Control-A and Control-E.
Re:Vim Anywhere by jaequery on Friday February 16, 2018 @05:29PM (#16397075)
now that’s funny
Re:Vim Anywhere by girvo on Friday February 16, 2018 @06:44PM (#16397665)
Doesn’t Option-(Arrow Left|Arrow Right) move around per word?
Re:Vim Anywhere by simplify on Friday February 16, 2018 @08:12PM (#16398200)
You're right, but option+(f/b) is handier when combined with ctrl+(f/b)
Re:Vim Anywhere by fao_ on Friday February 16, 2018 @08:50PM (#16398356)
Ok, 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.

Re:Vim Anywhere by zipperhead on Saturday February 17, 2018 @10:34AM (#16401105)
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.
Re:Vim Anywhere by bfred_it on Saturday February 17, 2018 @12:26AM (#16399222)
Relevant 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

Re:Vim Anywhere by rpdillon on Saturday February 17, 2018 @10:56AM (#16401187)
It's fantastic! I use this every day and it works great. Thanks for the effort you put into it!
Re:Vim Anywhere by davidbanham on Saturday February 17, 2018 @07:05AM (#16400335)
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:

    #!/bin/bash
    vim /tmp/everyvim && cat /tmp/everyvim | xclip -sel clip -i
Re:Vim Anywhere by Theodores on Friday February 16, 2018 @05:25PM (#16397047)
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.

Re:Vim Anywhere by wildmusings on Friday February 16, 2018 @08:13PM (#16398201)
There are vim builds for Windows, both graphical and terminal. You don't need to use the linux subsystem for that.
Re:Vim Anywhere by amelius on Friday February 16, 2018 @04:29PM (#16396541)
Meanwhile, the Escape key on popular keyboards is getting smaller and smaller :(
Re:Vim Anywhere by dag11 on Friday February 16, 2018 @04:55PM (#16396812)
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.
Re:Vim Anywhere by spraak on Friday February 16, 2018 @08:36PM (#16398306)
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?
Re:Vim Anywhere by _betty_ on Sunday February 18, 2018 @02:32AM (#16404925)
Other people's (when pair programming)
Re:Vim Anywhere by K0nserv on Friday February 16, 2018 @06:35PM (#16397598)
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
Re:Vim Anywhere by spraak on Friday February 16, 2018 @08:19PM (#16398231)
But what would it do in visual mode?
Re:Vim Anywhere by Pete_D on Saturday February 17, 2018 @08:30AM (#16400572)
Nothing, but you could add a `vnoremap jk <Esc>` line as well to have it leave visual mode if you wanted.
Re:Vim Anywhere by K0nserv on Saturday February 17, 2018 @09:02AM (#16400696)
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.
Re:Vim Anywhere by platinumrad on Friday February 16, 2018 @04:32PM (#16396574)
You can rebind caps lock to escape.
Re:Vim Anywhere by tetraodonpuffer on Friday February 16, 2018 @04:36PM (#16396622)
or rebind it to ctrl if held, escape if tapped, making it even better for RSI purposes
Re:Vim Anywhere by Scarbutt on Friday February 16, 2018 @05:59PM (#16397335)
and enter to ctrl if held and enter if tapped ;) (macbooks don't have a right ctrl key).
Re:Vim Anywhere by Lio on Saturday February 17, 2018 @05:30AM (#16400058)
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.

Re:Vim Anywhere by zcid on Friday February 16, 2018 @06:09PM (#16397407)
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.
Re:Vim Anywhere by mkl on Friday February 16, 2018 @04:46PM (#16396707)
What do you use to do this? On what operating systems?
Re:Vim Anywhere by tetraodonpuffer on Friday February 16, 2018 @05:51PM (#16397268)
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
Re:Vim Anywhere by alienreborn on Friday February 16, 2018 @05:26PM (#16397049)
I use this app on Mac for the exact key mentioned above Caps -> Ctrl/Esc

https://github.com/tekezo/Karabiner-Elements

Re:Vim Anywhere by farresito on Friday February 16, 2018 @04:49PM (#16396747)
If you are on Linux, try xcape; on Windows, you can do it with autohotkey.
Re:Vim Anywhere by fencepost on Saturday February 17, 2018 @03:27PM (#16402529)
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.

Re:Vim Anywhere by amelius on Friday February 16, 2018 @04:37PM (#16396630)
That's a good one!
Re:Vim Anywhere by aidos on Friday February 16, 2018 @05:44PM (#16397214)
Oh that’s interesting!
Re:Vim Anywhere by amelius on Friday February 16, 2018 @04:37PM (#16396625)
I already bound it to Ctrl.
Re:Vim Anywhere by chongli on Friday February 16, 2018 @05:00PM (#16396864)
I bound caps lock to ctrl. I use it with ctrl-[ to escape in vim. Does everything I need.
Re:Vim Anywhere by platinumrad on Friday February 16, 2018 @04:46PM (#16396711)
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.

Re:Vim Anywhere by derriz on Friday February 16, 2018 @04:59PM (#16396852)
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.
Re:Vim Anywhere by Moter8 on Friday February 16, 2018 @05:23PM (#16397022)
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.

Re:Vim Anywhere by fphilipe on Saturday February 17, 2018 @02:25AM (#16399530)
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.
Re:Vim Anywhere by oelmekki on Saturday February 17, 2018 @02:10PM (#16402160)
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?

Re:Vim Anywhere by vram22 on Tuesday February 20, 2018 @12:45PM (#16422222)
>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.

Re:Vim Anywhere by oelmekki on Tuesday February 20, 2018 @01:42PM (#16422741)
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.
Re:Vim Anywhere by vram22 on Tuesday February 20, 2018 @02:38PM (#16423417)
>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.

Re:Vim Anywhere by vram22 on Tuesday February 20, 2018 @12:44PM (#16422206)
>* 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)?

Re:Vim Anywhere by oelmekki on Tuesday February 20, 2018 @01:39PM (#16422718)
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`.
Re:Vim Anywhere by vram22 on Tuesday February 20, 2018 @02:41PM (#16423449)
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).

https://en.wikipedia.org/wiki/Esc_key

Re:Vim Anywhere by oelmekki on Wednesday February 21, 2018 @05:39AM (#16428468)
I see. thanks for sharing!
Re:Vim Anywhere by eddyg on Saturday February 17, 2018 @06:32AM (#16400254)
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.
Re:Vim Anywhere by cestith on Friday February 16, 2018 @08:22PM (#16398244)
Here's one way to mitigate that: use a less popular keyboard. I suggest evaluating https://shop.keyboard.io/ for starters.
Re:Vim Anywhere by Lio on Saturday February 17, 2018 @05:37AM (#16400082)
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).

Re:Vim Anywhere by imahorse on Saturday February 17, 2018 @07:30PM (#16403684)
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 :)

Re:Vim Anywhere by vram22 on Tuesday February 20, 2018 @12:41PM (#16422181)
On some laptops too :(
Re:Vim Anywhere by mikerathbun on Friday February 16, 2018 @06:20PM (#16397488)
Very cool. I am using it now to write this comment!

exit

quit

exit()

ctrlC

ctrlx

stop

please exit

help exit

Re:Vim Anywhere by applecrazy on Friday February 16, 2018 @06:48PM (#16397709)
ESC :wq should do the trick. (Yes, I know it's a joke)
Re:Vim Anywhere by ufo on Friday February 16, 2018 @07:18PM (#16397904)
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.

Re:Vim Anywhere by wfriesen on Friday February 16, 2018 @07:25PM (#16397936)
ZZ will save and exit, or ZQ to exit without saving.
Re:Vim Anywhere by vram22 on Tuesday February 20, 2018 @12:40PM (#16422171)
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 :)
Re:Vim Anywhere by gowld on Friday February 16, 2018 @07:48PM (#16398070)
Ctrl-Z to suspend and then you can kill the job
Re:Vim Anywhere by adtac on Saturday February 17, 2018 @01:50AM (#16399431)
Yanking the power cord usually does the trick for me too.
Re:Vim Anywhere by Noumenon72 on Saturday February 17, 2018 @09:47AM (#16400876)
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.
Re:Vim Anywhere by always_good on Saturday February 17, 2018 @11:13AM (#16401274)
:x is a shortcut for :wq. I wonder why nobody knows it.
Re:Vim Anywhere by vram22 on Tuesday February 20, 2018 @12:35PM (#16422126)
: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).

Re:Vim Anywhere by BenjiWiebe on Saturday February 17, 2018 @05:08PM (#16403021)
I've never used :wq, always :x. And I've been using vim for roughly 3 years.
Re:Vim Anywhere by applecrazy on Sunday February 18, 2018 @05:17PM (#16409117)
Sorry, I’m pretty new to vim (switched from ST this week and loving it so far). Thanks for the advice though
Re:Vim Anywhere by dbolgheroni on Friday February 16, 2018 @04:21PM (#16396449)
Vimperator did that. Just miss it.
Re:Vim Anywhere by leephillips on Friday February 16, 2018 @03:29PM (#16395817)
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.
Re:Vim Anywhere by eadmund on Friday February 16, 2018 @11:19PM (#16398976)
> 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 …

Re:Vim Anywhere by super_mario on Saturday February 17, 2018 @06:29AM (#16400246)
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.

Re:Vim Anywhere by leephillips on Saturday February 17, 2018 @08:10AM (#16400514)
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.
Re:Vim Anywhere by lphnull on Friday February 16, 2018 @05:56PM (#16397313)
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.

Re:Vim Anywhere by grifball on Friday February 16, 2018 @03:59PM (#16396176)
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.
Re:Vim Anywhere by leephillips on Friday February 16, 2018 @04:22PM (#16396457)
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.

Re:Vim Anywhere by mistahchris on Friday February 16, 2018 @03:35PM (#16395870)
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.

Re:Vim Anywhere by weinzierl on Saturday February 17, 2018 @02:07AM (#16399473)
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.
Re:Vim Anywhere by rpdillon on Saturday February 17, 2018 @10:54AM (#16401182)
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.

Re:Vim Anywhere by lucb1e on Saturday February 17, 2018 @07:28AM (#16400394)
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.
Re:Vim Anywhere by humbly on Monday February 19, 2018 @07:34PM (#16416955)
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
Re:Vim Anywhere by michaelsbradley on Friday February 16, 2018 @10:44PM (#16398844)
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.

Re:Vim Anywhere by yjftsjthsd-h on Friday February 16, 2018 @08:10PM (#16398186)
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.
Re:Vim Anywhere by fao_ on Friday February 16, 2018 @08:51PM (#16398364)
I wrote a five line script for it here >> https://news.ycombinator.com/item?id=16398356
Re:Vim Anywhere by yjftsjthsd-h on Saturday February 17, 2018 @11:01AM (#16401217)
Not what I was thinking, but that works. Thanks
Re:Vim Anywhere by sevensor on Friday February 16, 2018 @04:00PM (#16396187)
Perhaps I've missed the point here. Couldn't you set VISUAL to your editor of choice?
Re:Vim Anywhere by throw_away on Friday February 16, 2018 @04:06PM (#16396254)
It's for things like web forms or other GUI apps, for whom $VISUAL is not meaningful.
Re:Vim Anywhere by bch on Friday February 16, 2018 @04:14PM (#16396359)
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

Re:Vim Anywhere by jamesgeck0 on Friday February 16, 2018 @04:43PM (#16396682)
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.
Re:Vim Anywhere by bch on Friday February 16, 2018 @05:08PM (#16396909)
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!
Re:Vim Anywhere by shakna on Friday February 16, 2018 @06:35PM (#16397596)
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

Re:Vim Anywhere by smaddox on Friday February 16, 2018 @03:41PM (#16395952)
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.
Re:Vim Anywhere by ivarv on Friday February 16, 2018 @04:10PM (#16396312)
There's an outstanding PR that does precisely that - https://github.com/cknadler/vim-anywhere/pull/52
Re:Vim Anywhere by deecewan on Friday February 16, 2018 @09:45PM (#16398597)
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.
Re:Vim Anywhere by nastygibbon on Saturday February 17, 2018 @06:56AM (#16400306)
> ... 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.

Re:Vim Anywhere by tyingq on Friday February 16, 2018 @06:08PM (#16397396)
Somewhat related for vi enthusiasts: https://news.ycombinator.com/item?id=9055523

The comment about rlwrap is especially handy.

Re:Vim Anywhere by numbers on Friday February 16, 2018 @04:53PM (#16396794)
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 :/
Re:Vim Anywhere by staticvar on Friday February 16, 2018 @03:50PM (#16396066)
Clever architecture! Loving it!
Re:Vim Anywhere by orliesaurus on Friday February 16, 2018 @04:28PM (#16396532)
As someone who recently switched to vim and neovim - wow that's badass!
Re:Vim Anywhere by jcranberry on Friday February 16, 2018 @06:52PM (#16397736)
.
Re:Vim Anywhere by greatamerican on Friday February 16, 2018 @03:43PM (#16395972)
vim needs to be used in fewer places, not more.
Re:Vim Anywhere by ibejoeb on Friday February 16, 2018 @03:45PM (#16396001)
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?
Re:Vim Anywhere by nategri on Friday February 16, 2018 @04:13PM (#16396357)
Exactly why I switched to vim from emacs. I also never let my bashrc or vimrc files grow too baroque.
Re:Vim Anywhere by gkya on Saturday February 17, 2018 @05:42AM (#16400099)
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)

Re:Vim Anywhere by middleclick on Friday February 16, 2018 @03:47PM (#16396024)
Some context to the statement would be great.
Re:Vim Anywhere by moistoreos on Friday February 16, 2018 @03:27PM (#16395786)
while I love Vim and enjoy using Vim..... facepalm
Re:Vim Anywhere by aidos on Friday February 16, 2018 @03:29PM (#16395800)
Why?
Re:Vim Anywhere by myrandomcomment on Friday February 16, 2018 @03:34PM (#16395855)
testing that this works as comment....cool!
Re:Vim Anywhere by kilon on Saturday February 17, 2018 @04:48AM (#16399945)
Looks like a title of a horror movie