Use vim to edit text anywhere

For people that are used to the superior vim keybindings it may be nice to use their favorite editor on every text input, no matter if its a in another application or on a website. This small script helps so you to never again write text in a non-vim environment.

Demo

The script

Save somewhere and assign a hotkey to it. The script opens a new terminal with vim and pastes the output into the currently opened application once the editor is closed.

#!/bin/bash

function setclip {
  xclip -selection c
}

function getclip {
  xclip -selection clipboard -o
}

file=$(mktemp)
urxvt -e vim "$file" # replace with your favorite terminal

cat $file | setclip
rm $file

xdotool key ctrl+v

Sample i3 configuration:

bindsym $mod+Shift+o exec --no-startup-id ~/bin/editinvim.sh

Inspiration

I took the idea from this tool but realized that this simpler approach is enough for me.