by Gary R. Moser
Director of Institutional Research and Planning
The California Maritime Academy
I recently contacted Joseph Rickert about inviting Vim guru Drew Niel (web: vimcasts.org, book: "Practical Vim: Edit Text at the Speed of Thought") to speak at the Bay Area R User Group group. Due to Drew's living in Great Britain that might not be easily achieved, so Joe generously extended an invitation for me to share a bit about why I like Vim here.
When it comes to text editors, there are a number of strong contenders to choose from (...lots and lots of them). if you've found a tool with a rich feature set that makes you more productive (and more importantly, is something you like) you should probably stick with that. Given that editing text of various types is such a big part of our lives, however, it's worth turning a critical eye toward how well our tools facilitate this specific activity.
Do you spend a lot of time editing text? Yeah, me too. Personally this includes R code, Markdown, Latex, as well as notes and outlines (including this article). When I rediscovered Vim fairly recently, it was from the perspective of being a proficient R user. Therefore, my values and beliefs about what constitutes good software are framed by my experience with R. That includes being OK with an initial learning curve.
I have been using RStudio as my primary IDE for R since it was offered. It's great software; they did something not too long ago that I really appreciate - they added a stripped-down Vim editing mode. Vim pushes users to the documentation pretty quickly (usually as the result of accidentally deleting large chunks of work), and as I dug in and began to discover its full functionality, I came to realize how much I was missing out on by using the emulator. The ability to set and jump to marks in a document, or utilizing multiple registers for copy/paste are two good examples of essential but missing features in RStudio.
Vim has been described as "a language for text editing," which I think is a useful way to view it. At the risk of sounding snotty, I would compare the experiences of using Vim (or another good editor) versus a plain-jane text editor to that of playing chess versus checkers. That is, there's an element of strategic and intentional action compared to simply playing one of a limited set of moves over and over again.
One of the things that makes Vim so interesting and different from other editors stems from its origins. As the result of being developed in the context of severe constraints (slow networks, no digital displays, limited system resources, and no mouse), Vim - then "ed" - had to accomplish the greatest amount of work with the least number of keystrokes. This requirement led to the development of a vast number of very specific commands that can be combined in useful ways. Drew Neil artfully compares this to playing notes, chords, and melodies on a piano. It's also an appropriate comparison for setting one's expectations toward becoming a skilled Vim user! Michael Mrozekon's humorous plot cleverly suggests that, not unlike R, Vim doesn't hold your hand.
It also speaks to my point about specificity. Emacs, for example, can be extended to be a web client or music player, hence the rabbit-hole learning curve, but isn't that getting away from the primary task of text editing?
The fundamental way that Vim differs from most other text editors is that it is explicitly modal; all software is technically modal in certain ways (that is, the same keys do different things under different circumstances), but with Vim it is a central design feature. Essentially, what this means is that by switching modes, a different keyboard comes into existence under your fingers. Because Vim has four modes, and a very rich and terse set of key-bindings, it's like having four+ keyboards in one. The keyboard cheat sheet is a useful reference, especially in the beginning.
Warning: after becoming familiar with Vim's basic functionality, going back to a typical text editor feels rather clumsy.
Vim as an interface to R using the Vim-R-plugin is mostly good for how I use it, but I expect to be dialing-in Vim for a long time before it's got all the features I want. I don't mind this, but I can see how someone else might. I encourage you consider your own tools and how well they facilitate your most frequent tasks. If you're an RStudio user, try giving Vim mode a go. A visit to www.vim.org will connect you to the resources you'll need.
Vim is the bomb! If you get drew to come, make sure to make a webcast.
Posted by: Stefan | March 17, 2015 at 23:38
I am a vim user and the biggest problem is that these days we are not just editing text. Rstudio is a good example: vim-mode may be only a small subset of the original, but Rstudio offers too much comfort so I would never switch to pure vim. Another example: Texpad does not even have a vim-mode, still so much better, then vim + all of those half-broken latex plugins. It is a general problem with vim and emacs. Editor? Vim is the greatest. IDE? Vim is a very bad one.
Posted by: Sergej Hartfil | March 18, 2015 at 02:09
Emacs clone: "you vi(m) nuts have to keep switching modes!"
vi(m) borg: "you emacs sheep all get carpal tunnel in a week!"
Posted by: Robert Young | March 18, 2015 at 06:45
That graphic should actually be attributed to Ryan Bemrose.
Posted by: Steve Rowe | March 18, 2015 at 08:01
I love vim. I use it for all my latex editing, all my c programming and a lot of my r programming. I switch to Rstudio mostly for interactive sessions.
Posted by: Mark van der Loo | March 18, 2015 at 09:20
"The ability to set and jump to marks in a document, or utilizing multiple registers for copy/paste are two good examples of essential but missing features in RStudio."
These features (and lots more, such as macro recording and visual block mode) have recently been added to the preview release of RStudio. Some more detail here:
http://blog.rstudio.org/2015/02/23/rstudio-0-99-preview-vim-mode-improvements/
Give it a try and let us know what you think!
Posted by: Jonathan | March 18, 2015 at 09:34
I switched on Vim mode in RStudio preview. I did not know how to get started. That may be because I am not a real programmer and I only program in R. I would love to see a 60 - 90 second screencast of someone using Vim in RStudio while working on some simple code. Will you do it? Thanking you in anticipation.
Posted by: Farrel Buchinsky | March 19, 2015 at 13:38
These are easily the highest quality comments I have seen in a while on any sort of blog post - you guys are awesome. My replies:
***Stefan: Will do!
***Sergei: It's an good point - the importance of features will differ greatly by individual/application/task. I spend >90% of my professional time editing text, so Vim and its high degree of configurability is best for me. I can whip through a session in way less time and with less mouse-touching than any other approach so far. RStudio is great - I would never try to talk anyone out of it unless it's a poor match for their use-type profile. It doesn't sound like that's the case for you.
***Robert: Yeah - editor wars. Stick with what you like - we spend most of our life working so, be happy.
***Steve: Thank you - credit to ***RYAN BEMROSE***.
***Mark: It sounds like we're on the same page - I do the same thing, albeit less so as I use Vim and get familiar with some of the lesser-known R functions that I've been using the IDE to do
***Jonathan: AWESOME! THAT is a huge improvement. If you can get Visual, Visual Line, and Visual Block mode implemented I would say RStudio becomes a very strong contender to Vim-R-Plugin for the intermediate user. The primary weakness as I see it is configurability. Alt-Up/Down, for example, is a feature I loved in RStudio and then I discovered I could replicate it in Vim quite easily. Other things, such as fuzzy file-matching, custom highlighting, and in-app file browser would make it even stronger so that users don't need to touch the evil mouse. In RStudio, being limited to panes as opposed to windows is a big problem, too. Many of us work in a script screen and a console/output screen, but with a laptop and large monitor config...that's really not a tolerable option. Currently, Vim-R-Plugin with the correct .vimrc settings is better.
***Farrel: I know it's confusing at first, but you will learn very fast. Don't think in terms of being a "programmer." I strongly encourage you to persist.
As a general observation - not in response to the final comment: The poison of popular software design is thinking that it is possible to understand something complex quickly while probably making costly and difficult-to-discover errors. I have done a lot of that, btw. As you well know, investment in skills is a good idea, even if (especially if!) it hurts a bit at first.
An excellent and inspiring video:
https://www.youtube.com/watch?v=_NUO4JEtkDw
Once again, props to RStudio for adding essential Vim features to their emulation mode. And, as R users, let's not forget what can happen in a short time from humble yet uncompromising efforts a-la Robert & Ross.You won't know what you're missing, however, unless you start with the real thing.
www.vim.org
Sincerely,
-Gary
Posted by: Gary | March 19, 2015 at 21:57