Post

5 followers Follow
4
Avatar

Better vim mode

Vim mode is very cool in R and I'm planning on making a screencast to show it in action. I'm currently reading Practical Vim by Drew Neil (excellent book btw) and discovering differences between R's Vim emulator and real Vim. Some frustrating ones:

] symbol effortlessly skips between paras in normal mode in Vim - would be v. useful!

the search / key does not work the same: it does not you take to the word in the editor but to RStudios search bar, almost enforcing use of the mouse. Also, this prevents commands such as d/``` (delete until the end of the block in .Rmd files)

<C-x> and <C-a> do not work to rapidly update numbers.

So I find myself torn between using the full awesomeness of vim for editing but the lack of RStudio's amazingness and the semi-Vim coolness of Vim mode with the full advantages of RStudio. Information about plans to update would be very much appreciated and I imagine fuller Vim integration should be possible as it's an open source program.

Final comment: your implementation of Vim mode is a fantastic effort - way better than Kile's, which is the only other one I've tried. Happy RStudio useR Robin

Robin Lovelace

Official comment

Avatar

Hi Robin,

Thanks for the feedback! I'm a Vim user myself; it's still unclear to me why they kept making text editors after that one. ;-)

RStudio does very little in the way of Vim key handling; the Vim mode you see is a feature of the editing component we use, ACE. We pick up new versions of the editor regularly, but it's been a while since our last one, so we don't have all the Vim mode goodness that the latest version does. You can play with the ACE Kitchen Sink to see some new Vim editor features that will eventually migrate to RStudio (switch "Key Binding" to "Vim"): http://ace.c9.io/build/kitchen-sink.html

That said, most of the commands you mentioned aren't likely to make it into RStudio soon, since ACE hasn't picked them up yet.

If you want to live in no-compromise Vim, some folks from the R community have created an RStudio-like environment using Vim and tmux. More here: http://manuals.bioinformatics.ucr.edu/home/programming-in-r/vim-r

Jonathan.

Jonathan McPherson

Please sign in to leave a comment.

6 comments

0
Avatar

I hope at some point you will pick up Neovim (http://neovim.org/) as an embedded vim editor for R studio. Neovim is still under active development but i can bet in 6 months an alpha or working beta might be available. and it would be nice to play with it under Rstudio.

georgkam 0 votes
0
Avatar

I'm a heavy user of vim, and I have the same dilemma choosing between RStudio and vim with R plugin.

However, the vim mode in RStudio only has a basic subset of functionality of vim, and lack of many editing features.
For example, I heavily rely on text motions of vim when editing. "dt," will delete text till "," in ordinary vim, but will only move the cursor before "," in RStudio.

The latest ACE is much more mature than the version in RStudio in editing features. It would be nice to see the new version of ACE merged into RStudio soon.

Yuheng Li 0 votes
1
Avatar

There is middle way and that is to rely on the fast file-reloads in RStudio and just use both VIM and RStudio at the same time. Whenever I need to edit extensively I keep the file(s) open in both RStudio and VIM. And just rely on the file-reloat that happens pretty much immediatly after saving in VIM.

The ability to autocomplete words in VIM that are in separate files (especially server.R and ui.R) is something I could not be without while coding shiny apps. At the same time I find it hard to reproduce the ease of access of help, objects etc. of RStudio in tmux/VimR.

Frans van Dunné 1 vote
0
Avatar

Hi Frans van Dunne that sounds like a pretty good solution. Provide more information about how to actually implement this fast file load setup in RStudio. What plugins do you use in Vim? I'm a beginner so any links/advice for making vim work well with R/Rmd would be greatly appreciated.

R

Robin Lovelace 0 votes
0
Avatar

Hi Robin,

I don't think it is a setting but standard behaviour in RStudio: whenever you save changes to a file that is open in RStudio with an external editor, you will see the changes automagically appear in the open document as soon as you move your focus back to RStudio.

By the same token whenever you change that file in RStudio and press save, as soon as you move your focus back to VIM you will get a notification asking whether you want to load the changes.

This only works in either direction work if you have actually saved the file of course (:w in VIM or ctrl-s in RStudio).

As for my VIM settings and plugins: that is near impossible to answer. The great thing about VIM is that everybody ends up with different settings that reflect their own preference. The best way to get to the "ideal" settings and plugins is to set aside an hour every week to try out new things, and just keep adding to you vim skills whatever you pick up along the way.

Frans van Dunné 0 votes