Grokking the Zen of the Vi Wu-Wei

Comments

13 comments posted
Humorous narrative of your

Humorous narrative of your first experiences with vi! Who hasn't had a similarly inexplicable run-in with the holy-hell-ungodliness of vi's modal nature at his try?!

Thanks so much for mentioning visual mode in bash! I have been using "set editing-mode vi" in my .inputrc for a little while, but I was not aware that it even supports visual mode?!! (Got any other nuggets?)

Also, I just added "set keymap vi" to my .inputrc, as you have it. Wth does that do in addition to the editing-mode setting?

Posted by David Rivers (not verified) on Tue, 09/07/2010 - 11:47
Vi is Everywhere When You Need It
Nice post. I learned to love vi and vim when I spent all day, everyday in remote console sessions on servers that I didn't control. vi was always available and always worked the same way. Of course, since I had a login I could customize it as needed but it didn't turn out to be necessary very often. I'm stuck in a Java/Groovy gig now and Eclipse and Intellij are certainly tools that help productivity in some respects but nothing about them is easier when it comes to keyboard navigation or fast operations like line copies or deletes. Your insight that vi is a language is spot on. I had to make an effort to get comfortable in vi but now that I'm considerably along the learning curve I view knowing vi as indispensable.
Posted by Doug (not verified) on Sun, 04/04/2010 - 16:28
vi mode in readline?
I'm a somewhat proficient Vim user, using it since a few year, and loving it, however, each time I try to "set -o vi" in bash, I go back quickly, I use "alt-." a LOT (insert last parameter of last command in place), and did not find any quick equivalent, less important but still, more tan a few ctrl-.. (u,y,w,a,e,x) are in my muscle memory now, I will try again with your tips, but habits are strong ^^. (Oh, you should try Vimperator and the nice ctrl-i in textareas) Cheers, happy new Vim-er ;)
Posted by tshirtman (not verified) on Tue, 03/30/2010 - 04:09
You Can "import" Emacs Key-Bindings into Vi-mode Bash

Yes, some of those Emacs keys do come in handy on the prompt, and habits die hard.

I have the following lines in my "~/.bashrc", lifted almost verbatim from a Usenet posting somewhere:

################################################################################
# READLINE
################################################################################
 
# For those who want to use Vi bindings in bash, this corrects a
# few annoyances:
#
# 1) up and down arrows retrieve history lines even in insert mode
# 2) left and right arrows work in insert mode
# 3) Ctrl-A and Ctrl-E work how you expect if you have had to
# live in Emacs mode in the past.
# 4) So does Ctrl-D.
 
## Command-mode bindings
# Ctrl-A or Home: insert at line beginning like in emacs mode
bind -m vi-command 'Control-a: vi-insert-beg'
# Ctrl-E or End: append at line end like in emacs mode
bind -m vi-command 'Control-e: vi-append-eol'
# to switch to emacs editing mode
bind -m vi-command '"ZZ": emacs-editing-mode'
 
## Insert-mode bindings
# up arrow or PgUp: append to previous history line
bind -m vi-insert '"\M-[A": ""' # <---- CTRL-P CTRL-E
bind -m vi-insert '"\M-[5~": ""' #<---- CTRL-P CTRL-E
bind -m vi-insert 'Control-p: previous-history'
# dn arrow or PgDn: append to next history line
bind -m vi-insert '"\M-[B": ""' #<---- CTRL-P CTRL-E
bind -m vi-insert '"\M-[6~": ""' #<---- CTRL-P CTRL-E
bind -m vi-insert 'Control-n: next-history'
# Ctrl-A: insert at line start like in emacs mode
bind -m vi-insert 'Control-a: beginning-of-line'
# Ctrl-E: append at line end like in emacs mode
bind -m vi-insert 'Control-e: end-of-line'
# Ctrl-D: delete character
bind -m vi-insert 'Control-d: delete-char'
# Ctrl-L: clear screen
bind -m vi-insert 'Control-l: clear-screen'
 
## Emacs bindings
# Meta-V: go back to vi editing
bind -m emacs '"\ev": vi-editing-mode'

Posted by Jeet Sukumaran on Tue, 03/30/2010 - 04:58
funny, I went the opposite route

I was an exclusive Vim user for 5 - 6 years.

I think I started making the switch to Emacs when I began getting into Lisp (the two tend to go hand in hand).

The thing is, it stuck. Emacs was far easier to program for and made a lot more sense than Vim. The thing that took the most time getting over was the use of pre-fix commands. There seems to be a barrier between the modal and non-modal editors that takes some getting used to. One thing I don't miss is constantly reaching for the ESC key (though I do find myself re-configuring my keyboards more often now which pisses off anyone else who uses my computer to no end).

Vim keys are super-sweet but confusing in their own right. Once you know it though, it's freaking awesome.

Both are great editors. I just get more bang for the buck out of Emacs.

Posted by j_king (not verified) on Mon, 03/29/2010 - 09:58
If you know and like Lisp ...

... I cannot imagine why you would use any editor other than Emacs!

I do not know much Lisp, but all that I do know I learned from customizing Emacs over the years. And, like most long-term Emacs-users, I customized the bejeezus out of it. But actually, it was the Lisp-based approach to scripting Emacs (if that is the right term) that actually made it less appealing to me. Conversely, the fact that it is possible to script Vim using Python is a major plus for Vim (for me).

Nonetheless, Emacs definitely has its pluses, and as far as modeless editor goes, it is excellent, easily at least the second-best on most platforms that I have worked with.

No, the "second-best" was not a typo. On Macs, my favorite modeless editor has to be BBEdit (its only downside is that it uses the hideous monstrosity called "AppleScript" for its scripting), while on Windows it is UltraEdit (though I don't know how or whether this can be scripted). On Linuxes, there are couple of decent editors (Kate, BlueFish), but none that I was ever truly happy with: only here do I think that Emacs shines as clearly above the rest in the lead. Factor in scripting needs, however, then sure, Emacs takes the lead on all three platforms.

Posted by Jeet Sukumaran on Mon, 03/29/2010 - 22:24
Emacs on Macs..

I use Aquamacs myself and it's definitely a first-class citizen on my Macbook. I get all of the nice OSX font goodness and it integrates into the desktop environment, respecting the Apple interface guidelines. So you can both Apple-Q and C-x C-c. If you're a little more hardcore, I used to build a nightly carbon version of emacs as well. Either way, there are lots of options.

I'm not trying to win you back to the emacs camp but it should be pointed out that emacs can be scripted with Python as well (or Perl or whatever). Pymacs provides the bridge and along with rope and flymake on top of the python-mode; emacs becomes one mean python hacking machine. An in-editor interpreter, automatically scrubbed source with pyflakes/pylint, integrated test runner... it's freaking sweet (I hack python on my day job, can you tell? :)

There are a lot of reasons to like Vim and I think you hit most of them in your post. Good stuff. :)

Posted by j_king (not verified) on Tue, 03/30/2010 - 08:26
Aquamacs ...

"first-class citizen" ... "Apple interface guidelines"?

Have you opened the Aquamacs "Preferences" dialog recently? Like I said, I have been using (mostly console-based) Emacs for years. When I switched to a Mac as my primary machine, the first thing that I did was check out the various flavors of native GUI Emacs. Maybe it was just me, but the entire "Preferences" subsystem is worthy of its own chapter in a UI design textbook: "Approximating a Gordian Knot in Interface Design, Or How to Ensure that 90% of Your Users Never Use this Feature".

But yes, I agree, on the whole, Emacs is a great little modeless text editor .. and (potentially) quite a bit more. I suppose it comes down to how important that "bit more" part is to you over dedicated/specialized text processing and manipulation. I tend to call all the programming support tools and operations from the shell, even when it is supported by the IDE (as it was in Emacs): my typical configuration is a text editor window open one on half of the screen, and terminal open on the other side, both at full height, side-by-side. Tests, VCS, lint, etc. all run directly from Bash. So their integration/availability in Emacs was just so much bloated deadweight. This did not, and does not, bother me either way --- i.e., I never seen the availability of an unused feature a problem. But this also means that the integration of the tools into the text editor environment ranks pretty close to 0 as a selling a point for me.

On the other hand, the advantages of the significantly extra power, flexibility and elegance of (native) text processing operations available in a text editor does make a sense to me, and thus this easily trumps all the other probably-useful-but-just-not-used-by-me-so-often bells and whistles. But that might just be the song I'm singing now. Let us see what I'll be singing once the Kool Aid wears off.

Posted by Jeet Sukumaran on Thu, 04/01/2010 - 15:01
Using `emacs --daemon` and
Using `emacs --daemon` and `emacsclient` would give you an emacs even faster starting than vim (if you have some addons). I switched a few weeks ago from vim to emacs, because of the better environment (and honestly flymake and flyspell rock) but stayed with viper-mode and vimpulse. That's IMO the best of both worlds.
Posted by cofi (not verified) on Mon, 03/29/2010 - 09:42
Yes, but ...

Is that feasible in contexts where you might be logging on and off frequently?

In any case, now that I have discovered the sublime beauty of "communicating" to my text editor via a grammar, rather then bashing out memorized keys, I'm not sure I can go back ...

Posted by Jeet Sukumaran on Mon, 03/29/2010 - 23:53
Well I don't do that, but
Well I don't do that, but using screen/tmux/... in that context would help keeping the emacs daemon alive, as long as you don't shutdown. But you need to kill emacs gracefully before shutting down, it doesn't like being killed by SIGKILL (not that any other program likes that ..). viper-mode and vimpulse give you that grammar back, at least a whole deal of it - I didn't miss a command in that few weeks. Granted that combo is weak in ex-style commands because only a few are supported, but emacs comes with a nicer command-line anyway.
Posted by cofi (not verified) on Wed, 03/31/2010 - 10:41
I was trying to use emacs for
I was trying to use emacs for a while with viper, and vimpulse, but still it doesn't feel the same, because the shortcuts feels clunky and bolted on, and a lot of the things that I know and love from vim doesn't really work too well even with vimpulse. And the configuration for emacs is a big mess, so for me, vim is the way ;)
Posted by gullars (not verified) on Sat, 04/03/2010 - 20:21
Another happy customer ..
Happy vimming! Regarding `:cq`, I suppose you could also do `:q` or `:q!` to 'cancel' the current command. For me `:wq` saves and `:q!` exits _dangerously_
Posted by Jeff (not verified) on Sun, 03/28/2010 - 20:47

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a biological visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.