Text Editor a la Mode
December 7, 2009 11:24 AM   Subscribe

Vim tutorial. Efficient Editing with Vim. Vim as IDE. Vim cookbook.

Daily Vim. Vim Tips Wiki. Vim scripts.

Example vimrcs: 1 2 3 4 5

Vim colorscheme samples. (Heed the warnings about loading times.)

Related: Vi mode in Bash. Vimperator makes Firefox Vim-like. Configuring Opera to behave similarly. Eclim = Eclipse + Vim.
posted by kmz (119 comments total) 118 users marked this as a favorite
 
Trolling for favourites. Really now.

Also: DIE EMACS! Not even psychoanalyze-pinhead mode can save you.
posted by GuyZero at 11:28 AM on December 7, 2009


...But does it have an Emacs-bindings mode? ;)

(Like the Vimperator link, BTW... Very cool).
posted by pla at 11:28 AM on December 7, 2009


Fuck yes.
posted by chunking express at 11:30 AM on December 7, 2009


...But does it have an Emacs-bindings mode?

If I wanted to play the piano, I'd learn to play the piano.
posted by GuyZero at 11:31 AM on December 7, 2009 [6 favorites]


The best tip I ever received for vim:
imap jj

Now, to escape insert mode you just type 'jj' really quickly. If you actually need two j's, type one then wait a second before typing the next.

It will change your Vim'ing. More here.
posted by spiderskull at 11:31 AM on December 7, 2009 [6 favorites]


So the last four posts have been:

1a) Women
1b) with guns
2) Marijuana legalization
3) Green Party Redux
4) vi vs Emacs

My hats off to the mods.
posted by DU at 11:31 AM on December 7, 2009 [5 favorites]


M-x this-will-end-well
posted by xthlc at 11:31 AM on December 7, 2009 [7 favorites]


Dammit... Mefi broke it. Should be:
imap jj <Esc>
posted by spiderskull at 11:32 AM on December 7, 2009


I'm kinda partial to GNU Moe, although the stuff I do with it is pretty lightweight; for serious work I use jedit.
posted by XMLicious at 11:33 AM on December 7, 2009


Oh, also get a buffer explorer and map it to \\. The fuzzy search plugin is pretty useful if you're working with big files that you know the elements of.

If you're doing text-based editing (i.e. LaTeX), gqap will automagically wrap your current paragraph. Just make sure you have a newline surrounding it. Also works for C/C++ comment blocks and other well-implemented syntaxes.
posted by spiderskull at 11:35 AM on December 7, 2009 [1 favorite]


While we're on the topic of editors, go check out these free monospace coding optimized fonts. Crisp and Dina are my faves.
posted by spiderskull at 11:36 AM on December 7, 2009 [8 favorites]


This doesn't have to be some big emacs vs. vi flamewar. I mean, someone else can make a shitty emacs post.

OH SNAP!?
posted by chunking express at 11:37 AM on December 7, 2009


spiderskull: yep, I've got that one in mine. Though, I've had it bite me when pasting irregular text and forgetting to set paste mode. "Why the fuck is this RSA key not working??? Oh wait. It's short a few lines."
posted by kmz at 11:38 AM on December 7, 2009


I've been writing Actionscript in vim for about seven years now, which is an unholy combination of weird things. Imagine my joy when the Flex IDE came out and I could build from inside vim.

I also ended up working on a Silverlight project for a while where the company paid for a plugin to make Visual Studio act like vim. That was funny.

My fave vim tip is proper use of recording. Automating stupid repetitive tasks has saved my sanity on several occasions.

% s/suck/awesome/g
posted by lumpenprole at 11:38 AM on December 7, 2009


I love that gmail supports 'j' and 'k' for up and down and '/' for search. It makes my vi trained fingers very happy.
posted by octothorpe at 11:40 AM on December 7, 2009


Right, but does it have C-x M-c M-butterfly?
posted by leotrotsky at 11:41 AM on December 7, 2009


I wonder if Mefites, in aggregate, prefer vim over emacs. Of course, there's a pretty good chance the latter group browses Mefi from inside emacs...
posted by spiderskull at 11:48 AM on December 7, 2009


I'm really not trying to start a flamewar. What consenting adults edit with in the privacy of their own computers is none of my business.

Seriously though, if you prefer emacs, that's fine. I think we can all pick on pico.
posted by kmz at 11:49 AM on December 7, 2009


Is it bad that I pretty much already know most of the tips on Daily Vim?

Also, someone in my lab asked me how to do something in Vim that I do regularly, and I completely blanked. I had forgotten which keys I was pressing, so I had to actually do it to figure out the right key combination.

Seriously though, if you prefer emacs, that's fine. I think we can all pick on pico.

I knew a guy who -- no joke -- wrote and edited something like 1000+ lines of Verilog in Notepad. He was insane.
posted by spiderskull at 11:53 AM on December 7, 2009


vim is great, but I always end up in Notepad++
posted by swift at 11:55 AM on December 7, 2009 [1 favorite]


Vim as IDE? OK, there's such a thing as taking a joke too far....
posted by gurple at 11:57 AM on December 7, 2009


Oh, more awesomeness. I hate having search highlighting stay on, so I map Enter in Normal mode to temporarily disable highlighting:

nnoremap <CR> :nohlsearch<CR>/<BS><CR>
posted by spiderskull at 12:04 PM on December 7, 2009


Yes, vim is powerful. Emacs is powerful. I've written acres of code in both of them. On everything from VT52s (look ma, no arrow keys!) to the Linux workstation sitting over there in the corner.

But you know what? The rest of the universe has standardized on a relatively simple form of text editing that isn't modal and/or doesn't use 12 modifier keys. Modifying your browser or e-mail client, assuming you are not using VM or GNUS of course, to work like vi is like cutting a hole in your car and running like Fred and Wilma. I use Eclipse* now. It is perfectly adequate, and I don't accidentally type ZZ into my e-mails anymore.

* feel free to derail into eclipse and netbeans, if the level of vitriol seems too low
posted by Ella Fynoe at 12:05 PM on December 7, 2009


I still use vim as my IDE at work. Some python-specific tips:

" ,r = run script
" ,R = run script and add output to buffer
" ,e ,E = same but prompt for arguments first
let mapleader = ","
nmap <leader>r :w<CR>:!/usr/bin/env python %<CR>
nmap <leader>R :w<CR>!!/usr/bin/env python %<CR>
nmap <leader>e :w<CR>:!/usr/bin/env python %·
nmap <leader>E :w<CR>!!/usr/bin/env python %·

" the builtin syntax highlighting is more colorful with this
let python_highlight_all = 1

" make hard-tabs and trailing whitespace visible
set list listchars=tab:»·,trail:·,extends:$,nbsp:=

" tab key behaves just like actual tabs, but inserts spaces in underlying file.
set sw=4
set et
set smarttab


Also check out snipMate (a port of TextMate snippets for some pretty advanced tab completion that's language-aware) and python_editing.vim, which generally improves class/function folding and block-level awareness.
posted by cj_ at 12:07 PM on December 7, 2009


Notepad++ doesn't run in a terminal. I like Textmate when i'm on a Mac, though I barely know how to do anything fancy in it. Even my Vim usage is apparently particularly lame. I had no idea people put so much thought into remapping the ESC key. That wiki page is amazing.
posted by chunking express at 12:10 PM on December 7, 2009


Yeah, I use vi/vim, notepad++, or textmate. I can't believe folks still get baited into which is better ... Emacs or vi.

although I would love a vi metafilter comment plugin.

:wq
posted by YoBananaBoy at 12:11 PM on December 7, 2009


> But you know what? The rest of the universe has standardized on a relatively simple form of text editing that isn't modal

That's great for the rest of the universe, I am happy for them. As a ridiculously fast touch-typist I prefer modal input to constantly futzing with a mouse. Sorry that bugs you.

And yes you can use vim as an IDE. From code execution, syntax tab completion, and access to the standard library docs. I don't actually need anything else.
posted by cj_ at 12:11 PM on December 7, 2009 [2 favorites]


My favorite vim tip: remap caps lock to escape (in X or windows so that it's useful in other programs, too). Other tips: map ,v to edit .vimrc; sometimes syntax gets messed up in a long file, map SY to :syntax sync fromstart to fix; there is a pretty good outliner plugin for vim; there is a file browser called NERDTree that works well; you can map some insert mode shortcuts to move around e.g. one word back/forward, ctrl-h,j,k,l to move one char, alt-hjkl to move 5-7 chars; ctrl-d for Del, ctrl-a for End; imappings for save, change word, end+enter; comment multiple lines: vnoremap # :s/^/#/[CR] ; uncomment - vnoremap T :s/^#//[CR] (with angle brackets, of course).

I heart Vim.
posted by rainy at 12:13 PM on December 7, 2009


I think we can all pick on pico.

I edit things in pico (or nano). I don't use vi or emacs because I don't spend my life editing text files, I just need to do it once in a while, so taking the time to learn all the arcane commands is really not worth the effort.

Most of the time I use Textwrangler, to be honest.

I'll admit that seeing the stuff someone who knows vi can do in a short amount of time is pretty cool. But I still don't have a good reason to learn how to do it myself.
posted by caution live frogs at 12:14 PM on December 7, 2009 [1 favorite]


Invader Vim!
posted by ...possums at 12:18 PM on December 7, 2009 [3 favorites]


cj_: great python tips.. I didn't know about some of these.

Ella Fynoe: Yeah, the world standardized on a modeless text editing. guess why.. because most people will write a couple lines at a time and shoot off an email. That's quite a different thing than editing code for 5+ hours a day. By your logic, if most people found it sufficient to use a cell phone keypad to do all their typing, I'd have to use my nokia cell phone to edit 200k lines of code, as well. I see Vim as an Editing program, not a primarily Typing program, like wordpad. (And: i'm scared to leave homerow. There're dark shadows outside.)
posted by rainy at 12:23 PM on December 7, 2009 [1 favorite]


But I still don't have a good reason to learn how to do it myself.

Because sometimes you sit down on a 30 year-old stock UNIX box like some obscure piece of SYS V or SVR4 and you just want to edit the damn file and the only editor is vi.

I learned vi the year I had literally no choice. It was writing code in vi or deciding not to hand in any coursework. University of Technology, Sydney, Australia, you stink.

Also, I used to do training on a variety of weird unix boxes. Intro to C and such. Some weeks I got shunted onto the weird machines when we were full up in Solaris sysadmin classes so I had to use the AIX box. I am not going to even try to download a version of pico or whatever that compiles for AIX.

vi is everywhere. And the next time you're trying to reconfigure an IRIX box with velociraptors kicking down the door you'll wish you had learned how to use it.
posted by GuyZero at 12:24 PM on December 7, 2009 [8 favorites]


Metafilter supports 'j' and 'k' as well, if you hadn't noticed. Vimperator is cool, but it breaks the keybindings that are already there in gmail, greader, metafilter, etc. There is a way to switch the input mode, but that was too annoying to keep doing. Maybe we can't agree on vi vs. emacs, but any sane person will agree: The mouse is inefficient and must be banned!
posted by mike_bling at 12:25 PM on December 7, 2009 [6 favorites]


There are also some really tasty .vimrc files on github, search for 'dotfiles' and you should see them.
posted by mike_bling at 12:29 PM on December 7, 2009 [1 favorite]


VIM is the One True Editor. Period. There Is No EMACS.

EMACS weenies can't even claim Zippy the Pinhead anymore. GNU EMACS took out m-x yow and psychoanalyze-pinhead due to copyright concerns, and now the only quote you get is "copyright is BRAIN DEAD" or something like that.
posted by DecemberBoy at 12:31 PM on December 7, 2009


Metafilter supports 'j' and 'k' as well, if you hadn't noticed.

!!

I hadn't noticed.
posted by kmz at 12:31 PM on December 7, 2009


Also, I have a ton of cool .vimrc stuff if anyone's interested. Functions to auto-generate templates for Python classes, HTML documents, stuff like that.
posted by DecemberBoy at 12:32 PM on December 7, 2009


YoBananaBoy and other VIM fans! Check out the It's All Text add-on for Firefox! You can now edit your comments (or any web page textarea) using VIM (or, in theory, another editor)!
posted by amtho at 12:38 PM on December 7, 2009 [1 favorite]


GuyZero: Because sometimes you sit down on a 30 year-old stock UNIX box like some obscure piece of SYS V or SVR4 and you just want to edit the damn file and the only editor is vi.

Well, if ever confronted with such a hypothetical situation, I'd ask the that fly out of my ass to pull up the man page, or better yet, grab a nicely-formatted cheat sheet from the web. Then, I could just tell the elephant in the room to do the job for me.

Funny how few people make the same argument regarding motif or lynx.
posted by KirkJobSluder at 12:41 PM on December 7, 2009 [1 favorite]


That's great for the rest of the universe, I am happy for them. As a ridiculously fast touch-typist I prefer modal input to constantly futzing with a mouse. Sorry that bugs you.

I wasn't judging you, cj_ - I'm glad it works for you, and it worked for me as well when I wrote code full-time. Especially when I was using a terminal that didn't have a mouse. :) I just don't do that anymore, and the wetware context switching is more annoying than using the mouse. Plus I find there are times when I should be thinking about what I'm going to do next rather than just banging it out, and the "wide view" from the IDE is more amenable to that. It's a matter of style, or perhaps age...
posted by Ella Fynoe at 12:41 PM on December 7, 2009


s/the that/the monkeys that/ of course.
posted by KirkJobSluder at 12:43 PM on December 7, 2009


vi sucks. Everyone knows it. Once you go to TextMate or Notepad++ or jedit or some other user interface not cobbled together with dinosaur spit and precambrian bailing wire, you generally aren't going back.

But, when the server is flat on its back, and you need to mess with the host file to get it limping back into production, you need to know vi. It's on everything, absolutely everything, from the latest Cray supercomputer running CLE to the old DEC running Ultrix that's been quietly keeping the manufacturing database running for a decade until someone thought it would be a good idea to reboot it. It runs via SSH or straight on the terminal port, and when it hits the fan, you need to be conversant, if not fluent, in vi.
posted by Slap*Happy at 12:43 PM on December 7, 2009 [2 favorites]


> I wasn't judging you, cj_

Text editors are serious business. Don't even get me started on FreeBSD vs. Linux.
posted by cj_ at 12:46 PM on December 7, 2009


This one is kind of silly but I use it all the time: vpgq (vp - visual mode, highlights the paragraph and then gq - reformats according to your word wrapping). I do a lot of tex in vi, and this often comes in handy.

You rule kmz!

<3 kms
posted by kms at 12:48 PM on December 7, 2009


While we're talking about text-editors: In windows, I like e, which is a Windows port of TextMate.
posted by JDHarper at 12:50 PM on December 7, 2009 [1 favorite]


I can't believe all the strong opinions on text editors. I had you guys pegged as a bunch of liberal arts types. I feel like I'm on Reddit or something here.

That said, I work in Emacs all day, every day, because when I try something else (including vim) it always makes me sad and drives me back to Emacs.

Once you goes 'macs, you never goes backs.
posted by edheil at 12:54 PM on December 7, 2009 [1 favorite]


Funny how few people make the same argument regarding motif or lynx.

Because no one needs to use motif or lynx to make the system go again or to do basic sysadmin tasks like changing the IP address because the system doesn't have a functional dhcpd or whatever the hell needs doing.

I'm not saying it happens every day but it's something that's useful to know how to do.

By all means, use Visual Studio all day every day and convince yourself you know something about computers.
posted by GuyZero at 12:54 PM on December 7, 2009


although I would love a vi metafilter comment plugin.

I write all my comments in vi using It's All Text. This adds an "Edit" button to every text widget that will pop up an xterm with vi containing the contents of the text box. Save the file and it refreshes the text box.

Magic!

jsvi is now GPLv3, which means that it won't work for a hosted site like Meta. I hacked up a version that would work with MediaWiki themes to allow something that feels like vi as an optional editor, but never polished it enough for wider distribution.
posted by autopilot at 12:58 PM on December 7, 2009 [1 favorite]


Yeah, after (erm) 20 some years of working on Unix boxes, I'm finally _finally_ starting to be seriously tempted to get truly comfortable with vi, because very few boxes in our environment have emacs, and tramp-mode/sshfs/filers are usually unavailable on the weirdest of them. (Opsware Global Shell, I'm looking at you.) While I can tweak stuff in vi, I can't bring myself to code anything longer than hello_world in it. I guess I'm still trying to get my head around this whole _modality_ thing. I'm in an editor, I want to edit, I don't want to have to tell it I want to edit now, I did that when I hit return on "vim file". *sigh* Baby steps. I think the big things I need to figure out are:

a) Is there anything like cperl-mode? I don't want to worry about keeping track of my indent level on my own, I have a computer with tons of cycles to throw at that sort of problem. Similarly, making sure my braces match where I expect them to. (and syntax highlighting, too.)
b) How in hell do I manage the clipboard? I'm used to setting a mark, killing stuff I want to duplicate to the scratch area, then yanking it back as often as I want. I've never figured that out in vi.
c) Is there any sort of notion of undoing my most recent changes in a stepwise manner? I'm really used to just hitting ^Xu to undo back to a sane state, and right now my main way of handling screwups in vi ends up with a frustrated :q! and starting over.
d) is the probably the easiest complaint, cursor management. ^A, ^E, M-< & M-> for beginning of line, end of line, beginning of document and end of document are pretty hard wired at this point, and if I know exactly where to go I can usually M-goto-line[number] to go there all sweet and easy. (hell, I ^S[word] at the beginning of the line to get to my edit point, which works nicely with emacs' live searching.)

I mean, I figure vim has analogs for almost all of this, but all of the vi-related tutorials are either coming from a "So you want to learn LaTeX and vi!" standpoint, or they assume you're already familiar with vi, but here's some snazzy tips you might've missed in the last 30 years.

(And I suspect emacs's chording is less of an issue for people who don't touch type properly anyway - ctrl is right there under my left pinkie, but esc is sort of a reach and adjustment that takes me entirely out of my "home row" and forces a reset.)
posted by Kyol at 1:11 PM on December 7, 2009 [1 favorite]


Slap*Happy: Unix system administrators << the total population of people who use text editors.

GuyZero: Because no one needs to use motif or lynx to make the system go again or to do basic sysadmin tasks like changing the IP address because the system doesn't have a functional dhcpd or whatever the hell needs doing.

For that matter, you don't need vi either as there are at least three other tools that can be used to do the same job. But yes, as many systems are set up to helpfully launch X and put you into twm mwm, you might certainly have to negotiate with it to get a terminal. You might even need such quaint software as lynx and gopher to troubleshoot some services.

GuyZero: I'm not saying it happens every day but it's something that's useful to know how to do.

Yes, and so is knowing how to butcher a chicken, something I'm quite glad I don't have to do on a daily basis.

GuyZero: By all means, use Visual Studio all day every day and convince yourself you know something about computers.

The difference between you and me is that I actually know something about computers, and don't need to bullshit about my personal quirky choice of editors in order to claim some sort of nerd credibility.
posted by KirkJobSluder at 1:12 PM on December 7, 2009


ed is the standard editor.

Damn kids, get off my lawn.ZZ
posted by jewzilla at 1:15 PM on December 7, 2009 [5 favorites]


mike_bling: 'Vimperator is cool, but it breaks the keybindings that are already there in gmail, greader, metafilter, etc.'

Look around for the 'feedSomeKeys_2' plugin for vimperator. It allows you to have automap when you switch tabs, so you can do this (maps j/k/e/etc at gmail, and switch back on other tabs):
au LocationChange .* :fmapc
au LocationChange mail\.google\.com :fmap! j k a e g c r

Vimperator is handy, if only for C-6 to switch between tabs, marks, and C-a to auto increment urls. Oh yeah, it takes up a lot less screen space, which is huge on netbooks. Pure win.
posted by rider at 1:16 PM on December 7, 2009


And as a hint, I don't need a cheat-sheet to get around in vi.
posted by KirkJobSluder at 1:16 PM on December 7, 2009


I do all my editing in Vigor.
posted by davejay at 1:17 PM on December 7, 2009


d) is the probably the easiest complaint, cursor management. ^A, ^E, M-<> for beginning of line, end of line, beginning of document and end of document are pretty hard wired at this point, and if I know exactly where to go I can usually M-goto-line[number] to go there all sweet and easy.

^, $, :0, G. To go to a specific line n, :n. ^ and 0 are similar, although 0 goes to the very first column, while ^ goes to the first non-white space character.

Years ago I was an emacs user, but these days one of the first things I type in a terminal window on a strange machine is 'set -o vi'.
posted by autopilot at 1:20 PM on December 7, 2009


pico FOREVER!
posted by delmoi at 1:20 PM on December 7, 2009 [2 favorites]


vi sucks. Everyone knows it. Once you go to TextMate or Notepad++ or jedit or some other user interface not cobbled together with dinosaur spit and precambrian bailing wire, you generally aren't going back.

It's really about what you know and use. Every time I try Eclipse or TextMate or BBEdit or what-have-you, I always run back to vi as quickly as I can, for the same reason I only last a few days with a dvorak keyboard before I run screaming back to qwerty, despite its known shortcomings.

how interesting; firefox highlights 'qwerty' as misspelled, but not 'dvorak'
posted by davejay at 1:21 PM on December 7, 2009


Nethack is the one real text editor. All the non-roguelike text editors are but pale shadows.
posted by sebastienbailard at 1:31 PM on December 7, 2009 [3 favorites]


$ cat > file

is the one true editor. All the rest are but crude imitations.

Well, someone was bound to say it eventually
posted by nonspecialist at 1:39 PM on December 7, 2009 [1 favorite]


$ cat > file

Bahh, real programmers don't bother with files, they just pipe their text right to the compiler.
posted by octothorpe at 1:47 PM on December 7, 2009 [5 favorites]


Once you go to TextMate or Notepad++ or jedit or some other user interface not cobbled together with dinosaur spit and precambrian bailing wire, you generally aren't going back.

If your work involves ssh'ing onto various *nix servers all day, this isn't really an option. While I much prefer a full featured, graphical IDE, being familiar with the vi environment is a good skill to have.
posted by sophist at 1:58 PM on December 7, 2009


kyol:

a) put 'filetype on' in your .vimrc and it will automatically detect your filetypes and set up indentation and syntax highlighting.
b) With text selected, 'y' yanks it, and 'p' puts it. Deleting text with 'd' also yanks it.
c) 'u' does stepwise undo. Ctrl-R is redo.
d) has already been answered!
posted by zsazsa at 2:01 PM on December 7, 2009


1. ctrl-s: map to 'save' in .vimrc (useful if you do a lot of change/save/change/save)
imap :w
map :w

2. ctrl-n: autocomplete (saves a lot of typing, like 'ctrl-r' in *nix)

3. retab! : convert spaces to tabs (fix Python whitespace issues)

4: set bs=2 " .vimrc - allow backspacing over everything in insert mode

5. ctrl-o + cmd : quit insert for just one command, e.g. ctrl-o + A = quit insert, go to end of line, enter insert

6. dt : delete to char
diw : delete in word, di( : delete in parens, di" : delete in set of quotes

I hate vim and will always hate vim -- the keybindings are SO STUPID, the UI is insane -- but for various reasons I've resigned myself to using it (gvim from a mac ssh'd into *nix box at work).

It's hard to break habits once acquired so I recommend printing out the tips that seem most useful and forcing yourself to spend part of each day thinking 'before I do what I'm about to do, is there a better way to do it?"

posted by jcruelty at 2:05 PM on December 7, 2009


GuyZero: vi is everywhere. And the next time you're trying to reconfigure an IRIX box with velociraptors kicking down the door you'll wish you had learned how to use it.

Surely you mean jot.
posted by demiurge at 2:06 PM on December 7, 2009


I miss jot, and that crazy 3d shape editor that didn't seem to do anything useful.
posted by KirkJobSluder at 2:29 PM on December 7, 2009


The difference between you and me is that I actually know something about computers, and don't need to bullshit about my personal quirky choice of editors in order to claim some sort of nerd credibility.

Do you want to learn computers? Try our video course to learn computers today. Call now!
posted by swift at 2:56 PM on December 7, 2009 [1 favorite]


My dirty little secret is that I use TECO
posted by gadha at 2:59 PM on December 7, 2009


Also, if loving vi too much is a crime then I am guilty as charged. GUILTY OF LOVE.
posted by GuyZero at 3:00 PM on December 7, 2009 [1 favorite]


Bahh, real programmers don't bother with files, they just pipe their text right to the compiler.

Or you can just use this incredibly versatile program.
posted by one more dead town's last parade at 3:00 PM on December 7, 2009 [1 favorite]


Whatever you think about vim, you should seriously consider
sponsoring the project.
posted by effbot at 3:06 PM on December 7, 2009


Bahh, real programmers don't bother with files, they just pipe their text right to the compiler.

Feh!

Real programmers don't even bother with a compiler, they just toggle the bits on the spinning media with a small magnet, by hand.
posted by nonspecialist at 3:07 PM on December 7, 2009 [2 favorites]


Also, if loving vi too much is a crime then I am guilty as charged. GUILTY OF LOVE.

vim is a great editor. I used it pretty much exclusively for about two years before I switched to emacs primarily for the common-lisp and R shells. And now that I'm no longer doing common-lisp or R, I'm happy with TextMate, TextWrangler, and Dreamweaver.

It's a tool that every unix system administrator should learn. But that's only a small fraction of the population.

And just because you can work within a minimal UNIX environment doesn't mean that you have to do so on a routine basis.
posted by KirkJobSluder at 3:24 PM on December 7, 2009


Slap*Happy: Unix system administrators <>

I am aware of this... my post wasn't for the benefit of lesser lifeforms.

Programmers. Pfeh. Give them an inch, and they'll round it out to the nearest centimeter.

posted by Slap*Happy at 3:26 PM on December 7, 2009 [1 favorite]


Errrm. /o isn't the same as /i. Who knew?
posted by Slap*Happy at 3:29 PM on December 7, 2009


@GuyZero

What do you have against EMACS? It is an excellent and powerful program.
It only lacks a good editor...
posted by yoyo_nyc at 3:43 PM on December 7, 2009 [3 favorites]


vi sucks. Everyone knows it.

First off, are we talking about Bill Joy's vi or Bram Moolenaar's?

Once you go to TextMate or Notepad++ or jedit

I think TextMate deserves some respect, and actually some novel-ish features, but not enough to give it an appreciable advantage over vim. I suppose it's possible that Notepad++ and jEdit have substantial a featureset I'm unaware of since I last checked them out roundabout 2003, but if not, I don't think they're even in the same ballpark.

There's a reason why it's vi vs emacs, and not anything else. I'm sure part of my preference for vi comes from the fact that I got many of the commands into my muscle memory when I was 16, but over 20 years and a dozen or so other setups from Turbo/Borland IDEs, through THINK, BBEdit, MPW, Dreamweaver, Homesite, Eclipse, XCode and probably a few others I'm forgetting, you'd think if vi sucked so much I would have found something in there that should have been a clear favorite. Instead I generally find layers of dialogs and menus for commands I already have burned into my fingers, and only occasionally a nifty truly special feature, which has never been compelling enough to abandon it (particularly since as vim moves on, it has a neat way of acquiring the nicest features).

Someday I might invest in Emacs or something like TextMate, but for the moment, not only does not using it suck, I find it generally a better experience than the alternatives.
posted by weston at 3:47 PM on December 7, 2009 [1 favorite]


but over 20 years and a dozen or so other setups from Turbo/Borland IDEs, through THINK, BBEdit, MPW, Dreamweaver, Homesite, Eclipse, XCode and probably a few others I'm forgetting

How dare you forget the second-best editor ever, Brief???

The only editor that I've ever used that can cut & paste columns of text in addition to rows.
posted by GuyZero at 3:51 PM on December 7, 2009


columns in emacs:

Cutting and pasting rectangular regions of a document is especially useful when you need to edit the contents of multi-column tables. To perform this operation in Emacs, follow these steps:

1. Move the cursor to the upper-left corner of the area you want to cut.

2. Set the mark by pressing C-@ or C-SPC . If your terminal does not allow this keystroke, you can also set the mark by pressing: M-x At the prompt, enter: set-mark
3. Move the cursor one space beyond the lower-right corner of the region you are going to cut.

4. Delete the rectangle into the kill buffer by pressing: M-x At the prompt, enter: kill-rectangle
5. Move the cursor to the upper-left corner of the area where you want to paste the rectangle.

6. Retrieve your text by entering: M-x yank-rectangle

-http://kb.iu.edu/data/afhg.html
posted by sebastienbailard at 4:02 PM on December 7, 2009


Ctrl-v will let you select in columns of text in Vim.
posted by zsazsa at 4:30 PM on December 7, 2009


GuyZero -- vim can also do rectangular selection. Hit ^V to go into Visual Block mode and then hjkl around to select the region.
posted by autopilot at 4:36 PM on December 7, 2009


The only editor that I've ever used that can cut & paste columns of text in addition to rows.

There are many, many editors which handle this. I recently found out it is even the Apple recommended behavior of option-click selection on OSX for an editor (I can verify it works in TextEdit, BBEdit and native terminal, don't have much else on this comp to check against).
posted by sophist at 4:40 PM on December 7, 2009


You know, when the vi vs. emacs wars come, you can count on me to bring a copy of Vim and a bad attitude. It is still the first text editor I reach for when I need a text editor. (You don't want to know how many filetypes have their open/edit actions defaulted to Vim. If it is vaguely text, it opens in Vim.) For years, it was all I needed. I wrote letters to my friends in vi. I still use it for email when I'm not on the Mac.

But after years of being a maintenance coder with more and more of that time being spent in Java, I have gone completely over to Eclipse. No matter what plugins you have, or how large your .vimrc gets, a full dedicated IDE is just so much more powerful and useful.

Only a small proportion of coding is actually writing text, or even passively reading it. I need to see a class or method in terms of its hierarchy and call graph. I need to be able to show the hierarchy, some source, and a list of methods and Javadocs and search results open at the same time. And we all need to be able to drive through the source sensibly when we have our inevitable "agile" visits to another cubicle.

And there is a built-in debugger that understands incremental builds. I'm not aware of any vi/emacs makefile integrated shell trick that does that.

I've seen some folks at work get Emacs (wuzzat?) to behave pretty closely to Eclipse, but there is a fair amount missing. I assume Vi would be in a similar boat.

Don't get me wrong: I love Vim to pieces and I could get by for a day or two with Vim alone. But I'd be sunk if I had to go back to my old vi habits for an entire release cycle again, no matter how fancy the plugins were.

As usual, mileage with vary, but this die-hard vi user couldn't live without Eclipse these days.
posted by clvrmnky at 4:49 PM on December 7, 2009 [1 favorite]


All very compelling, but if I was going to choose a text editor based on the average quality of writing in advocacy of it, I would be using ed.
posted by sfenders at 4:56 PM on December 7, 2009


I must say that as a law student, vimoutliner (alluded to above[?]) has been a real lifesaver: http://www.vimoutliner.org/.

I got a kick out of busting out 256 color vim/rxvt-unicode in 1L torts :)
posted by print at 5:06 PM on December 7, 2009 [1 favorite]


I always feel like a deviant when these vi vs. emacs vs. whatever discussions pop up: when I'm not on a Mac, I use joe, for that not-quite-WordStar, not-quite-emacs, not-quite-pico feel.
posted by a little headband I put around my throat at 5:23 PM on December 7, 2009


While Eclipse is great for autocomplete of method and functions names while writing code, what it and most GUIs fail at are common editing tasks, say converting a list of statements to a list of arguments:
foo();
bar();
baz();
quuz();
into
foo,
bar,
baz,
quuz,
In vi, I go to the opening ( by hitting f(, then change the rest of the line to a comma by hitting C,Escape. And then I go to the next three lines and do it again by hitting j.j.j. to repeat the edit. This last bit, the j. sequence is very, very fast and can be repeated for how ever many lines there are. How many steps does it take to do this in your editor? Don't you get tired of hitting End, Backspace, Backspace, Backspace, Backspace, Coma, Down-arrow, End, Backspace, Backspace...? Or worse, reaching for the mouse to reposition the cursor after each edit?

It makes me feel like I'm trapped in a Fisher-Price toolbox if I don't have a real editor available. It isn't just about counting keystrokes (although that is part of it), it is about how much does the editor help me with the repetitive parts of editing code. If there is anything more complicated than a single edit that needs to be repeated, I can define an ad-hoc macro with q in as much time as it takes to do the first one. For maintenance programming, this ability to horse around text makes my life much easier.

But at the end of the day, much of it is just familiarity. After two decades, the vi keys are in muscle memory and I'm not going to invest the same amount of time in learning a new editor. Twenty years from now we had better have something that is an improvement over pounding on a glorified keypunch machine to express our desires to the computer.

(I'd also be remiss if I did not mention bvi, the binary vi editor for all your hex editing needs)
posted by autopilot at 5:37 PM on December 7, 2009 [2 favorites]


I wish there was a text editor that had the powerful features of vim and emacs but not their stabby user interface. Having to memorize ridiculous shortcut combinations with no way to learn or look them up in menus is not my idea of fun text editing.
posted by azazello at 5:39 PM on December 7, 2009


#define BEGIN {
#define END }
posted by flabdablet at 5:40 PM on December 7, 2009


autopilot, in any number of sane text editors, the sequence is: ctrl-r (); , enter enter enter enter. That's all. Pretty much a moot comparison.
posted by azazello at 5:42 PM on December 7, 2009


Dammit, beaten to TECO.

Vi and Emacs need gang colors, that's all I'm saying.
posted by Skorgu at 5:43 PM on December 7, 2009 [1 favorite]


(metafilter ate my tab)
posted by azazello at 5:43 PM on December 7, 2009


After two decades, the vi keys are in muscle memory...
posted by autopilot


eponysterical!

I wish there was a text editor that had the powerful features of vim and emacs but not their stabby user interface.

There should be some sort of law of computer UIs where power/flexibility and stabbiness are inversely correlated.
posted by GuyZero at 5:43 PM on December 7, 2009


Nah, there are graphical frontends for both now with menus and whatnot. I dunno about Emacs, but gvim is pretty great for learning with — most of the basic commands and some of the common combinations are findable in the menus, and every menu item's got the corresponding keyboard shortcut next to it, so eventually you wind up learning the shortcuts without trying.
posted by nebulawindphone at 5:55 PM on December 7, 2009


Anybody else cut their teeth on XEDIT?

posted by flabdablet at 6:05 PM on December 7, 2009


The best tip I ever received for vim:
imap jj <esc>
Now, to escape insert mode you just type 'jj' really quickly. If you actually need two j's, type one then wait a second before typing the next.

That would drive me bonkers. j is "jump to next line" and I mostly navigate up and down via repeated j's and k's.
posted by Creosote at 6:36 PM on December 7, 2009


But after years of being a maintenance coder with more and more of that time being spent in Java, I have gone completely over to Eclipse

While I wasn't thusly charmed, I'd grant that there are some development platforms for which the advantages of an IDE oriented on it are significant enough that they're worthwhile even if you lose some editor productivity. I'm given to understand that you can do Cocoa / Obj C development just fine w/o XCode, but XCode's such a boost for someone only ankle deep in the platform that I generally forgo my favorite editor if I'm working on that stuff. And I think Java's in the same boat. As Steve Yegge more or less says, the language itself and the culture around it almost require certain kinds of tools. If I did more Java development, it's pretty likely I'd become an Eclipse or NetBeans user, just as I took to JBuilder the last time anyone paid me to work in Java (yeah, it's been a while).
posted by weston at 6:39 PM on December 7, 2009


That would drive me bonkers. j is "jump to next line" and I mostly navigate up and down via repeated j's and k's.

That's what it does in normal mode. They're talking about changing what it does in insert mode.
posted by nebulawindphone at 6:56 PM on December 7, 2009


This is vi! I know this!
posted by SPrintF at 7:20 PM on December 7, 2009


autopilot: Don't you get tired of hitting End, Backspace, Backspace, Backspace, Backspace, Coma, Down-arrow, End, Backspace, Backspace...? Or worse, reaching for the mouse to reposition the cursor after each edit?

No because I do replace-in-selection.

It makes me feel like I'm trapped in a Fisher-Price toolbox if I don't have a real editor available.

Whee! Does anyone really think they are doing vim a favor by posting such earnest silliness?
posted by KirkJobSluder at 7:46 PM on December 7, 2009


Maybe y'all can help me with a nagging vim problem:

"back in the early days of Vim" (cough), I could record a macro into "a", then replay it with "@a". So far so good. Back in those days, I could replay it again with ".", and 20 more times with "20."

"sometime in the last few years" that behavior changed, so that "@a" works fine, but a subsequent "." only redoes the last thing the macro did, so to do something 20 more times, I have to enter the rather more awkward "20@a". Can I recover the old behavior with a setting?

On another topic, speaking as one of the few folks I know of who are both Dvorak keyboard users, and vi fans, I have to say that even though I somewhat miss the convenience of the layout of the "hjkl" keys, it's not nearly as bad as you'd guess, because even messed up as the location of those letters is, they're still spatially sensible.
posted by dylanjames at 7:57 PM on December 7, 2009


Whoah.... In trying to duplicate dylanjames's problem, I got vim to segfault. That is the first time I've seen vim segfault, well, ever, that I know of and I've been using vi/vim pretty much daily since 1989 or so. Unfortunately ulimit default was such that I didn't get a core file.

Couldn't duplicate the segfault when I tried to do it again though.

It involved recording a macro of several steps, using the macro a few times, doing ":set compatible" then doing ":20@a" (which makes not much sense.)

I did duplicate dylanjames's problem though.
posted by smcameron at 8:32 PM on December 7, 2009


That would drive me bonkers. j is "jump to next line" and I mostly navigate up and down via repeated j's and k's.

Creosote -- the shortcut is only for Insert mode. Normal mode is untouched, so navigation around the text is exactly the same. This trick saves you from having to hit Escape (thereby leaving home row) , or doing the other workarounds (like remapping Caps Lock to Escape).
posted by spiderskull at 8:48 PM on December 7, 2009


Ok, my first example was a bit too trivial and could be done with search-and-replace. But there are lots of similar tasks that can't be solved quite as easily with replace-in-selection without coming up with a regex to match the input text, such as if the text at the end of the line was not exactly the same:
foo(1);
bar(2);
baz(3);
// ...
Another common programming task that I struggle with in non-modal editors is to reverse the order of two adjacent lines of code. In vi it is ddp to delete the line and then paste it below the current line. Home, shift-End, ^C, Down, Home, ^V is not just loads more keystrokes, but they are far off from the home row and feel like a speed bump to me, especially on keyboards that don't have dedicated Home and End keys (Apple, I'm looking at you).

Does anyone really think they are doing vim a favor by posting such earnest silliness?

Yes, because it helps folks who are curious about vi understand why anyone would choose to use it. If most readers' only experience is "wtf? how do I just quit this?", then perhaps hearing from folks who like it can help them see why a thirty year old editor still has fans.

It is a statement of fact that I do feel far less productive having to type into a text box with limited flexibility (like this one) than using my editor of choice. In any event, this post is all about vi, its variants, tips and proselytizing. The emacs post is two doors down, on the left. ed users are welcome to stay, so long as they limit the number of comments about the "one true editor" thing.
posted by autopilot at 8:49 PM on December 7, 2009


MeTa.
posted by ALongDecember at 8:50 PM on December 7, 2009 [2 favorites]


Once you go to TextMate or Notepad++ or jedit or some other user interface not cobbled together with dinosaur spit and precambrian bailing wire, you generally aren't going back
Eh, totally not true. These days I spend all my time in front of a Mac, but I'll often be simultaneously using XCode (for some coding), SubEthaEdit (often as a pager), vi(m) (for quickies), and Emacs (for other coding or for stuff on other machines), depending on what task I'm trying to perform. XCode's editor is pretty powerful but it's still really frustrating when you hit that functionality wall and you have to get out and push your Flintstonemobile when a programmer's editor would do what you want with only a little more effort.
I knew a guy who – no joke – wrote and edited something like 1000+ lines of Verilog in Notepad. He was insane.
Was he insane before he did that, too?
posted by hattifattener at 9:17 PM on December 7, 2009


I think it's strange that there's more than one reference to how old or dated Vim is -- that's just not true. It's constantly updated, there's new extensions all the time, and as processing power grows, so do options to leverage that for quick coding (i.e. fuzzy finder would've been slow as hell 10 years ago, but now works reasonably fast).

Don't let its minimalist, console-derived interface fool you into thinking it has become outdated.
posted by spiderskull at 9:45 PM on December 7, 2009


Was he insane before he did that, too?

He had to have been. He was not terribly efficient at writing code.
posted by spiderskull at 9:45 PM on December 7, 2009


So, all of you vi geeks, can you tell me why vim complains my terminal is too wide and how to fix it? I'm having to use cludges such as COLUMNS=120; vi $FOO on the console on my new system, and since I only use vi for quickies like editing config files and the like, it's getting tiresome.
posted by Dr Dracator at 11:02 PM on December 7, 2009


That is a weird error. What OS are you on, are you using vim, and what version? What is $TERM set to?
posted by cj_ at 12:43 AM on December 8, 2009


Hey, it turns out I was using Bill Joy vi, not vim. TERM is set to linux, it's the console on an intel video card with KMS enabled under Arch, supplying a hefty 210 columns. I installed vim and it apparently can handle it fine, it's just that vanilla Arch comes with plain vi.
posted by Dr Dracator at 2:16 AM on December 8, 2009



MeTa.
posted by ALongDecember at 8:50 PM on December 7


Man, you had me going there for a sec. I'd love to see what a metatalk thread about vi would be like.
posted by DarkForest at 5:03 AM on December 8, 2009


But there are lots of similar tasks that can't be solved quite as easily with replace-in-selection without coming up with a regex to match the input text, such as if the text at the end of the line was not exactly the same:

foo(1);
bar(2);


Which requires adding one character to the search pattern. Wow.

Yes, because it helps folks who are curious about vi understand why anyone would choose to use it.

So, people choose to use vi for reasons that are obviously bullshit? Good to know.

It is a statement of fact that I do feel far less productive having to type into a text box with limited flexibility (like this one) than using my editor of choice.

Of course, subjective feelings are notoriously unreliable indicators of actual productivity. But you don't really need to say anything else beyond "I use vi because I like it."

In any event, this post is all about vi, its variants, tips and proselytizing.

Well, false information is false information, and vi advocacy is harmed when its advocates emphasize falsehoods over its actual strengths.
posted by KirkJobSluder at 5:08 AM on December 8, 2009


nedit for the win!
posted by mr. strange at 6:36 AM on December 8, 2009


> Hey, it turns out I was using Bill Joy vi, not vim.

Yeah, people really should stop calling vim "vi", since they are two different editors. The latter is outdated. It doesn't help that Linux distros tend to install vim and alias it as vi.

KirkJobSluder: No one cares. Make an Eclipse thread or something.
posted by cj_ at 6:48 AM on December 8, 2009


Is there an emacs-speaks-statistics dotfile that does a good job? Mostly now I use Kate with vi keybindings enabled.
posted by a robot made out of meat at 9:51 AM on December 8, 2009


If you just can't get enough vi/vim in your life, there's viemu.
posted by wobh at 4:59 PM on December 8, 2009


Even I do not love vi that much.
posted by GuyZero at 5:12 PM on December 8, 2009 [1 favorite]


my vimrc maps nearly every letter to some command, such that my muscle memory makes using a plain vi painful. (Your browser may treat the file as binary since it has a lot of embedded escapes).
posted by ecco at 6:56 PM on December 8, 2009


This thread reminds me of a yellow plastic hornet trap, filled with orange soda.
posted by mecran01 at 1:56 PM on December 9, 2009 [1 favorite]


« Older It's Not My Party And I'll Fly If I Want To   |   Bubble Tanks Tower Defense Newer »


This thread has been archived and is closed to new comments