810 lines
44 KiB
HTML
810 lines
44 KiB
HTML
|
<!DOCTYPE html>
|
||
|
<html lang='en'><head><meta charset='utf-8' /><meta name='pinterest' content='nopin' /><link href='http://stevelosh.com/static/css/style.css' rel='stylesheet' type='text/css' /><link href='http://stevelosh.com/static/css/print.css' rel='stylesheet' type='text/css' media='print' /><title>Coming Home to Vim / Steve Losh</title></head><body><header><a id='logo' href='http://stevelosh.com/'>Steve Losh</a><nav><a href='http://stevelosh.com/blog/'>Blog</a> - <a href='http://stevelosh.com/projects/'>Projects</a> - <a href='http://stevelosh.com/photography/'>Photography</a> - <a href='http://stevelosh.com/links/'>Links</a> - <a href='http://stevelosh.com/rss.xml'>Feed</a></nav></header><hr class='main-separator' /><main id='page-blog-entry'><article><h1><a href='index.html'>Coming Home to Vim</a></h1><p class='date'>Posted on September 20th, 2010.</p><p>I'm a programmer. I work with text files for 6-12 hours every weekday so I care
|
||
|
about the text editor I use. If switching to a different editor can increase my
|
||
|
efficiency by even 10% it would save a good chunk of my time and let me get
|
||
|
back to making cool things.</p>
|
||
|
|
||
|
<p>I don't buy the "you're thinking 90% of the time and only typing 10% of the
|
||
|
time, so your editor doesn't really matter" argument. Even if the premise is
|
||
|
true, the conclusion is wrong.</p>
|
||
|
|
||
|
<p>If I think for 10 minutes and then start typing, I want the typing to take the
|
||
|
shortest time possible so I can get back to thinking. Any time I spend typing
|
||
|
is an interruption that I want to minimize so I can keep my train of thought.</p>
|
||
|
|
||
|
<p>I recently started using <a href="http://www.vim.org/">Vim</a> as my primary editor. As I'm adjusting I'm
|
||
|
finding a lot of <a href="http://jeetworks.org/node/89">the</a> <a href="http://www.viemu.com/a-why-vi-vim.html">blog</a> <a href="http://wekeroad.com/2010/07/29/vim-is-your-daddy/">posts</a> <a href="http://yehudakatz.com/2010/07/29/everyone-who-tried-to-convince-me-to-use-vim-was-wrong/">people</a>
|
||
|
<a href="http://nvie.com/posts/how-i-boosted-my-vim/">have</a> <a href="http://stackoverflow.com/questions/1218390/what-is-your-most-productive-shortcut-with-vim/1220118#1220118">written</a> <a href="http://weblog.jamisbuck.org/2008/10/10/coming-home-to-vim">about</a> Vim very helpful, so I'm hoping this
|
||
|
post will help people too.</p>
|
||
|
|
||
|
<ol class="table-of-contents"><li><a href="index.html#s1-some-background-about-me">Some Background About Me</a></li><li><a href="index.html#s2-why-i-switched-to-textmate">Why I Switched to TextMate</a></li><li><a href="index.html#s3-why-i-came-back-to-vim">Why I Came Back to Vim</a></li><li><a href="index.html#s4-core-differences">Core Differences</a></li><li><a href="index.html#s5-vim-s-feeling">Vim's "Feeling"</a><ol><li><a href="index.html#s6-a-language-of-text-editing">A "Language" of Text Editing</a></li><li><a href="index.html#s7-the-physics-of-text">The Physics of Text</a></li><li><a href="index.html#s8-programming-your-editing">"Programming" Your Editing</a></li></ol></li><li><a href="index.html#s9-getting-started">Getting Started</a></li><li><a href="index.html#s10-making-vim-more-useful">Making Vim More Useful</a><ol><li><a href="index.html#s11-important-vimrc-lines">Important .vimrc Lines</a></li><li><a href="index.html#s12-using-the-leader">Using the Leader</a></li><li><a href="index.html#s13-quicker-escaping">Quicker Escaping</a></li><li><a href="index.html#s14-working-with-split-windows">Working With Split Windows</a></li></ol></li><li><a href="index.html#s15-aesthetics">Aesthetics</a></li><li><a href="index.html#s16-bundles-i-use">Bundles I Use</a><ol><li><a href="index.html#s17-pathogen">Pathogen</a></li><li><a href="index.html#s18-peepopen">PeepOpen</a></li><li><a href="index.html#s19-nerdtree">NERDTree</a></li><li><a href="index.html#s20-nerdcommenter">NERDCommenter</a></li><li><a href="index.html#s21-ack">Ack</a></li><li><a href="index.html#s22-snipmate">Snipmate</a></li><li><a href="index.html#s23-sparkup">Sparkup</a></li><li><a href="index.html#s24-yankring">Yankring</a></li><li><a href="index.html#s25-surround-and-repeat">Surround (and Repeat)</a></li><li><a href="index.html#s26-slime">Slime</a></li><li><a href="index.html#s27-scratch">Scratch</a></li><li><a href="index.html#s28-rainbow-parentheses">Rainbow Parentheses</a></li></ol></li><li><a href="index.html#s29-things-i-want">Things I Want</a><ol><li><a href="index.html#s30-html-indentation-that-doesn-t-suck">HTML Indentation that Doesn't Suck</a></li><li><a href="index.html#s31-python-support-for-slime">Python Support for Slime</a></li><li><a href="index.html#s32-gundo">Gundo</a></li><li><a href="index.html#s33-a-mercurial-version-of-fugitive">A Mercurial Version of Fugitive</a></li></ol></li><li><a href="index.html#s34-overall-thoughts">Overall Thoughts</a></li></ol>
|
||
|
|
||
|
<h2 id="s1-some-background-about-me"><a href="index.html#s1-some-background-about-me">Some Background About Me</a></h2>
|
||
|
|
||
|
<p>I used Vim exclusively from about 2002 to 2005. I never really learned much
|
||
|
about it and mostly used it as a glorified <a href="http://en.wikipedia.org/wiki/Nano_(text_editor)">nano</a>.</p>
|
||
|
|
||
|
<p>In 2006 I decided it was time for a change. I wanted an editor that "fit" with
|
||
|
OS X. I tried <a href="http://www.codingmonkeys.de/subethaedit/">SubEthaEdit</a> for a while and it was kind of cool. The
|
||
|
collaborative editing was more polished than any other version I've seen,
|
||
|
though I didn't have much use for it.</p>
|
||
|
|
||
|
<p>As cool as SubEthaEdit was, I always felt like there was a better editor out
|
||
|
there for me. Then I found <a href="http://macromates.com/">TextMate</a>.</p>
|
||
|
|
||
|
<p>At the time I thought TextMate was amazing (and it really was). It <em>looked</em>
|
||
|
like a Mac application. It was super easy to learn (all the OS X text movement
|
||
|
commands just worked). There were bundles for everything.</p>
|
||
|
|
||
|
<p>I still used Vim occasionally (like when I had a job and only had a Windows
|
||
|
machine), but for the most part I was a TextMate kid.</p>
|
||
|
|
||
|
<p>After using TextMate for four years I decided it was time for another change.
|
||
|
Development on TextMate has stalled while TextMate Forever (err, TextMate 2) is
|
||
|
in the works. I started thinking about Vim (and reading blog posts by others
|
||
|
about how they switched back) and decided to give it another try.</p>
|
||
|
|
||
|
<p>A few months ago I bought <a href="http://amzn.com/059652983X">Learning the vi and Vim Editors</a> and went
|
||
|
cold-turkey with Vim as my main text editor. I haven't looked back since.</p>
|
||
|
|
||
|
<h2 id="s2-why-i-switched-to-textmate"><a href="index.html#s2-why-i-switched-to-textmate">Why I Switched to TextMate</a></h2>
|
||
|
|
||
|
<p>As I mentioned before, there were a few reasons I switched to TextMate in the
|
||
|
first place.</p>
|
||
|
|
||
|
<p>First of all: it looks and acts like a real OS X application. You can drag
|
||
|
files onto the icon to open them, it supports all the default OS X text
|
||
|
movement commands, and the chrome looks like it belongs on OS X. I don't know
|
||
|
if <a href="http://code.google.com/p/macvim/">MacVim</a> was around at the time, but if it was I never found it.</p>
|
||
|
|
||
|
<p>This matters. The effort required to get started with a new editor is
|
||
|
dramatically reduced if that editor supports all the conventions of the
|
||
|
operating system you use every day.</p>
|
||
|
|
||
|
<p>It also has a vibrant community of people writing bundles for it, so there was
|
||
|
support for almost anything I wanted to use.</p>
|
||
|
|
||
|
<h2 id="s3-why-i-came-back-to-vim"><a href="index.html#s3-why-i-came-back-to-vim">Why I Came Back to Vim</a></h2>
|
||
|
|
||
|
<p>I came back to Vim for a number of reasons.</p>
|
||
|
|
||
|
<p>First of all: I started reading about and desiring features that didn't seem to
|
||
|
be coming to TextMate any time soon. The biggest of those was split windows.
|
||
|
I saw the appeal of split windows right away and now that I use them I can't
|
||
|
imagine not having them.</p>
|
||
|
|
||
|
<p>Another reason is version control. A while ago I started keeping my
|
||
|
<a href="http://bitbucket.org/sjl/dotfiles/">dotfiles</a> in a <a href="http://hg-scm.org/">Mercurial</a> repository which makes it extremely easy to set
|
||
|
up new machines. Vim keeps all of its configuration in two simple places:
|
||
|
a simple <code>~/.vimrc</code> file and a <code>~/.vim</code> directory full of plain text files.</p>
|
||
|
|
||
|
<p>Vim's plain text configuration files and plugins are very easy to version
|
||
|
control. They diff well, unlike TextMate's multiple <code>Bundles</code> directories and
|
||
|
ugly XML file format.</p>
|
||
|
|
||
|
<p>Vim's community has been around far longer than TextMate's so there's an even
|
||
|
richer set of plugins, bundles and syntax files available.</p>
|
||
|
|
||
|
<p>Another reason people give for enjoying Vim is that it runs everywhere. Yes,
|
||
|
it's nice to have my favorite editor available when I SSH into a machine, but
|
||
|
it's not a huge deal if I don't. I almost always edit files on my own machine
|
||
|
and then deploy them with an automated script of some kind, so editing on
|
||
|
a server is very rare for me.</p>
|
||
|
|
||
|
<h2 id="s4-core-differences"><a href="index.html#s4-core-differences">Core Differences</a></h2>
|
||
|
|
||
|
<p>For me, Vim and TextMate are very different. TextMate relies mainly on
|
||
|
keyboard shortcuts (involving Shift, Ctrl, Cmd and Alt) to do more than simply
|
||
|
edit text. Vim uses a "modal editing" idea to accomplish the same task.</p>
|
||
|
|
||
|
<p>TextMate's philosophy is much the same as any normal OS X application's, and
|
||
|
I said that acting like the OS reduces the barrier of entry for a text editor,
|
||
|
so why do I prefer Vim's philosophy?</p>
|
||
|
|
||
|
<p>First I should prefix my answer with this: I'm not averse to a learning curve
|
||
|
for something as important to me as a text editor. Yes, it's awesome if
|
||
|
I don't need to unnecessarily rewire my brain, but if it's going to save me
|
||
|
a lot of time then I'm willing to cut a bit of slack here.</p>
|
||
|
|
||
|
<p>My problem with TextMate's philosophy can be summed up in one word:
|
||
|
"shadowing".</p>
|
||
|
|
||
|
<p>If I want to define a new command in a bundle (or if someone else has already
|
||
|
done it), I'm never really sure if I'm "overwriting" some other command that my
|
||
|
fingers know but my brain doesn't really register.</p>
|
||
|
|
||
|
<p>By the time I try to use the default command it could be days or weeks after
|
||
|
I defined the custom one, and I need to figure out what I did all over again.
|
||
|
It's quite frustrating.</p>
|
||
|
|
||
|
<p>Vim's "insert" mode means that when I'm editing text I'm using the normal OS
|
||
|
X text movement shortcuts that I know and love. When I want to do something
|
||
|
special I enter normal mode and don't have to worry about shadowed commands
|
||
|
(Vim's leader key also helps with this).</p>
|
||
|
|
||
|
<h2 id="s5-vim-s-feeling"><a href="index.html#s5-vim-s-feeling">Vim's "Feeling"</a></h2>
|
||
|
|
||
|
<p>Vim's normal mode has a unique "feeling" that I haven't seen in any other text
|
||
|
editor (although <a href="http://www.e-texteditor.com/">E</a> may <a href="http://e-texteditor.com/blog/2010/beyond-vi">change that</a>). I've heard it described in
|
||
|
a number of ways, and I think that while no one analogy fully explains it,
|
||
|
together they give a pretty good description.</p>
|
||
|
|
||
|
<h3 id="s6-a-language-of-text-editing"><a href="index.html#s6-a-language-of-text-editing">A "Language" of Text Editing</a></h3>
|
||
|
|
||
|
<p>One way to think about Vim's normal-mode commands is like a language. You have
|
||
|
"verbs" and "nouns". For example: the "change" command (<code>c</code>) would be a verb
|
||
|
and the "word" item (<code>w</code>) is a noun. You can combine them to form imperative
|
||
|
sentences that talk about what you want to do with your text.</p>
|
||
|
|
||
|
<p>The wonderful part about this is that whenever you learn a new verb (like
|
||
|
"delete" (<code>d</code>)) you can immediately apply it to all the nouns you know, and
|
||
|
vice versa.</p>
|
||
|
|
||
|
<p>Vim also has "adjectives" like "inside" and "around" (<code>i</code> and <code>a</code>) that let you
|
||
|
craft sentences like "change inside parenthesis" (<code>ci(</code> or <code>cib</code>). Once you
|
||
|
learn one of these you can immediately apply it to all the verbs and nouns you
|
||
|
already know.</p>
|
||
|
|
||
|
<h3 id="s7-the-physics-of-text"><a href="index.html#s7-the-physics-of-text">The Physics of Text</a></h3>
|
||
|
|
||
|
<p>The second way to describe the feeling of Vim is "physics". It's a much less
|
||
|
concrete description but I think it's still useful.</p>
|
||
|
|
||
|
<p>If I throw a bowling ball into the air it behaves much the same way as if
|
||
|
I throw a turkey sandwich. They might have very different effects when they
|
||
|
land on someone but the act of throwing them is pretty much the same.</p>
|
||
|
|
||
|
<p>Vim's operators/actions/verbs act the same way. <code>daw</code> has a very different
|
||
|
effect than <code>da{</code> but they can both be understood with a basic underlying
|
||
|
principle: <code>da<something></code> will "delete around <code><something></code>".</p>
|
||
|
|
||
|
<h3 id="s8-programming-your-editing"><a href="index.html#s8-programming-your-editing">"Programming" Your Editing</a></h3>
|
||
|
|
||
|
<p>The last way that I hear people talking about Vim's editing is: "it feels like
|
||
|
you're 'programming' your text".</p>
|
||
|
|
||
|
<p>This analogy is often made by programmers (obviously) and I think it works on
|
||
|
more than one level.</p>
|
||
|
|
||
|
<p>First: Vim's basic editing commands can be likened to function calls. <code>daw</code>
|
||
|
can be thought of a running a function like <code>delete(type='word', around=True)</code>.
|
||
|
I don't think this way (I prefer the language and physics analogies) but other
|
||
|
people do.</p>
|
||
|
|
||
|
<p>Although I don't think of the <em>basic</em> Vim commands as programming I do see
|
||
|
some aspects of it in other areas. For example: say I define a leader command
|
||
|
in my <code>~/.vimrc</code> file:</p>
|
||
|
|
||
|
<pre><code>nnoremap <leader>1 yypVr=</code></pre>
|
||
|
|
||
|
<p>I think of this as defining <code><leader>1</code> to be a function that performs the
|
||
|
following actions:</p>
|
||
|
|
||
|
<ul>
|
||
|
<li>Yank/copy the current line.</li>
|
||
|
<li>Paste it below (and move down to the pasted version).</li>
|
||
|
<li>Select the copied line.</li>
|
||
|
<li>Replace every character with <code>=</code>.</li>
|
||
|
</ul>
|
||
|
|
||
|
<p>Another more obvious "programming" aspect of Vim is creating macros. Macros are
|
||
|
like tiny little functions you create to help you when you're editing a file.
|
||
|
You can define them, execute them, and even edit them by pasting, editing and
|
||
|
yanking them back.</p>
|
||
|
|
||
|
<h2 id="s9-getting-started"><a href="index.html#s9-getting-started">Getting Started</a></h2>
|
||
|
|
||
|
<p>When I switched back to Vim I did a few things that helped make my transition
|
||
|
stick.</p>
|
||
|
|
||
|
<p>First: I bought <a href="http://amzn.com/059652983X">Learning the vi and Vim Editors</a> and read it cover to cover.
|
||
|
It helps quite a bit to know the history behind Vim, and the book also teaches
|
||
|
you the basics of Vim's editing commands.</p>
|
||
|
|
||
|
<p>I also looked through <a href="http://reddit.com/r/vim/">the Vim subreddit</a> to find some good blog posts about
|
||
|
switching. A lot of people have written about it and it was very helpful to
|
||
|
read about their experiences.</p>
|
||
|
|
||
|
<p>And finally, the most important part: I switched cold-turkey. Vim runs everywhere, so
|
||
|
there's really no excuse for not doing this. Every decent OS has a version of
|
||
|
Vim that makes insert mode "just work" for their OS (like gvim or MacVim), so
|
||
|
the barrier to entry these days is pretty low.</p>
|
||
|
|
||
|
<p>You can get Vim and start using it right away by staying in insert mode most of
|
||
|
the time. Then you can start learning its real features at your own pace.
|
||
|
Trying to use two different editors at once just slows down the learning
|
||
|
process and makes you less productive in both.</p>
|
||
|
|
||
|
<h2 id="s10-making-vim-more-useful"><a href="index.html#s10-making-vim-more-useful">Making Vim More Useful</a></h2>
|
||
|
|
||
|
<p>One of the flaws of Vim is that it takes quite a bit of configuration to make
|
||
|
it behave in a decent way. The defaults are backwards-compatible with vi (i.e.
|
||
|
older than most college students) and not very helpful.</p>
|
||
|
|
||
|
<p>Here are a few of the things I do to make Vim a bit more palatable.</p>
|
||
|
|
||
|
<p><strong>A quick side note:</strong> even if you don't use Vim, you <em>need</em> to <a href="http://c2.com/cgi/wiki?RemapCapsLock">remap your
|
||
|
capslock key</a> to something useful. Just do it, you'll thank me.</p>
|
||
|
|
||
|
<h3 id="s11-important-vimrc-lines"><a href="index.html#s11-important-vimrc-lines">Important .vimrc Lines</a></h3>
|
||
|
|
||
|
<p>I won't go through every line in <a href="http://bitbucket.org/sjl/dotfiles/src/tip/vim/.vimrc">my <code>~/.vimrc</code> file</a>, but here are some of the
|
||
|
lines that I simply could not live without.</p>
|
||
|
|
||
|
<p>First, a few lines that you absolutely must have:</p>
|
||
|
|
||
|
<pre><code>filetype off
|
||
|
call pathogen#runtime_append_all_bundles()
|
||
|
filetype plugin indent on
|
||
|
|
||
|
set nocompatible
|
||
|
|
||
|
set modelines=0</code></pre>
|
||
|
|
||
|
<p>The <code>filetype</code> and <code>call</code> lines are for loading Pathogen, which is described in
|
||
|
the bundles section. See <a href="http://www.vim.org/scripts/script.php?script_id=2332">Pathogen's docs</a> to learn about why the
|
||
|
first <code>filetype</code> line is there.</p>
|
||
|
|
||
|
<p><code>set nocompatible</code> gets rid of all the crap that Vim does to be vi compatible.
|
||
|
It's 2010 — we don't need to be compatible with vi at the expense of
|
||
|
functionality any more.</p>
|
||
|
|
||
|
<p>The <code>modelines</code> bit prevents some <a href="http://lists.alioth.debian.org/pipermail/pkg-vim-maintainers/2007-June/004020.html">security exploits</a> having to do with
|
||
|
modelines in files. I never use modelines so I don't miss any functionality
|
||
|
here.</p>
|
||
|
|
||
|
<p>Next I set my tab settings:</p>
|
||
|
|
||
|
<pre><code>set tabstop=4
|
||
|
set shiftwidth=4
|
||
|
set softtabstop=4
|
||
|
set expandtab</code></pre>
|
||
|
|
||
|
<p>I like all tabs to expand to four spaces. Check out <a href="http://vimcasts.org/episodes/tabs-and-spaces/">this Vimcast</a> to
|
||
|
learn more about each of these options.</p>
|
||
|
|
||
|
<p>Next are a few options that just make things better:</p>
|
||
|
|
||
|
<pre><code>set encoding=utf-8
|
||
|
set scrolloff=3
|
||
|
set autoindent
|
||
|
set showmode
|
||
|
set showcmd
|
||
|
set hidden
|
||
|
set wildmenu
|
||
|
set wildmode=list:longest
|
||
|
set visualbell
|
||
|
set cursorline
|
||
|
set ttyfast
|
||
|
set ruler
|
||
|
set backspace=indent,eol,start
|
||
|
set laststatus=2
|
||
|
set relativenumber
|
||
|
set undofile</code></pre>
|
||
|
|
||
|
<p>Each of these lines are basically to make Vim behave in a sane manner. The two
|
||
|
"interesting" ones are the last two, and both deal with features that are
|
||
|
<a href="http://groups.google.com/group/vim_announce/browse_thread/thread/66c02efd1523554b">new in Vim 7.3</a>.</p>
|
||
|
|
||
|
<p><code>relativenumber</code> changes Vim's line number column to display how far away each
|
||
|
line is from the current one, instead of showing the absolute line number.</p>
|
||
|
|
||
|
<p>I almost never care what numeric line I'm on in a file (and if I do I can see
|
||
|
it in the status line), so I don't miss the normal line numbers. I <em>do</em> care
|
||
|
how far away a particular line might be, because it tells me what number I need
|
||
|
to use with motion commands like <code>d<NUMBER>d</code>.</p>
|
||
|
|
||
|
<p><code>undofile</code> tells Vim to create <code><FILENAME>.un~</code> files whenever you edit a file.
|
||
|
These files contain undo information so you can undo previous actions even
|
||
|
after you close and reopen a file.</p>
|
||
|
|
||
|
<p>Next I change the <code><leader></code> key:</p>
|
||
|
|
||
|
<pre><code>let mapleader = ","</code></pre>
|
||
|
|
||
|
<p>For me <code>,</code> is easier to type than <code>\</code>. I use leader commands constantly so it's
|
||
|
worth changing.</p>
|
||
|
|
||
|
<p>The next thing I do is tame searching/moving:</p>
|
||
|
|
||
|
<pre><code>nnoremap / /\v
|
||
|
vnoremap / /\v
|
||
|
set ignorecase
|
||
|
set smartcase
|
||
|
set gdefault
|
||
|
set incsearch
|
||
|
set showmatch
|
||
|
set hlsearch
|
||
|
nnoremap <leader><space> :noh<cr>
|
||
|
nnoremap <tab> %
|
||
|
vnoremap <tab> %</code></pre>
|
||
|
|
||
|
<p>The first two lines fix Vim's horribly broken default regex "handling" by
|
||
|
automatically inserting a <code>\v</code> before any string you search for. This turns
|
||
|
off Vim's crazy default regex characters and makes searches use normal regexes.
|
||
|
I already know Perl/Python compatible regex formatting, why would I want to
|
||
|
learn another scheme?</p>
|
||
|
|
||
|
<p><code>ignorecase</code> and <code>smartcase</code> together make Vim deal with case-sensitive search
|
||
|
intelligently. If you search for an all-lowercase string your search will be
|
||
|
case-insensitive, but if one or more characters is uppercase the search will be
|
||
|
case-sensitive. Most of the time this does what you want.</p>
|
||
|
|
||
|
<p><code>gdefault</code> applies substitutions globally on lines. For example, instead of
|
||
|
<code>:%s/foo/bar/g</code> you just type <code>:%s/foo/bar/</code>. This is almost always what you
|
||
|
want (when was the last time you wanted to only replace the first occurrence of
|
||
|
a word on a line?) and if you need the previous behavior you just tack on the
|
||
|
<code>g</code> again.</p>
|
||
|
|
||
|
<p><code>incsearch</code>, <code>showmatch</code> and <code>hlsearch</code> work together to highlight search
|
||
|
results (as you type). It's really quite handy, as long as you have the next
|
||
|
line as well.</p>
|
||
|
|
||
|
<p>The <code><leader><space></code> mapping makes it easy to clear out a search by typing
|
||
|
<code>,<space></code>. This gets rid of the distracting highlighting once I've found what
|
||
|
I'm looking for.</p>
|
||
|
|
||
|
<p>The last two lines make the tab key match bracket pairs. I use this to move
|
||
|
around all the time and <code><tab></code> is a hell of a lot easier to type than <code>%</code>.</p>
|
||
|
|
||
|
<p>The next section makes Vim handle long lines correctly:</p>
|
||
|
|
||
|
<pre><code>set wrap
|
||
|
set textwidth=79
|
||
|
set formatoptions=qrn1
|
||
|
set colorcolumn=85</code></pre>
|
||
|
|
||
|
<p>These lines manage my line wrapping settings and also show a colored column at
|
||
|
85 characters (so I can see when I write a too-long line of code).</p>
|
||
|
|
||
|
<p>See <a href="http://vimdoc.sourceforge.net/htmldoc/change.html#fo-table"><code>:help fo-table</code></a> and the Vimcasts on <a href="http://vimcasts.org/episodes/soft-wrapping-text/">soft wrapping</a> and <a href="http://vimcasts.org/episodes/hard-wrapping-text/">hard wrapping</a> for more information.</p>
|
||
|
|
||
|
<p>Next comes something other TextMate refugees may like:</p>
|
||
|
|
||
|
<pre><code>set list
|
||
|
set listchars=tab:▸\ ,eol:¬</code></pre>
|
||
|
|
||
|
<p>This makes Vim show invisible characters with the same characters that TextMate
|
||
|
uses. You might need to adjust your color scheme so they're not too
|
||
|
distracting. <a href="http://vimcasts.org/episodes/show-invisibles/">This Vimcast</a> has more information.</p>
|
||
|
|
||
|
<p>New Vim users will want the following lines to teach them to do things right:</p>
|
||
|
|
||
|
<pre><code>nnoremap <up> <nop>
|
||
|
nnoremap <down> <nop>
|
||
|
nnoremap <left> <nop>
|
||
|
nnoremap <right> <nop>
|
||
|
inoremap <up> <nop>
|
||
|
inoremap <down> <nop>
|
||
|
inoremap <left> <nop>
|
||
|
inoremap <right> <nop>
|
||
|
nnoremap j gj
|
||
|
nnoremap k gk</code></pre>
|
||
|
|
||
|
<p>This will disable the arrow keys while you're in normal mode to help you learn
|
||
|
to use <code>hjkl</code>. Trust me, you want to learn to use <code>hjkl</code>. Playing a lot of
|
||
|
<a href="http://www.nethack.org/">Nethack</a> also helps.</p>
|
||
|
|
||
|
<p>It also disables the arrow keys in insert mode to force you to get back into
|
||
|
normal mode the instant you're done inserting text, which is the "right way" to
|
||
|
do things.</p>
|
||
|
|
||
|
<p>It also makes j and k work the way you expect instead of working in some
|
||
|
archaic "movement by file line instead of screen line" fashion.</p>
|
||
|
|
||
|
<p>Next, get rid of that stupid goddamned help key that you will invaribly hit
|
||
|
<em>constantly</em> while aiming for escape:</p>
|
||
|
|
||
|
<pre><code>inoremap <F1> <ESC>
|
||
|
nnoremap <F1> <ESC>
|
||
|
vnoremap <F1> <ESC></code></pre>
|
||
|
|
||
|
<p>I also like to make <code>;</code> do the same thing as <code>:</code> — it's one less key to hit
|
||
|
every time I want to save a file:</p>
|
||
|
|
||
|
<pre><code>nnoremap ; :</code></pre>
|
||
|
|
||
|
<p>I don't remap <code>:</code> back to <code>;</code> because it seems to break a bunch of plugins.</p>
|
||
|
|
||
|
<p>Finally, I really like TextMate's "save on losing focus" feature. I can't
|
||
|
remember a time when I <em>didn't</em> want to save a file after tabbing away from my
|
||
|
editor (especially with version control and Vim's persistent undo):</p>
|
||
|
|
||
|
<pre><code>au FocusLost * :wa</code></pre>
|
||
|
|
||
|
<p>Those are the most important bits of my <code>~/.vimrc</code> file. Next I'll talk about
|
||
|
the wonderful namespace of customization that is Vim's <code><leader></code> key.</p>
|
||
|
|
||
|
<h3 id="s12-using-the-leader"><a href="index.html#s12-using-the-leader">Using the Leader</a></h3>
|
||
|
|
||
|
<p>Vim dedicates an entire keyboard key for user-specific customizations. This is
|
||
|
called the "leader" and by default it's mapped to <code>\</code>. As I mentioned in the
|
||
|
previous section I prefer to use <code>,</code> instead.</p>
|
||
|
|
||
|
<p>Each person will find little things they type or execute often and want to
|
||
|
create shortcuts for those things. The leader is a kind of "namespace" to keep
|
||
|
those customizations separate and prevent them from shadowing default commands.</p>
|
||
|
|
||
|
<p>Here are a few of the things I use leader commands for. You'll certainly have
|
||
|
different ideas than I do, but this might give you an idea of what you can do.</p>
|
||
|
|
||
|
<p>I use <code>,W</code> to mean "strip all trailing whitespace in the current file" so I can
|
||
|
clean things up quickly:</p>
|
||
|
|
||
|
<pre><code>nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR></code></pre>
|
||
|
|
||
|
<p>I use Ack a lot (described below), so I mapped a leader key for it:</p>
|
||
|
|
||
|
<pre><code>nnoremap <leader>a :Ack</code></pre>
|
||
|
|
||
|
<p>I work with HTML often, so I have <code>,ft</code> mapped to a "fold tag" function:</p>
|
||
|
|
||
|
<pre><code>nnoremap <leader>ft Vatzf</code></pre>
|
||
|
|
||
|
<p>I also work with Nick Sergeant and he likes his CSS properties sorted, so
|
||
|
here's a <code>,S</code> mapping that sorts them for me:</p>
|
||
|
|
||
|
<pre><code>nnoremap <leader>S ?{<CR>jV/^\s*\}?$<CR>k:sort<CR>:noh<CR></code></pre>
|
||
|
|
||
|
<p>This next mapping imitates TextMates <code>Ctrl+Q</code> function to re-hardwrap
|
||
|
paragraphs of text:</p>
|
||
|
|
||
|
<pre><code>nnoremap <leader>q gqip</code></pre>
|
||
|
|
||
|
<p>I have a <code>,v</code> mapping to reselect the text that was just pasted so I can
|
||
|
perform commands (like indentation) on it:</p>
|
||
|
|
||
|
<pre><code>nnoremap <leader>v V`]</code></pre>
|
||
|
|
||
|
<p>This last mapping lets me quickly open up my <code>~/.vimrc</code> file in a vertically
|
||
|
split window so I can add new things to it on the fly.</p>
|
||
|
|
||
|
<pre><code>nnoremap <leader>ev <C-w><C-v><C-l>:e $MYVIMRC<cr></code></pre>
|
||
|
|
||
|
<h3 id="s13-quicker-escaping"><a href="index.html#s13-quicker-escaping">Quicker Escaping</a></h3>
|
||
|
|
||
|
<p>One thing you'll find yourself constantly doing in Vim is moving from insert
|
||
|
mode to normal mode. The default way to do this is by hitting Escape, but that
|
||
|
key is out of the way and hard to hit.</p>
|
||
|
|
||
|
<p>Another way is to use <code>Ctrl+C</code> or <code>Ctrl+[</code>, but I don't like using a chord for
|
||
|
something I press that often.</p>
|
||
|
|
||
|
<p>I personally use <code>jj</code> to exit back to normal mode. The only time I've ever
|
||
|
actually tried to hit two <code>j</code>'s in a row is just now while writing this entry,
|
||
|
so it doesn't conflict with my normal typing at all:</p>
|
||
|
|
||
|
<pre><code>inoremap jj <ESC></code></pre>
|
||
|
|
||
|
<h3 id="s14-working-with-split-windows"><a href="index.html#s14-working-with-split-windows">Working With Split Windows</a></h3>
|
||
|
|
||
|
<p>Being able to split my editor window and see more than one file at once is one
|
||
|
of the main reasons I switched to Vim. I know I'm not alone here after reading
|
||
|
various posts around the internet asking for this feature in TextMate.</p>
|
||
|
|
||
|
<p>Vim's default commands for interacting with splits, however, are kind of
|
||
|
clunky. I've added a few mappings to my <code>~/.vimrc</code> that make things work a bit
|
||
|
smoother.</p>
|
||
|
|
||
|
<p>This first mapping makes <code>,w</code> open a new vertical split and switch over to it.
|
||
|
Because really, how often do you split your window and not want to do something
|
||
|
in the new split?</p>
|
||
|
|
||
|
<pre><code>nnoremap <leader>w <C-w>v<C-w>l</code></pre>
|
||
|
|
||
|
<p>You might notice that this mapping is for vertical splits. I almost <em>never</em>
|
||
|
use horizontal splits. All of my screens are widescreen, so I can fit several
|
||
|
files onscreen if they're split vertically. Horizontal splits don't let me see
|
||
|
enough of the file. If I <em>really</em> want a horizontal split I can use <code><C-w>s</code>
|
||
|
to get one.</p>
|
||
|
|
||
|
<p>This next set of mappings maps <code><C-[h/j/k/l]></code> to the commands needed to move
|
||
|
around your splits. If you remap your capslock key to <code>Ctrl</code> it makes for very
|
||
|
easy navigation.</p>
|
||
|
|
||
|
<pre><code>nnoremap <C-h> <C-w>h
|
||
|
nnoremap <C-j> <C-w>j
|
||
|
nnoremap <C-k> <C-w>k
|
||
|
nnoremap <C-l> <C-w>l</code></pre>
|
||
|
|
||
|
<h2 id="s15-aesthetics"><a href="index.html#s15-aesthetics">Aesthetics</a></h2>
|
||
|
|
||
|
<p>I know some people say: "looks don't matter, the only thing that's important is
|
||
|
functionality". That's completely wrong.</p>
|
||
|
|
||
|
<p>If I'm looking at something for multiple hours each day it had damn well better
|
||
|
look pretty. There are three main steps to making Vim look pretty (for me, on
|
||
|
OS X — your mileage may vary).</p>
|
||
|
|
||
|
<p>First: get <a href="http://code.google.com/p/macvim/">MacVim</a>. It makes Vim look (and behave) like a native Mac
|
||
|
application. It helps it avoid standing out like a sore thumb among your other
|
||
|
applications. Linux and Windows users will probably want gvim.</p>
|
||
|
|
||
|
<p>Next: pick a decent font. I prefer 12 point <a href="http://arstechnica.com/apple/news/2009/06/font-changes-coming-to-mac-os-x-snow-leopard.ars">Menlo</a>. You might have
|
||
|
a different preference, but at least try out a few and find one that has a nice
|
||
|
balance between line height (so you can get a good amount of lines on the
|
||
|
screen) and readability (slashed zeros, please).</p>
|
||
|
|
||
|
<p>Finally: find a good color scheme. I've been using <a href="http://bitbucket.org/sjl/dotfiles/src/tip/vim/colors/molokai.vim">a slightly modified
|
||
|
version</a> of <a href="http://www.vim.org/scripts/script.php?script_id=2340">Molokai</a> (a port of the TextMate <a href="http://www.monokai.nl/blog/2006/07/15/textmate-color-theme/">Monokai</a> theme)
|
||
|
since I came back to Vim, but recently I've also started flirting with
|
||
|
<a href="http://hcalves.deviantart.com/art/Mustang-Vim-Colorscheme-98974484">Mustang</a> and <a href="http://forr.st/~yZn">Clouds Midnight</a>. Spend an hour and find something that
|
||
|
looks good to you.</p>
|
||
|
|
||
|
<p>Here's what my current setup looks like:</p>
|
||
|
|
||
|
<p><img src="http://stevelosh.com/static/images/blog/2010/09/vim.png" alt="Current Vim Setup Screenshot" title="My Current Vim Setup"></p>
|
||
|
|
||
|
<h2 id="s16-bundles-i-use"><a href="index.html#s16-bundles-i-use">Bundles I Use</a></h2>
|
||
|
|
||
|
<p>Vim has been around for a <em>long</em> time, and many people have written extensions
|
||
|
for it. Here are a few of the bundles I couldn't live without in my day-to-day
|
||
|
editing.</p>
|
||
|
|
||
|
<h3 id="s17-pathogen"><a href="index.html#s17-pathogen">Pathogen</a></h3>
|
||
|
|
||
|
<p>First of all: <a href="http://github.com/tpope">Tim Pope</a> has created the wonderful <a href="http://github.com/tpope/vim-pathogen">Pathogen</a> plugin that
|
||
|
makes managing <em>other</em> Vim plugins painless. Instead of scattering their files
|
||
|
throughout your <code>~/.vim/</code> folder you can keep their files inside a single
|
||
|
folder in <code>~/.vim/bundles/</code>.</p>
|
||
|
|
||
|
<p>Install it and keep your sanity.</p>
|
||
|
|
||
|
<h3 id="s18-peepopen"><a href="index.html#s18-peepopen">PeepOpen</a></h3>
|
||
|
|
||
|
<p>One of TextMate's "killer features" is its <code>Cmd+T</code> key. It lets you open files
|
||
|
quickly by typing fragments of their names.</p>
|
||
|
|
||
|
<p>There are a number of Vim plugins out there that try to emulate it. My
|
||
|
favorite is <a href="http://peepcode.com/products/peepopen">PeepOpen</a>. Yes, it's OS X only and costs money, but it's worth
|
||
|
it. It looks good and "just works".</p>
|
||
|
|
||
|
<p>PeepOpen has some nifty little features, like showing Git metadata in the file
|
||
|
list. I've <a href="http://github.com/topfunky/PeepOpen-Issues/issues#issue/91">offered a patch</a> to add the same functionality for Mercurial but
|
||
|
haven't heard back from the developers.</p>
|
||
|
|
||
|
<p>If you don't use OS X (or want a free alternative to PeepOpen) I hear the
|
||
|
<a href="https://wincent.com/products/command-t">Command-T</a> plugin is quite nice.</p>
|
||
|
|
||
|
<h3 id="s19-nerdtree"><a href="index.html#s19-nerdtree">NERDTree</a></h3>
|
||
|
|
||
|
<p>One plugin you'll hear about in almost all of these "switching to Vim" blog
|
||
|
posts is <a href="http://github.com/scrooloose/nerdtree">NERDTree</a>. It's a little plugin for browsing files in your project,
|
||
|
and it works great. There's no better "TextMate file-drawer" plugin around.</p>
|
||
|
|
||
|
<h3 id="s20-nerdcommenter"><a href="index.html#s20-nerdcommenter">NERDCommenter</a></h3>
|
||
|
|
||
|
<p>Want to be able to comment and uncomment code with a few keypresses? You need
|
||
|
<a href="http://github.com/scrooloose/nerdcommenter">NERDCommenter</a>. It's surprising that Vim doesn't have decent commenting
|
||
|
functionality built in, but NERDCommenter fixes that.</p>
|
||
|
|
||
|
<p>I really only use this plugin for one single function: "toggle comment" with
|
||
|
<code><leader>c<space></code>. That function alone is worth installing it.</p>
|
||
|
|
||
|
<h3 id="s21-ack"><a href="index.html#s21-ack">Ack</a></h3>
|
||
|
|
||
|
<p>If you're a programmer and you don't know about <a href="http://betterthangrep.com/">Ack</a>, you need to start
|
||
|
using it now. It's far, far better than grep.</p>
|
||
|
|
||
|
<p>The <a href="http://github.com/mileszs/ack.vim">Ack plugin</a> for Vim integrates Ack with Vim's quickfix window so
|
||
|
you can easily search and jump to results.</p>
|
||
|
|
||
|
<p>As I mentioned in the section about leader mappings I've got <code>,a</code> mapped to
|
||
|
bring up Ack all ready to search.</p>
|
||
|
|
||
|
<h3 id="s22-snipmate"><a href="index.html#s22-snipmate">Snipmate</a></h3>
|
||
|
|
||
|
<p>Another feature of TextMate that was <em>amazing</em> when I first saw it was
|
||
|
snippets. <a href="http://github.com/msanders/snipmate.vim">SnipMate</a> is a Vim plugin that emulates TextMate snippets.</p>
|
||
|
|
||
|
<p>It also stores them in easily-version-controlled plain text files, which is
|
||
|
a bonus over TextMate's snippets.</p>
|
||
|
|
||
|
<h3 id="s23-sparkup"><a href="index.html#s23-sparkup">Sparkup</a></h3>
|
||
|
|
||
|
<p><a href="http://github.com/rstacruz/sparkup">Sparkup</a> is pretty much a great port of <a href="http://code.google.com/p/zen-coding/">Zen Coding</a> for Vim. If you write
|
||
|
HTML at all this plugin will save you a ton of typing.</p>
|
||
|
|
||
|
<p>In a nutshell it lets you type something like:</p>
|
||
|
|
||
|
<pre><code>div.content>h1.post-title+p{Sample Content}</code></pre>
|
||
|
|
||
|
<p>Press <code>Cmd+E</code> and it will expand to this:</p>
|
||
|
|
||
|
<pre><code><div class="content">
|
||
|
<h1 class="post-title"></h1>
|
||
|
<p>Sample Content</p>
|
||
|
</div></code></pre>
|
||
|
|
||
|
<p>It's far less typing and it adds up over time.</p>
|
||
|
|
||
|
<h3 id="s24-yankring"><a href="index.html#s24-yankring">Yankring</a></h3>
|
||
|
|
||
|
<p>Vim's copying and pasting functionality (which uses registers) is very, very
|
||
|
powerful, but it's not exactly "user friendly". The <a href="http://www.vim.org/scripts/script.php?script_id=1234">YankRing</a> plugin adds
|
||
|
a lot <em>more</em> power, but also adds a few features that make copying and pasting
|
||
|
much more pleasant.</p>
|
||
|
|
||
|
<p>For example, after you paste some text you can replace that paste with the
|
||
|
previous item you copied with <code>Ctrl-P</code>. You can cycle back further by just
|
||
|
hitting <code>Ctrl-P</code> over and over.</p>
|
||
|
|
||
|
<p>YankRing also shares your yanked text between Vim windows, which makes things
|
||
|
"just work" when you want to paste text from one window into another.</p>
|
||
|
|
||
|
<p>You can also show a list of all your previously yanked text with <code>:YRShow</code>.
|
||
|
Mapping that command to a key is quite helpful:</p>
|
||
|
|
||
|
<pre><code>nnoremap <silent> <F3> :YRShow<cr>
|
||
|
inoremap <silent> <F3> <ESC>:YRShow<cr></code></pre>
|
||
|
|
||
|
<p>YankRing offers a ton of other cool functionality but I haven't had the time or
|
||
|
motivation to really dig in and find out how to use it.</p>
|
||
|
|
||
|
<h3 id="s25-surround-and-repeat"><a href="index.html#s25-surround-and-repeat">Surround (and Repeat)</a></h3>
|
||
|
|
||
|
<p>Another of Time Pope's plugins that I use all the time is the <a href="http://github.com/tpope/vim-surround">Surround</a>
|
||
|
plugin. It adds another layer to Vim's physics: "surrounding items".</p>
|
||
|
|
||
|
<p>For example, you can "change surrounding single quotes to double quotes" by
|
||
|
using <code>cs'"</code>. Or if you're writing something in Markdown and want to italicize
|
||
|
a word you can use <code>ysiW*</code>.</p>
|
||
|
|
||
|
<p>All the nouns and verbs you already know can be used, which fits with Vim's
|
||
|
philosophy and makes it extremely powerful.</p>
|
||
|
|
||
|
<p>The <a href="http://github.com/tpope/vim-repeat">Repeat</a> plugin is necessary to make these surround actions repeatable
|
||
|
with <code>.</code>.</p>
|
||
|
|
||
|
<h3 id="s26-slime"><a href="index.html#s26-slime">Slime</a></h3>
|
||
|
|
||
|
<p>Emacs users often tout SLIME as one of Emacs' "killer features". When writing
|
||
|
LISP code it's unchallengably awesome.</p>
|
||
|
|
||
|
<p>Vim doesn't have anything like SLIME. It's not integrated with any language the
|
||
|
way Emacs is coupled to LISP. You can, however, achieve <em>some</em> of the power of
|
||
|
SLIME in Vim.</p>
|
||
|
|
||
|
<p><a href="http://technotales.wordpress.com/">Jonathan Palardy</a> has written a little Vim plugin called <a href="http://technotales.wordpress.com/2007/10/03/like-slime-for-vim/">Slime.vim</a> that
|
||
|
lets Vim easily communicate with a screen session, probably one running a REPL
|
||
|
for some language like LISP, Python or Ruby.</p>
|
||
|
|
||
|
<p>The general idea is that you'll fire up LISP in a screen session, then go over
|
||
|
to Vim and use <code>Ctrl+C Ctrl+C</code> to put chunks of code in your Vim window into
|
||
|
the screen session.</p>
|
||
|
|
||
|
<p>It works and is quite handy for when you want to experiment with the contents
|
||
|
of a file. Add a mapping for shoving over the entire file and you're all set to
|
||
|
bash out and test some code quickly.</p>
|
||
|
|
||
|
<p>I personally use <a href="http://bitbucket.org/sjl/dotfiles/src/tip/vim/plugin/slime.vim">a slightly modified version</a> that removes a bit of
|
||
|
the flexibility I don't need to make it quicker to use. Maybe some day I'll
|
||
|
expand on it and push it up to BitBucket and GitHub in a repo of its own.</p>
|
||
|
|
||
|
<h3 id="s27-scratch"><a href="index.html#s27-scratch">Scratch</a></h3>
|
||
|
|
||
|
<p>The <a href="http://www.vim.org/scripts/script.php?script_id=664">Scratch</a> plugin adds a function to quickly open a "scratch" buffer that
|
||
|
will never be saved.</p>
|
||
|
|
||
|
<p>I have it mapped to <code><leader><tab></code> and use it with slime to quickly stick
|
||
|
a bit of code that I don't want in my actual file into the REPL.</p>
|
||
|
|
||
|
<h3 id="s28-rainbow-parentheses"><a href="index.html#s28-rainbow-parentheses">Rainbow Parentheses</a></h3>
|
||
|
|
||
|
<p><a href="http://www.vim.org/scripts/script.php?script_id=1561">Rainbow Parentheses</a> is a Vim plugin that colorizes parentheses, square
|
||
|
brackets, curly brackets and angle brackets according to their nesting.</p>
|
||
|
|
||
|
<p>It's easiest to describe what this looks like with a screenshot:</p>
|
||
|
|
||
|
<p><img src="http://stevelosh.com/static/images/blog/2010/09/rainbow.png" alt="Rainbow Parentheses Screenshot" title="Rainbow Parentheses"></p>
|
||
|
|
||
|
<p>I use <a href="http://bitbucket.org/sjl/dotfiles/src/tip/vim/bundle/rainbow/">a slightly modified version</a>. I have it mapped to <code><leader>R</code>
|
||
|
and off by default. When I'm dealing with a particularly hairy piece of code
|
||
|
that has lots of nesting I simply hit <code><leader>R</code> and get some color that helps
|
||
|
me keep my place.</p>
|
||
|
|
||
|
<h2 id="s29-things-i-want"><a href="index.html#s29-things-i-want">Things I Want</a></h2>
|
||
|
|
||
|
<p>Although Vim is definitely my new favorite editor, this blog post wouldn't be
|
||
|
complete without a few complaints.</p>
|
||
|
|
||
|
<p>If anyone fixes/implements any of these I'll gladly buy them several beers.</p>
|
||
|
|
||
|
<h3 id="s30-html-indentation-that-doesn-t-suck"><a href="index.html#s30-html-indentation-that-doesn-t-suck">HTML Indentation that Doesn't Suck</a></h3>
|
||
|
|
||
|
<p>I write a lot of HTML. One thing that annoys the hell out of me is Vim's
|
||
|
"smart" indenting of HTML. I've tried every combination of <code>cindent</code>,
|
||
|
<code>smartindent</code> and <code>autoindent</code> and I can't seem to get Vim to behave sanely.</p>
|
||
|
|
||
|
<p>The problem is that sometimes when I press return after a tag that I've already
|
||
|
created Vim will unindent the new line <em>and the previous line</em>. This is
|
||
|
excruciatingly annoying.</p>
|
||
|
|
||
|
<p>All I want is the following:</p>
|
||
|
|
||
|
<ul>
|
||
|
<li>When I press return, create a new line at the same indentation level as the
|
||
|
current one. Don't try to be clever and adjust the indent of new line in
|
||
|
any fashion.</li>
|
||
|
<li>If I press tab at the beginning of a line, indent the <em>current line</em> by
|
||
|
one tabstop.</li>
|
||
|
<li>If I press backspace at the beginning of a line, delete one tabstop on that
|
||
|
line only.</li>
|
||
|
</ul>
|
||
|
|
||
|
<p>Please, someone make this happen and restore my sanity.</p>
|
||
|
|
||
|
<h3 id="s31-python-support-for-slime"><a href="index.html#s31-python-support-for-slime">Python Support for Slime</a></h3>
|
||
|
|
||
|
<p>Earlier I mentioned that I use the slime plugin. One language it doesn't work
|
||
|
very well with is Python, because it preserves whitespace when it moves the
|
||
|
code over the REPL.</p>
|
||
|
|
||
|
<p>This is a problem with Python because if you try to move over an indented block
|
||
|
of code you'll get "unexpected indent" problems.</p>
|
||
|
|
||
|
<p>I'd love for someone to tweak slime so it intelligently unindents Python code.
|
||
|
I have some ideas on how this could work but unfortunately I don't have the
|
||
|
time to implement them.</p>
|
||
|
|
||
|
<h3 id="s32-gundo"><a href="index.html#s32-gundo">Gundo</a></h3>
|
||
|
|
||
|
<p>A little-known fact about Vim is that it doesn't keep a list of your undo
|
||
|
history, it keeps a <em>tree</em>.</p>
|
||
|
|
||
|
<p>If I make 5 changes, undo 2 and then make 2 more Vim keeps track of <em>all</em> of
|
||
|
them. You can use <code>:undolist</code> to see the list of leaves in this "undo tree".</p>
|
||
|
|
||
|
<p>What I want is for someone to make an awesome "graphical undo" plugin that
|
||
|
shows a graph of the undo tree, much like Mercurial's graphlog extension shows
|
||
|
a graph of the changesets in a repository.</p>
|
||
|
|
||
|
<p>This graph would actually be simpler than Mercurial's graphlog because there
|
||
|
are no merges to deal with.</p>
|
||
|
|
||
|
<p>For bonus points let me browse the tree with <code>j</code> and <code>k</code>, press <code>p</code> to preview
|
||
|
a diff of what would happen if I went back to that version, and press <code><CR></code> to
|
||
|
actually go back.</p>
|
||
|
|
||
|
<p><strong>UPDATE:</strong> I got tired of waiting, so I <a href="http://bitbucket.org/sjl/gundo.vim/">wrote it myself</a>.</p>
|
||
|
|
||
|
<h3 id="s33-a-mercurial-version-of-fugitive"><a href="index.html#s33-a-mercurial-version-of-fugitive">A Mercurial Version of Fugitive</a></h3>
|
||
|
|
||
|
<p>The final thing I'd like is for someone to make a Mercurial plugin for Vim that
|
||
|
is as awesome as Tim Pope's <a href="http://github.com/tpope/vim-fugitive">Fugitive</a>.</p>
|
||
|
|
||
|
<p>There's some Mercurial support for Vim out there, but for the most part it's
|
||
|
tied up in plugins that support multiple version control systems.</p>
|
||
|
|
||
|
<p>Any plugin that tries to support every system will fail at supporting one
|
||
|
single system perfectly, so I'd love for someone to come along and make an
|
||
|
<em>awesome</em> Vim plugin that lets you use Mercurial to its fullest while
|
||
|
inside Vim.</p>
|
||
|
|
||
|
<p>I simply don't know vimscript well enough to do this on my own, but if someone
|
||
|
else is interested I can certainly help out on the Mercurial and user interface
|
||
|
aspects.</p>
|
||
|
|
||
|
<h2 id="s34-overall-thoughts"><a href="index.html#s34-overall-thoughts">Overall Thoughts</a></h2>
|
||
|
|
||
|
<p>Transitioning back to Vim after using TextMate for a few years wasn't trivial,
|
||
|
but I feel that it was worth the effort. I have features like split windows
|
||
|
now and there are plugins that can provide anything I miss from TextMate.</p>
|
||
|
|
||
|
<p>If TextMate 2 ever gets released it would have to do some pretty amazing things
|
||
|
for me to want to switch back.</p>
|
||
|
|
||
|
<p>Overall I'm very happy with Vim. There are a lot of things that could be
|
||
|
improved, especially with the default settings (who cares about vi
|
||
|
compatibility in 2010?), but a text editor is worth a learning curve.</p>
|
||
|
|
||
|
<p>In my eyes Vim has two huge advantages over almost any other editor out there.
|
||
|
The first is it's <em>huge</em> ecosystem of plugins and syntax definitions, which is
|
||
|
only rivaled by Emacs (and <em>possibly</em> TextMate, though I doubt it). The second
|
||
|
is it's "modal editing" philosophy, which is extremely powerful and hasn't been
|
||
|
adopted by any other mainstream editor (except for <em>very</em> recent versions of
|
||
|
E).</p>
|
||
|
|
||
|
<p>If you've got questions or comments you should <a href="http://twitter.com/stevelosh/">find me on Twitter</a> and
|
||
|
let me know.</p>
|
||
|
</article></main><hr class='main-separator' /><footer><nav><a href='https://github.com/sjl/'>GitHub</a> ・ <a href='https://twitter.com/stevelosh/'>Twitter</a> ・ <a href='https://instagram.com/thirtytwobirds/'>Instagram</a> ・ <a href='https://hg.stevelosh.com/.plan/'>.plan</a></nav></footer></body></html>
|