
Steve Losh's .vimrc - earnubs
https://bitbucket.org/sjl/dotfiles/src/tip/vim/.vimrc
======
xutopia
For those wondering who Steve Losh is. He's the creator of a few vim projects
and is writing "Learn VimScript The Hard Way".

<http://stevelosh.com/projects/>

------
nickknw
I didn't know this was possible:

    
    
        " Resize splits when the window is resized
        au VimResized * exe "normal! \<c-w>="
    

That's really handy. Also, this part made me smile:

    
    
        " Heresy
        inoremap <c-a> <esc>I
        inoremap <c-e> <esc>A

~~~
swah
(I love both editors)

That's something disgusting about Vim - mapping to other keys instead of
commands. In Emacs its much nicer IMO:

    
    
        (global-set-key (kbd "C-a") 'beginning-of-line)

~~~
stevelosh
Disgusting but practical. I already know the keys on the right because I use
them every day. If it were a function I'd have to look it up first.

~~~
undees
Is there a Vim equivalent of Emacs's C-h k followed by the key combo, which
basically says, "Tell me what the official command name is for this
keystroke?"

~~~
similarthough
I don't know of anything quite like that but the help can be searched by key,
though only for the default key combinations, e.g. ":h i^a" would show the
docs for the ctrl-a command in insert mode.

Note though that vim really doesn't have commands the same way as emacs does.
That's why you generally see assigning one key combination to another instead
of some "command name."

------
zmanji
I think that having all of this in one file is too crazy. I suggest putting
some of the stuff in the appropriate files in ftplugins, etc in your ~/.vim
directory.

~~~
stevelosh
Some of this definitely belongs in separate files.

The problem is that most of these are things I came up with when, during the
middle of coding, I thought "oh, this would be really nice". So I just
switched to my vimrc, added it, and got back to working, instead of thinking
about where to put it, creating new files, etc.

Every so often I'll go through and clean it up. I just haven't gotten around
to it for a long time since it works perfectly fine as is.

------
spatten
If you want to learn how to do this yourself, let Steve know here:
<http://leanpub.com/learnvimscriptthehardway>

------
mmavnn

        function! NyanMe() " {{{ ...
    

I very much hope that's just there as an easter egg for those of us who read
to the bottom.

~~~
stevelosh
Actually I'm planning on splicing it into MakeGreen, so instead of getting a
green bar when my tests pass I get Nyan Cat flying across my window. Maybe
over Thanksgiving weekend I'll get around to it.

Edit: Also, if anyone can show me how to draw an ASCII-art Nyan Cat in one
line of text that would be awesome. Nothing I tried looked recognizable.

~~~
gerggerg
how bout 2 lines? <http://jsfiddle.net/MHj9N/>

~~~
xer0x
Ascii Nyan cat!! Thank-you! My mind just melted.

------
LeafStorm
That's one thing that worries me about using vim full-time: if I become
reliant on a .vimrc or a set of plugins to use vim effectively, but I'm on a
computer that doesn't have my .vimrc on it, I'm doomed.

~~~
billybob
I feel exactly the opposite. The previous editors that I used required
configuration through a menu system. I wouldn't have known how to take that
with me elsewhere.

With Vim, all my configuration is in files, which can be backed up. I have
them in a dotfiles repo on Github. As I make tweaks, I regularly pull and push
from my various computers and they are always up to date. If I'm on a computer
that doesn't have my .vimrc, I'm just a `git pull` away from having it. (Same
goes for zsh config, etc.)

The most likely time for me not to have my .vimrc is when sshing into a
server, in which case I can use stock vim just fine. If my main editor were a
GUI, I wouldn't have it available at all, so I think Vim has a leg up in that,
too.

~~~
billybob
By the way, if you're ever confused about what behavior is native and what
comes from your config, use the `-u "NONE"` option to run vanilla vim (or
macvim or gvim).

------
factorizer
vimscript really is an abomination. vim users of the world unite! and create a
proper macro language for your editor. and no: running an external
python/ruby/brainfuck process does not count.

~~~
fferen
I dunno, I think the Python interface is adequate. Not great, but gets the job
done. I write almost all my Vim scripts in Python.

~~~
sashahart
Using Python and other runtimes is often kind of slow - it's not a huge deal
but if you have a lot of this stuff in your config, then vim might start up
only like 8 times faster than Eclipse.

The other thing is that the Vim API you use in these other languages is pretty
much Vimscript anyway.

For me, Vimscript is basically a normal imperative language in the general
neighborhood of perl and shell... I agree it is more awkward to write than
Python, particularly with escaping. But it's a decent DSL for configuring text
editors, and Python isn't as much.

~~~
fferen
The two advantages of using Python for me are being able to use utilities I've
already written, and the comprehensive standard library.

For example, I wrote a macro to split long Python function calls into multiple
lines, and I could access a parsing function that I already wrote, along with
Python's own compile() to detect when I've parsed a complete expression (yes,
this one is Python-specific).

I also wrote a macro to submit the current file to a private pastebin, and
AFAIK you can't make web requests with Vimscript.

------
kgroll
Here's a commented version of my .vimrc, which is modeled after Steve's,
albeit nowhere near as comprehensive. (Looks like I lost it's fixed width in
the paste? Sorry!)

<http://pastebin.com/jJQFxQpR>

For me it's a lot quicker to reference comments than the :help entry for each
option. Thought it might help others who are creating/modifying their .vimrc.

And of course, thanks Steve for continuing to share your stuff. I'm in love
with Vim, and a lot of that's thanks to you.

~~~
weaksauce
Here is the code in a more readable gist without fixed width:

<https://gist.github.com/1377245>

------
klauern
If anyone stumbles on this problem when grabbing the Clojure configs, I found
that the TurnOnClojureFolding() method was missing:
[https://bitbucket.org/sjl/dotfiles/src/27ec8da23760/vim/.vim...](https://bitbucket.org/sjl/dotfiles/src/27ec8da23760/vim/.vimrc#cl-357)

But, a bit of Googling will find it (works pretty well, too):
<http://writequit.org/blog/?p=413>

------
marshray
I'm sure I've seen this in vim, but I can't find it now. Isn't there a
statusline config item that shows any pending command prefix chars you've
typed?

~~~
beaumartinez
I think you want _:set showcmd_ —"Show partial command in the last line of the
screen".

~~~
marshray
THAT'S IT! My long lost friend is back! Thank you!

------
sashahart
I also have a huge vim configuration: <https://github.com/sashahart/.vim>

I highly recommend putting your vim configuration on github or similar, you
don't have to worry about losing your config and it gets easier for everyone
to learn the new tricks

~~~
stevelosh
I'm stealing "nnoremap <CR> o<ESC>" immediately. Thanks!

------
JoshTriplett

        nnoremap <leader>ev <C-w>s<C-w>j<C-w>L:e $MYVIMRC<cr>
    

:vsplit $MYVIMRC and so on would work the same way, but more obviously, and
without depending on the placement of split windows.

------
shortlived
What do the triple open and close curly braces represent?

~~~
stevelosh
They're fold markers. When I open my vimrc in Vim it looks like this:
<http://d.pr/YKCM>

~~~
shortlived
Why doesn't my Vim fold things automatically? What options am I missing?

~~~
nickknw
Either

    
    
        set foldmethod=marker
    

Or put this modeline at the top of your .vimrc:

    
    
        " vim: foldmethod=marker foldlevel=0

------
robbles
inoremap # X<BS>#

This has been annoying me forever, but I never got around to fixing it. Not
sure how the solution works, but it does!

~~~
graywh
This is probably b/c you're using 'smartindent' or 'cindent' all the time.
Don't. The former is deprecated by the latter and they're only for C-like
syntax--hence why # belongs in column 0. If you want filetype-specific
indenting, you just need "filetype indent on".

------
bobbyi
I find semicolon and comma to be very useful so I am surprised when I see
people remap them or use them as leader.

------
michaelty
I love reading these files and finding something new to use. gdefault is
definite going in.

~~~
gaving
Ugh. Be careful with that, since actually giving a /g has the effect of
toggling the behaviour all together.

From :help 'gdefault':-

    
    
        :help 'gdefault'
        'gdefault' 'gd'		boolean	(default off)
        global
        {not in Vi}
        When on, the ":substitute" flag 'g' is default on.  This means that
        all matches in a line are substituted instead of one.  When a 'g' flag
        is given to a ":substitute" command, this will toggle the substitution
        of all or one match.  See |complex-change|.
    
        command		'gdefault' on	'gdefault' off	~
        :s///		  subst. all	  subst. one
        :s///g		  subst. one	  subst. all
        :s///gg		  subst. all	  subst. one
    

While not quite documented under ":help :s_flags", two 'g' flags cancel each
other out. This also applies to 'gdefault'.

Also, be aware that this may break a huge amount of scripts out there, should
you decide to use it as some (hard to debug) issues are caused because of it.

~~~
stevelosh
I've had this set for a while now and haven't noticed any scripts breaking.
It's _far_ more common for scripts to break because I'm remapped something and
they used 'nmap' instead of 'nnoremap' or 'normal' instead of 'normal!'.

Whenever a script breaks, I bite the bullet and fix it, fork it on Github,
switch my dotfiles repo to use my fork and send a pull request. If they merge
my fix I switch my dotfiles repo back.

It's a pain in the ass, but I like to think that it helps other Vim users a
little bit.

------
riffraff
I like PulseCursorLine, but I wonder why only on N and n? (e.g. not on *)

~~~
stevelosh
Because I have Vim set up to not move at all when I press star, so there's no
point in pulsing the line:

    
    
        " Don't move on *
        nnoremap * *<c-o>

------
rplnt
Does this affect performance in any way? 1k+ lines is quite a lot.

~~~
stevelosh
In _any_ way? Of course.

But my laptop has 8 _gigabytes_ of RAM, a solid state hard drive, and _four_
processor cores.

I can run Minecraft at the highest settings while accidentally leaving a Linux
VM running in the background. Loading a 1.5k vimrc file is barely a blip on
the processor graph.

------
sramov
God bless nvi.

I will never understand why people go out of their way to write and maintain
such monster configuration files.

Learning core/traditional vi gets one a long way, instead of delusioning
themselves with false cleverness and productivity.

~~~
exDM69
I don't think that the author wrote his 1200 lines of .vimrc in one sit. More
likely it's years of accumulated 1-2 line additions and removals.

My vimrc has slowly accumulated, I add 1 or 2 new keybinds every now and then
and I might remove them later if I notice they don't suit my workflow. Most of
my changed keybindings are related to making Vim usable with my native
keyboard layout (finnish/swedish).

Also per-language additions accumulate over time. The author seems to have put
all settings for all file types in the same file.

Learning standard Vi gets you a long way, but sometimes adding or changing a
keybind will make things work more fluently.

~~~
sramov
My point was, time better spent is coding, not dicking around (and relying) on
.vimrc.

We often forgot about the essence of things such as typing the actual code or
words, and focus on tools. Better investment is learning how to properly type
than having countless little helpers which are nothing more than debt.

Increasing complexity in all areas of life really is troublesome.

~~~
viraptor
I think you're thinking about it backwards. It's usually not thinking "what
could I tweak today" that results in adding something to .vimrc. It's "I keep
doing this a lot / this feel uncomfortable, maybe there's an easier way" that
results in changes. And if you take time to actually implement it, that's a
good indication it was worth the tweak.

Let's say you work with splits a lot. Sure you could press ctrl+w all the
time, but it's a bit annoying. Rebinding doesn't take much time, but makes it
(in the presented example) actually simpler. So did it waste time? A minute or
so. Does it make life easier? A little bit. Did the "coding time" suffer? Who
cares about a minute or so ;)

------
dbbo
Anyone who knows who sjl is could have easily found his vimrc through his
website. According to the bitbucket history, the file has been hosted there
since at least 2009.

~~~
derwiki
Which doesn't make it less useful. And for those of use who don't know sjl,
this was useful.

~~~
dbbo
Did I say it wasn't useful? Maybe you missed my point.

I could post a link to a perldoc page for some builtin function, and that
would be useful, and it's probably been around for awhile, and probably nobody
knows who wrote it. Would you defend that too?

------
xerxes2001
Can we now have a long discussion about profanity in dotfiles?

~~~
skimbrel
There should be more of it.

