vimmy
Will type outside vim so you don’t have to
Once you learn vim and develop muscle memory for its key bindings, its quite hard to go back to a text editor without them. Emulators in other text editors don’t generally implement enough of vim’s functionality for a smooth transition and using them can be a little jarring after spending hours in a vim buffer, especially if you’ve got a specialized configuration.
I use firenvim for my browser to get a neovim buffer and some plugins in any text box. This is nice when I have to use a browser for email, Github, and Slack/Teams. However, when I need to write with other people, writing a response to reviewers after peer-review for example, I find myself forced to use Word online which does not use a standard text-input box for text entry. Word online is particularly frustrating because, for reasons I don’t understand, it loses text after I type. I could write a whole paragraph and hit retrun only to lose all but the first few words I wrote.
My solution, partially inspired by tools like that bring a vim buffer where you are, was to launch a temporary vim buffer, write in it, and when I save and close the buffer, the vim and its container terminal window close and what I just wrote is typed into the vim-unfriendly buffer that I just had to deal with.
The first problem was an extra newline getting added when catting the file. I found a solution using perl that ‘chomps’ the final newline to remove it. Then the issue was getting it into the original editor. I tried to paste it but couldn’t find a way to programmatically paste with xclip
since xclip -o
calls only paste into the calling terminal window. So I turned to xdotool
to type it out. This worked but lost all newlines. I then figured out how to preserve newlines by translating the linefeed (LF) \n
character to the carriage return (CR) \r
character.
#! /usr/bin/env zsh
kitty --class flykitty \
\
nvim -c 'set laststatus=0' \
-c 'set spell' \
-c 'source ~/.config/nvim/vim/autocorrect.vim' /tmp/temp_buffer
perl -pe 'chomp if eof' /tmp/temp_buffer |\
tr \\n \\r |\
xdotool type --delay 0.5 -file -
This script launches neovim in a kitty window with spell check and autocorrect, but without a status bar. Once saved, kitty exits and the output file is processed and typed out wherever my cursor focus was before launching the script.