MilesMcBain/fnmate

Vim binding?

dewoller opened this issue · 1 comments

Hey Miles, I love your work (and coding style). Any chance of a VIM binding? Or a little bit of documentation about how it works. I am a bit daunted by the ESS bindings (although it appears more principled than the vimscript).

Cheers

Thanks for the compliment! And don't worry, the ESS binding is not completely clear to me at this point :)

I think the main thing you need to know is the interface to the fnmate machinery. If you want to create a vim binding for a template in a new file, then your aim is to call:

fnmate_fn.R(text, index), where:

  • text is some lines of text that surround the cursor above and below. For example, 10 above, the cursor line, and 10 below (21 total). They'll be concatenated into one long vector.
  • and index is a 1-indexed position into that text vector that corresponds to the cursor position.

I don't know vimscript or how the interface to vim and R works. So I can't be much help, but in Emacs I resorted to pasting in the text as a literal argument. Like:

fnmate_fn.R("all the lines\\nOf text", 1)

A bit of annoying math might be required to calculate the index depending on what facilities you have in Vim. You could use the R code I have for the RStudio addin as a guide.