Remainders: Vim, The One-Fork Rule, dashes, and ETech, ho!
Merlin Mann | Mar 14 2005
- Vim: The Journey Begins - It’s official. I’m learning Vim, one of the storied UNIX text editors that so many geeks live in. My copy of Learning the vi Editor arrived last week, and I’ve been spending at least an hour each night getting through the basics. I can definitely see why this is so popular with people (even though I’m having a heckuva time un-learning five years of what I now realize are Emacs key bindings). It’s totally configurable and scriptable, and once you get the hang of switching between command and insert modes, it’s just faster than hell. If you want to join in with me for the long walk, ala Oprah’s Book Club, feel free. I’ll be posting on my progress periodically, and have been bookmarking good vi/Vim links to help us out. Also, I do recommend grabbing the Vim carbon app, since it behaves and interacts more like a Mac program and is much easier to customize and use. (Vim studs in the house? Got a good trick I need to know? Dish!)
- Plan before you buy - I keep running lists of all the features and geegaws that I know I’ll want in the next version of a costly product I’ll need to buy someday—from little stuff like a mobile phone or TV to bigger stuff like a car or a house. Capturing these ideas as they occur to you over 1-5 years is a lot less stressful than having to pore manically over a bunch of spec sheets on the day your cell phone falls in the toilet.
- The One-Fork Rule - At one point in my third year of college, my housemates and I felt entropy’s hot breath on the back of our necks. As the dishwasher overflowed with week-old plates and the crisper teemed with blue and brown goo, we acknowledged it was time for a radical change. Thus, Richard, Jake, and I made a pact to instantiate what we called “The One-Fork Rule.” Each of us was issued one and only one of each eating tool: cutlery, plate, bowl, glass, etc. We were to bond with our tools like an infantryman with his rifle. If your fork was dirty when it was time to eat, you were to clean it. You were not to breach the sacred seal of the duct-tape-sealed boxes containing all the additional forks and plates. Like all emergency measures “The One-Fork Rule” passed in time, but I can tell you, it really works if you’re ever feeling overwhelmed by the crufty multiples in your kitchen—or elsewhere your life. Consider trying it for a week or so whenever you need to simplify or just get it together.
- Research dashes - I keep a plaintext file with a long-ass list of stuff to learn, fix, or improve on my computer. Stuff like “learn Perl,” “find out why Mail crashes on
CTRL-click,” or “research cheap external hard drives.” These kinds of items represent very low-pressure and low-priority on my radar screen, but I do like to make progress on a few of them from time to time. Try scheduling “a dash”, 2 to 4 hours, twice a month for researching and conquering little stuff that’s been driving you nuts. This not only gives you a chance to review, update, and solve the stuff that’s probably stealing seconds from every day, but you can also start to watch for interesting patterns that might indicate bigger problems and opportunities (“Whoa: time to get a new laptop”).
- Mass-mailing Customer Service - I sometimes fantasize that I can breach the gates of “Customer Service” at a given company by sending regular old email to several logical addresses. It doesn’t always work—I mean, gracious me, why would you ever want dissatisfied customers to contact you—but I wanted a way to quickly try it without a lot of hassle.
Fellow TextMate fans can make the following bit into a Snippet and assign it a key command.
support@${1:`echo $TM_SELECTED_TEXT`}, help@${1:`echo $TM_SELECTED_TEXT`}, customerservice@${1:`echo $TM_SELECTED_TEXT`}, web@${1:`echo $TM_SELECTED_TEXT`}, webhelp@${1:`echo $TM_SELECTED_TEXT`}$0
In a blank TM document, type the domain of the company (“example.com”), select it, then apply the Snippet via menu or key command to quickly generate a handy, comma-delimited list of potential help sources.
- General ETech slowdown - Things have gotten a bit busy around here with ETech and a few other pet projects coming to the fore, so I’ve decided to hold off on a couple announcements until next week; sorry to be a tease. Check back next Monday (I hope). Since I’ll be pretty heads-down on all things ETech (and post-ETech catchup) over the next week, the volume here will likely stay fairly quiet until then. Still, I’ll probably be posting occasionally here, and watch for ETech related stuff from me on del.icio.us (link | rss) and Flickr (link | rss). Like my friends currently at SxSW, I’ll probably be posting lots of pictures of pleasant-looking people you don’t know eating and sitting in chairs.
Thanks, have a great week, and if you see me in San Diego, please do say hi, and introduce yourself.
|
|
|
Congratulations on the vim decision!...
Congratulations on the vim decision! While the O’Reilly book (Learning the vi editor) is a good one for the bare basics, there are GREAT docs on the www.vim.org website (just look for the Documentation link on the main page).
The complete vim help is available as a PDF or in HTML format - it’s well-written, comprehensive, and very easy to learn from. IMHO, much much easier than the documentation that comes with emacs.
There’s an online and downloadable version of what’s called “The VIM book”, which is handy as well, but it’s based on vim 5, I believe, Still, it’s useful and begins with a very good tutorial section. On about page 527 is a multi-page quick reference section, which is handy to print out.
Of course, the best way to take the plunge is to run vimtutor from the command line. It takes a “learning by doing” approach and it’s very effective. Highly recommended.
Then you can check out The Vim Outliner (TVO), or an alternative, VimOutliner, which are plugins for outlining. At this point, you’ll get addicted and start scrounging around the vim scripts and tips database on the website…
Have lots of fun! It’s the best text editor out there (ducking from the future flames of emacs users…)
vi/vim and less are the...
vi/vim and less are the power tools for those who know how to type. I was never able to get into Escape Meta Alt Control Shift.
Thanks for this Bryan. Super-helpful! Although...
Thanks for this Bryan. Super-helpful!
Although there’s no way to completely avoid the inevitable “Great War of the Text Editors” headed for this topic, I’ll just pointlessly say that I also have every intention of learning Emacs too! I promise. See? I even have the book.
I would say that this never-ending battle will be an exxxxxxcellent topic to take to the Google Group thread I just created.
And thus, I will actively discourage text editor duelling in this particular alley of Verona. Please.
Not trying to provoke a...
Not trying to provoke a fued here, but I’m really eager to hear your thoughts about how learning vim differs from learning emacs. I started learning GNU Emacs, found myself wasting too much time on the learning curve, and went back to using BBEdit. I’ve considered trying out Vim, but I’m not sure it would end up any differently.
Ben: My decision-making was fractured...
Ben: My decision-making was fractured and personal, because they both look terrific and very much worth learning. I went with Vim because based on talking to people and reading up on both, the learning curve was a bit less steep for Vim and it seemed to offer more immediate short term benefits for writing (as opposed to programming, etc.), which is how I will use it for now. Also, I just know more people who are using vi, so my tech support circle was greater there. :)
I have a very long list of things I still find baffling (like how to get ispell working more like auto-spell check in OS X), but I’m determined to stick with it til everything clicks.
My sense is, from talking to a lot of people about this, that learning either will eventually pay huge benefits for people who spend a lot of time doing anything with text. There are some paradigmatic bad habits that GUI editors encourage, and either of these editors really forces you to rethink text editing as much more than just a hobbled version of Microsoft Word or Front Page. The automation, scripting, shortcuts and endless benefits of shell manipulation come together in very compelling ways in both apps.
The thing I like best...
The thing I like best about vi is that I can open a file, do all that I want and never reach for the mouse. When you are editing lots of text files (html, scripts, etc.) like I do, it saves a lot of time.
Now I’m not an Emacs pro, but I’m sure someone who is can acheive similar success. I have the Emacs book on my shelf, but I’ve never really used it since I know vi so well.
Didn't even remotely desire the...
Didn’t even remotely desire the potential flamewar a vi vs emacs comparison can provoke :-)
However, it’s very true that once one settles on a “power” text editor like vim or emacs, there’s no looking back. It’s like learning how to play guitar - easy to pick up and strum chords, takes a lifetime to master.
I have played around with emacs - its outlining mode is really powerful. But with TVO (and I guess VimOutliner), vim has a similar capability.
(By the way, Merlin, I met you at O’Reilly’s Mac OS X conference, and we spoke after your joint revelation of Mac power tools with Danny. Good to be speaking with you again!)
Once you get the hang...
Once you get the hang of it, you will LOVE Vim. The best thing I learned is the * command: It searches for the next occurrence of the word under the cursor. Press n to go to the next word or N to go to the previous. Very useful!
does the same thing, only backwards.
Dammit, I was going to...
Dammit, I was going to write the * tip :)
Then here’s another one: :SEx will split the window and give you a file browser
Wow, I had just added...
Wow, I had just added a NextAction to my list to research a good text editor for Windows so I can edit stuff on Mac & Windows in plain text (Notepad mangles the line endings). I log in and find this entry, I never even thought of vi, just kind of skipped my processing. So I bought the book at lunch today to do the play along at home game :-)
I'm excited about your decision,...
I’m excited about your decision, Merlin. I’m an emacs user who frequently wishes there was a “command” mode in emacs so I could do single-key functions and navigation. If there was a way to duplicate longlines.el in vi (or vim), I might (occasionally, just to keep things interesting) switch back and forth.
I don't know if this...
I don’t know if this will help you, but I’m a Unix/vi user who came to OS X. Some time ago, I wrote this article about Vim tricks that I came across in my transition.
Another tip is substitution: Say you...
Another tip is substitution:
Say you have a line of text:
Hear we go ‘round the mulberry bush.
Now, you’ll note that it should be “Here”, not “Hear”. Simply change in vi!
:s/Hear/Here/
That’s it. Now what if you find out that you’ve misspelled something throughout your document. For instance, you discover that it is spelled “missile” instead of “missle” (something I recently discovered myself).
:%s/missle/missile/g
The % means the entire file (you can actually set a range of line numbers here instead).
The g means globally, not just the first entry on a line.
So if you have the line:
Hear, Hear!
:s/Hear/Here/ will only replace the first one and leave the second one alone. :s/Hear/Here/g will replace all instances on the line.
Substitution is great for the examples above, or if you’re writing code and a function or variable name has changed, or any countless situations.
One the best things I...
One the best things I have done is to map pressing jj quickly to escape as suggested on the tips page of vim.org . Now my fingers don’t need to leave the home row to switch modes. The vim regex’s are awesome as well, :help pattern
Using the period key to repeat the last operation is very helpful as well. So is line based visual mode (V) to delete and move chunks of text.
I forgot to mention :bufdo...
I forgot to mention :bufdo and :argo. Very helpful when combined with substitution expressions.
You want Vim tips? ...
You want Vim tips? Go to the fountainhead: The tips page at vim.org sorted in decending order by rating.
There is much to be learned there…
You want Vim tips? ...
You want Vim tips? Go to the fountainhead: The tips page at vim.org sorted in decending order by rating.
There is much to be learned there…
You want Vim tips? ...
You want Vim tips? Go to the fountainhead: The tips page at vim.org sorted in decending order by rating.
There is much to be learned there…
And the second tip on...
And the second tip on that page is my favorite: the best of vim tips. Not only is it a great reference, it’s also a great learning tool. The descriptions of the commands are often short and cryptic, so you’ll have to go hunting through the docs for what they actually do. Once you understand everything on that page, you will have attained vim zen ;)
The substitution tips mentioned above...
The substitution tips mentioned above are great.
If you know perl, however…you can compile vim to include the perl interpreter (if you’re a fan of another scripting language, python and ruby interpreters are compilable too). This gives you the advantage of using perl’s regular expression grabbag like this:
:%perldo s/]+?HREF\s=\s[“’]?([^’” >]+?)[‘”]?\s*>/”$1”/g
to pull links from simple HTML and surround them with quotes, for a silly example. Perl’s regexes are much more powerful than the ones built-in to vim. If you’re building vim from source, it’s an easy option to configure. I can’t remember offhand if the perl interp is built into the standard binary.
If you’re going to use a powerful text editor like vim or emacs, it really pay to learn all about how to use regular expressions.
Sorry, the regex above should...
Sorry, the regex above should have read as follows:
:%perldo s/]+?HREF\s=\s[“’]?([^’” >]+?)[‘”]?\s*>/”$1”/g
Why anyone would want to do the above - well, that’s another question.
One of my favorites (that...
One of my favorites (that I’m hilighting here, as it’s a few pages into the list of tips) is emulating tabbed editing in Vim.
Anybody got a Markdown syntax...
Anybody got a Markdown syntax setting for Vim?
Also learning a lot from...
Also learning a lot from other people’s .vimrc files:
http://tinyurl.com/4qvcz
Also, FWIW, my favorite colorscheme so far is “dante”
http://www.vim.org/scripts/script.php?script_id=611
Dante Screenshot: http://www.flickr.com/photos/merlin/6539855/
Wow, what great tips! ...
Wow, what great tips! I’ve added them to my list. Here are two I found useful 1. bracket highlighting- http://www.vim.org/tips/tip.php?tipid=177 and setting it to default http://www.vim.org/tips/tip.php?tipid=411 2. set the color scheme to something other than the white. I like the darkblue scheme to relieve eye strain.
Ahhh... if we're talking colorschemes,...
Ahhh… if we’re talking colorschemes, then my two favorites are Zenburn (screenshot) and Desert (screenshot). The low contrast of Zenburn is porticularly nice.
While they are not tricks...
While they are not tricks exactly, there are many creative ways of using the basic commands that I didn’t pick up on at first, but wish I had. For example, lots of commands can be limited using visual mode (Shift+V). y will copy the selected text, d will delete the selected lines, > and < will change indentation for all those lines, and p will replace all of the selected text with the clipboard. So useful. Don’t miss the O command, either. Like P, which pastes above the current line, O inserts a new line above the current one (as opposed to o, which creates a new line below).
Ooh, and when working on text documents, pressing g before the up or down movement keys will take you up or down by only one screen line, instead of one line in the document.
I have no idea what...
I have no idea what vim is (all I know is that it goes with vigor sometimes) but I am a big, big fan of the one fork rule. Our kitchen drawers were filled with seldom used implements that gave my wfie, a chef, a warm fuzzy feeling to have around. But did we really need six wooden spoons? I convinced her that one would probably do and the other five went in storage. I’m trying to apply this theory to other stuff, too.
"But did we really need...
“But did we really need six wooden spoons? I convinced her that one would probably do and the other five went in storage. I’m trying to apply this theory to other stuff, too.”
It doesn’t work with clothing. Trust me.
don't unlearn the emacs keybindings,...
don’t unlearn the emacs keybindings, just use vimacs. google it. it just makes it so vim in insert mode supports the basic emacs C-p, C-n, C-a, C-e, type motion keys. i love it.
i code using emacs with viper-mode but i use vim with vimacs for everything at the console. best of both worlds.