iVimClippy

Because vimclippy is a shell command, iVim users may fear they are OUT OF LUCK when it comes to FAST clipboard-editing, and that they are doomed to forever tapping out "*P:%y* like NEANDERTHALS.

But there is a way.

Step 1: Create a User-Defined Command

First we’re going to set up a :VimClippy Ex command to insert the current content of the clipboard into a buffer and set up the autocommand to write the edited text back into the clipboard when the buffer is saved.

Open up your vimrc1 and enter the following:

function! s:vimclippy() abort
  edit vimclippy
  silent put! +
  $delete
  1
  augroup vimclippy
    autocmd!
    autocmd BufWriteCmd vimclippy %yank + | set nomodified
  augroup END
endfunction

command VimClippy call s:vimclippy()

This is the same basic set of commands as in the original vimclippy, but written out in full as a Vimscript function and :command.

Step 2: Set Up a Shortcut

Next, we need a method of running iVim and immediately calling this command in an AUTOMATED fashion. iVim does support passing in the command line arguments that we used in the shell version, but the mechanism2 isn’t suitable for our purposes.

Instead we’re going to use iVim’s custom URL scheme, using the Shortcuts app3 to add a home screen icon to invoke the custom command we defined above.

iVim URL Scheme
iVim’s custom URL scheme is explained in its help, at :help ivim-url-scheme. For a beginner’s guide to URLs and their dastardly schemes, check out my nine-year-old guide to automating your phone with x-callback-url.

In Shortcuts, add a new Shortcut and add an OpenURLs action. For the URL, enter

ivimeditor:runexcmd?excmd=VimClippy

/posts/ivimclippy/images/ivimclippy-shortcut.png

When the shortcut is run, this will fire up iVim and invoke the VimClippy command we set up in Step 1. Give your shortcut an appropriate name and icon, and then you can “Add to Home Screen”.

/posts/ivimclippy/images/shortcut-menu.png

Step 3: Configure iVim

Open the iOS Settings app and find the iVim section. Scroll down to the bottom and toggle the URL SCHEME switch to Allow so that iVim will respond to your new URL. Optionally, you can also set Paste from Other Apps to Allow to stop iVim from asking you if you want to paste in your clipboard contents every time the shortcut is run.

Step 4: PROFIT!!!

Try out your new shortcut, and REJOICE at the EASE with which you can now edit your clipboard contents.


  1. If you don’t have a vimrc, :e ~/.vimrc will create one for you in the default location. If you do already have one, :e $MYVIMRC is a better command to use, as it’s set to the location of the vimrc that Vim found during startup. ↩︎

  2. You type them into a textbox in the Settings app. ↩︎

  3. If you have a favourite app launcher (Launch Center Pro is the one I use), then you can use the same URL in that instead. I’m using Shortcuts in this tutorial because it’s free and supported by Apple themselves. ↩︎