Yan Pritzker photographer, entrepreneur, software engineer, musician, skier

Blog :: Git Workflows Book :: Dotfiles :: Photography :: About Me

TwitterCounter for @skwp

Get the news feed
Get updates by email
Follow me on twitter

hello, i'm yan

I am a photographer, entrepreneur, software engineer, guitarist, climber, and telemark skier

This blog is about startups, blogging, Ruby On Rails, virtualization and cloud computing, photography, customer service, marketing, ux and design, git, and lots more.

I am the chief technical something or other at Reverb.com - The Marketplace for Musicians. We're hiring web designers!

Recent Tweets

Selected Reading

Archives

Contact

Reach me at yan at pritzker.ws

The cleanest vimrc you’ll ever see

Posted 20 January 2012 @ 12pm in vim



Submit to HN

So many of us use vimrc files that are a frankenstein’s monster, cobbled together from spare parts, gists, and snippets from wikis. One day I decided I was no longer going to treat my vimrc as a garbage dump. As programmers, we strive toward well factored code, so why do we accept such ugly vimrc’s that are impossible to understand, and even worse impossible to share because of their complexity. Let’s stop the insanity! It turns out it’s very easy…

Since vim automatically loads everything in ~/.vim/plugin/, you can just add a directory like ~/.vim/plugin/settings and put each semantic piece in its own snippet. Put your keymaps in ~/.vim/plugin/settings/keymap.vim. Put your visual setup like font and colors into ~/.vim/plugin/settings/gui.vim, etc.

After I did this, I ended up with a vimrc that’s only about 90 lines long including very detailed comments about every section.

I think this is the cleanest vimrc you’ll see on the web. All my vim plugin settings are broken down into individual files, following a convention of one file per vim plugin that I use, plus some extra ones that are too small to be plugins.

Think your vimrc is better? Show me! I want to learn :)

My vimrc and the rest of my vim setup is available as part of my YADR (Yet Another Dotfiles Repo) project. Come check it out, I need alpha testers!

40 Comments

Posted by
Jay Graves
20 January 2012 @ 12pm

Very timely. Just this week I gave myself a TODO so my various VIM configs (work windows, work linux, home windows, home linux) were in sync.

But I stated it: “Startover with VIM”

I’ll check it out.


Posted by
Apreche
20 January 2012 @ 1pm

My vimrc is definitely cleaner than yours.

https://github.com/Apreche/vim/blob/master/vimrc

The real answer to making your vimrc cleaner is to stop using all those customizations. You don’t need them. If you haven’t become a complete master of all the defaults of vim, then you don’t need to add more features you don’t need anyway.

The only things I change are fonts, syntax highlighting, colors, indentation, and not much else.


Posted by
Kristian
20 January 2012 @ 2pm

Are you guys really jerking off over who has a better vimrc file? Get a hotel room already.


Posted by
Tony
20 January 2012 @ 3pm

One thing you do have kind of wrong in there is your guard around undofile and undodir – these setting are not dependent upon the GUI or MacVim, they are new features in Vim 7.3, so your guard should be:

if version >= 703


Posted by
Yan
20 January 2012 @ 3pm

@Tony thanks! an example of something I did early in my vim experimentations without bothering to learn. Will fix this.


Posted by
Chris Smith
20 January 2012 @ 4pm

Mine goes:

syntax on
colorscheme blue

That is it. There is no ~/.vim


Posted by
Chris
20 January 2012 @ 4pm

I spent a fair amount of time on my vim config, and tried to organize it into something to share with a few folks: http://github.com/csexton/viceroy

I am all for knowing the default vim, but it’s vim — the true power is being able to make it do what you want. Even Bram talks about how bloated his vimrc is.


Posted by
Eric
20 January 2012 @ 5pm

Yan,

I’m a community curator at DZone.com, and I recently read your blog post entitled “The cleanest vimrc you’ll ever see.” I was impressed by the quality of your writing, as well as the healthy response from your commenters. At DZone.com, we post quality content for the benefit of our community, as well as providing some much deserved exposure for good bloggers.

May I have permission to republish your blog post titled “The cleanest vimrc you’ll ever see”?

Shoot me an email if you’re interested.

Best,

Eric


Posted by
Yan
20 January 2012 @ 8pm

@Chris – viceroy looks interesting, I’ll take a peek and see what learnings may come. Looks a bit Janus-y in the way it handles bundles with a config file. I decided that I was going to use git submodules and not worry about having a config file, to keep things simpler, but there are probably tradeoffs on both sides.

The nice thing with a config-less approach is that if I want to try out a cool vim plugin I see on git, I just run a command like “yav -u http://github.com/foo/some-vim-plugin” and I have that plugin downloaded.

@Eric that sounds great. I will email you.


Posted by
Chris
20 January 2012 @ 8pm

@Yan It is a bit Janus like, but there were some things I really disagreed with in Janus so I rolled my own. Not that Janus is bad or anything, I just wanted something different.


Posted by
yan
20 January 2012 @ 8pm

@Chris that’s why I started doing the YADR project as well. Janus felt a little overcomplicated, and it didn’t really have the best plugins by default either. In addition to removing the idea of config files, I’m also being very strict in what it will support (i.e. only one color scheme, and only MacVim, and ensuring that every plugin I add looks good in that color scheme). I think once more people are forking it, it will become tempting to add support for other things, but I’m going to try to stay strong and opinionated to ensure that the core of the product works well. That said, I am always looking to learn from other projects and I’m going to have a look at your viceroy :)


Posted by
Igor
21 January 2012 @ 3am

You should give Sublime Text 2 a try :) It’s pretty hot.


Posted by
yan
21 January 2012 @ 3am

@Igor sublime is pretty…and it has some nice features. one of my friends at work uses it. but I can’t say it will replace vim for me because of the overall keystroke savings I get from vim


Posted by
sunaku
21 January 2012 @ 2pm

Hey, I thought *mine* was the cleanest of them all:

” delegate configuration to files in config/
runtime! config/**/*.vim

As you can see, it’s [not a single giant vimrc file](https://github.com/sunaku/.vim#readme)!


Posted by
sunaku
21 January 2012 @ 3pm

Nice tip about ~/.vim/plugin/**/*.vim being autoloaded on startup. I followed suit and replaced “runtime! config/**/*.vim” in my vimrc with nothing. Cheers.


Posted by
Matael
21 January 2012 @ 3pm

Mine is only… 8 lines long… And vim does exactly what I need :

syntax on
filetype plugin indent on
au BufNewFile,BufRead *.pde setf arduino
au BufNewFile,BufRead *.mkd setf mkd

set statusline=%F%m%r%h%w\ %{fugitive#statusline()}\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [LEN=%L]
set laststatus=2


Posted by
richard bucker
21 January 2012 @ 6pm

In theory I really like your approach to you vim layout. It has a certain elegance that I really like. Now I know you heard me say that I like it and I do not want to detract from that… however (aka but), since you installed NERDTree and possibly other plugins that have certain dependencies I start to get a little scrambled. Your approach could be seriously improved if there were a GEM or PEAK like installer that would install the dependencies. And while I’m on the RUBY thing I hope your plugins that depend on RUBY are capable of running within RVM.

Other than that, really nice work.


Posted by
Matt
31 January 2012 @ 1pm

Well, I thought mine was pretty darn clean…

https://github.com/mattdbridges/dotfiles/blob/master/vim/vimrc


Posted by
Matt
31 January 2012 @ 6pm


Posted by
Jean
23 February 2012 @ 6pm

No mine but kind of unique!
http://amix.dk/vim/vimrc.html


Posted by
Ewan
3 March 2012 @ 6pm

Stupid question (I’m very, very new to Vim), but how should I make changes to ~/.vimrc?

I.e. can I edit it directly, or does YADR expect changes to be made elsewhere? I ask because when I try to update I get:

error: Your local changes to the following files would be overwritten by merge:
vimrc
Please, commit your changes or stash them before you can merge.

Thanks! YADR is making the switch from TextMate much easier :-)


Posted by
Yan
6 March 2012 @ 5pm

@Ewan if you pull the latest version (just updated), there is support for ~/.vimrc.after – so you can put your changes in that file and it will be read


Posted by
Ewan
8 March 2012 @ 8am

Thanks – that works great.

While I’m at it, adding plugins:

The README says to use “yav”, but I’ve never got that working. Instead, I just drop entire package folder (e.g. vim-latex) into ~/.vim/bundle/, which seems to work fine.

Is this OK?

Thanks!!


Posted by
yan
9 March 2012 @ 4am

@Ewan that should be just fine. What sort of errors did you get on using yav? I am still debugging things as this is an alpha product, but I want to polish it up. If you don’t mind, please open issues on github, that’s the best way to reach me for YADR support . thanks!


Posted by
Ewan
13 March 2012 @ 5am

@Yan Thanks.

> please open issues on github

Will do in future. Wasn’t sure where the best place for support-type questions were. Thanks for all your efforts on YADR – very much appreciated.


Posted by
Qian
22 May 2012 @ 9pm

I need vim expert help. Every time I copy a few lines from Windows Firefox page to my vim xterm, it would insert at least one blank line after each line. This is really annoy!

How do I disable this automatically adding blank lines?


Posted by
yan
29 May 2012 @ 3am

@Qian, Are you using paste mode? Try using

:set paste

[...] The cleanest vimrc you’ll ever see [...]


Posted by
Kris
28 June 2012 @ 2pm

YADR kicks ass. I’m incredibly please with this set up. Thank you so much!


Posted by
yan
26 July 2012 @ 5pm

Thanks @Kris I am glad it’s working out for you!


Posted by
Michael Scheper
15 August 2012 @ 11pm

My .vimrc has grown into quite a beast over my 12 or so years of being a vim fanatic. (This doesn’t include the preceding in which I plodded along with vi, ignorant of the power I had if only I RTFM.) Conventions have changed in that time, and I’m honestly not sure where the best place is to put things these days.

I’m finally doing the big clean-up I’ve procrastinated for years. Thanks for the ideas to get me started!


Posted by
Roy Mathur
31 October 2012 @ 6pm

Beat this!

"File     :_vimrc
"Required :vim 7.1+
"Language :VimScript
"Title    :Multiplatform GVIM/VIM Cinfiguration File
"Author   :Roy Mathur, Roy.Mathur@gmail.com, http://www.roymathur.com
"Copyright:(C)Roy Mathur 2009-2011
"Notes    :Less intrusive than Cream config file for GVIM/vim
"          Based on thousands of other peoples' uncredited tweaks that I
"          ruthlessly appropriated to further the greater good of
"          sentient-kind throughout the known and unknown multiverse.  
"          Built-in colour scheme, CUA shortcuts and console menu
"          ativated by pressing F5.
"
"Ver Hist :v 1.0 Fri 5 Aug 2011
"          ----------------------
"          Public release version to be distributed with CaptRoyzAppz, just fiddled with menu and some of the hotkeys.  
"
"Ver Hist :v 0.02 Fri 10 Jul 2009
"          ----------------------
"          Still tweaking.
"
"          v 0.01 Fri 30 Jan 2009
"          ----------------------
"          Actually started a few years back, but never bothered to comment it.
"
"****************************************************************************
"****************************************************************************
"
"set GVim/Vim locations
"----------------------
"let $VIM = "/appz/Code/vim"
"let $VIMRUNTIME = "/appz/Code/vim" } ignore this section as vars set in external shell scripts gvim/vim.bat
"let $HOME = "/appz/Code/vim"
"
"GVim Only Options
"-----------------
set guifont=Courier_New:h10
set antialias
set guioptions+=b "show horizontal scroll bar
"
"GVim/Vim Options
"----------------

"General Settings
"----------------
set nocompatible               "Use Vim settings instead of Vi
"set backspace=indent,eol,start "allow backspacing over everything in insert mode
set viminfo+='10,\"100,:1,n$VIM/_viminfo
                               "Where-
                                   "'10           = Marks will be remembered for the last 10 files you edited.
                                   "100           = Contents of registers (up to 100 lines each) will be remembered.
                                   ":1            = Command-line history will be saved.
                                   "$VIM/_viminfo = The name of the file to use.
"set viminfo=""                "disable viminfo
set directory=$VIM             "Save swap files...
set backupdir=$VIM             " ...and backup files here.
set history=1000               "Remember last n commands.
set number                     "Turn line numbering on.
syntax on                      "Syntax highlighting on.
set foldmethod=syntax          "Enable code folding.
set showmatch                  "Show briefly matching bracket when closing it.
set ttyfast                    "Smoother redraws.
autocmd InsertLeave * se nocul "Highlight current line in insert mode.
autocmd InsertEnter * se cul   "Unhighlight current line when not in insert mode.
set sessionoptions+=unix,slash "Store session info in Unix format.
set ignorecase                 "Make searches case-insensitive.
set nowrap                     "Start with line wrapping off.
set shortmess=I                "Disable startup screen.

"Tabs and Whitespace
"-------------------
set autoindent                 "Autoindent should also be on when using smartindent...
set smartindent                " ...smart autoindenting when starting a new line (see :help smartindent).
set tabstop=4                  "number of spaces the TAB key will indent while editing with gvim
set shiftwidth=4               "number of spaces the lines will be shifted with ">>" or "<<" vi commands
set expandtab
"set list                      "display non-printing characters
"set listchars=tab:>-,trail:-  "choose characters to show non-printing characters

"Movemment
"---------
set mouse=a                    "Enable full mouse support in the console.
map j gj
                               "}map j to gj and k to gk, so line navigation ignores line wrap
map k gk

"Status Bar
"---------
set ruler                      "turn on status bar
set showmode                   "display the current mode in the status line
set showcmd                    "show partially-typed commands in the status line
set laststatus=2               "always show status line
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [LEN=%L] "show every damn thing in status bar
"
"console menu!
"-------------
:source $VIM/menu.vim
:set wildmenu
:set cpo-=<
:set wcm=<C-Z>
:map <F5> :emenu <C-Z>
"
"Kill Beeps
"----------
"This diables stupid errorbell and, horrible, epilepsy inducing visual bell
set noerrorbells
set visualbell
set t_vb=
"
"MS Windows-like behaviour
"-------------------------
so $VIM/mswin.vim
behave mswin
"
"Extra CUA-like Commands
"-----------------------
"
"CTRL+O Open
:map <C-o> :exe "20vsp " . expand("%:p:h") <CR>
"
"CTRL+N New (to the right)
:map <C-n> :vnew <CR><C-w>r
"
"CTRL+S Save
:map <C-s> :confirm w <CR>
"
"F4 Close
:map <F4> :close <CR>
"
"ALT+P
:map <M-P> :%s/$/\r/g\|:hardcopy!<CR>
"
"ALT+X Exit
:map <M-x> :confirm qa <CR>
"
"CTRL+F Find
:map <C-f> :/findThis
"
"CTRL+R Replace
:map <C-r> :firstLine, lastLine s/replaceThis/withThis/
"
"F3 RepeatCmd
:map <F3> n <CR>
"
"F7 Word Processor Mode On
:map <F7> :set linebreak <CR> :set display+=lastline <CR> :set wrap <CR> :setlocal spell spelllang=en_gb <CR>
"
"F8 Word Processor Mode Off
:map <F8> :set nowrap <CR> :set nospell <CR>
"
"ALT+1 Hex Edit Mode On
:map <M-1> :%!xxd <CR>
"
"ALT+2 Hex Edit Mode Off
:map <M-2> :%!xxd -r <CR>
"
"ALT+3 Save Current State
:map <M-3> :mksession! $VIM/lastsess.vim <CR>
"
"ALT+4 Restore Last State
"
:map <M-4> :source $VIM/lastsess.vim <CR>
"
"ALT+5 Terminal
:map <M-5> :shell <CR>
"
"F2 About
:map <F2> :echo "Less intrusive than cream configuration for GUI and console versions Vim with a theme for colour and non-colour terminals.  One vimrc to rule them all! (C)Roy Mathur 2011.  " <CR>
"
"...same shortcuts now in Menu
"Menu
"window title
:set titlestring=CaptRoyzVim\ (Press\ F5\ for\ console\ menu)\ %t%(\ %M%)%(\ (%{expand(\"%:~:.:h\")})%)%(\ %a%)
"menu
:5amenu CaptRoyzMenu.Open\  Ctrl+O :exe "20vsp " . expand("%:p:h") <CR>
:5amenu CaptRoyzMenu.New\   Ctrl+N :vnew<CR><C-w>r
:5amenu CaptRoyzMenu.Save\  Ctrl+S :confirm w<CR>
:5amenu CaptRoyzMenu.Save\ As\ (GUI)\ Only\  :browse confirm sav<CR>
:5amenu CaptRoyzMenu.Close\ F4 :close<CR>
:5amenu CaptRoyzMenu.Print\ Alt+P :%s/$/\r/g\|:hardcopy!<CR>
:5amenu CaptRoyzMenu.Exit\  Alt+X :confirm qa<CR>
:5amenu CaptRoyzMenu.-sep1- <Nop>
:5amenu CaptRoyzMenu.Find\  Ctrl+F :/findThis
:5amenu CaptRoyzMenu.Replace\   Ctrl+R :firstLine, lastLine s/replaceThis/withThis/
:5amenu CaptRoyzMenu.RepeatCmd\ F3 n<CR>
:5amenu CaptRoyzMenu.-sep2- <Nop>
:5amenu CaptRoyzMenu.Word\ Processor\ Mode\ On\ F7 :set linebreak <CR> :set display+=lastline <CR> :set wrap <CR> :setlocal spell spelllang=en_gb <CR>
:5amenu CaptRoyzMenu.Word\ Processor\ Mode\ Off\    F8 :set nolinebreak <CR> :set nowrap <CR> :set nospell <CR>
:5amenu CaptRoyzMenu.-sep3- <Nop>
:5amenu CaptRoyzMenu.Hex\ Mode\ On\ Alt+1 :%!xxd<CR>
:5amenu CaptRoyzMenu.Hex\ Mode\ Off\    Alt+2 :%!xxd -r<CR>
:5amenu CaptRoyzMenu.-sep4- <Nop>
:5amenu CaptRoyzMenu.Save\ Current\ State\  Alt+3 :mksession! $VIM/lastsess.vim<CR>
:5amenu CaptRoyzMenu.Restore\ Last\ State\  Alt+4 :source $VIM/lastsess.vim<CR><CR>
:5amenu CaptRoyzMenu.-sep5- <Nop>
:5amenu CaptRoyzMenu.Terminal\  Alt+5 :shell <CR>
:5amenu CaptRoyzMenu.-sep6- <Nop>
:5amenu CaptRoyzMenu.About\ F2 :echo "Less intrusive than cream configuration for GUI and console versions Vim with a theme for colour and non-colour terminals.  One vimrc to rule them all! (C)Roy Mathur 2011.  " <CR>
"
"****************************************************************************
"****************************************************************************
"
"Elflady is same(ish) for GUI, colour console and non-colour console versions of Vim
"(It's called 'Elflady' because I used 'Elflord' as a template to figure things out and because I fancy Galadriel)
"
hi clear
syntax reset
"
"GUI
hi Normal guifg=Cyan guibg=Black
hi Comment guifg=DarkGreen
hi Constant guifg=Magenta
hi Special guifg=Magenta
hi Identifier guifg=Cyan
hi Statement guifg=Blue
hi PreProc guifg=LightBlue
hi Type guifg=LightGreen
hi Function guifg=White
hi Repeat guifg=White
hi Operator guifg=Red
hi Ignore guifg=Black
hi Error guibg=Red
hi Todo guibg=Yellow
hi lineNr guifg=Red
hi CursorLine guibg=DarkRed
hi Cursor guibg=Cyan
hi VertSplit guifg=Cyan
hi StatusLine guifg=Cyan
hi StatusLineNC guifg=Cyan
hi NonText guifg=DarkBlue
"hi SpellBad
hi SpellCap guibg=Black
hi SpellRare guibg=Black
hi SpellLocal guibg=Black
"
"Colour Terminal
hi Normal ctermfg=Cyan ctermbg=Black
hi Comment ctermfg=DarkGreen
hi Constant ctermfg=Magenta
hi Special ctermfg=Magenta
hi Identifier ctermfg=Cyan
hi Statement ctermfg=Blue
hi PreProc ctermfg=LightBlue
hi Type ctermfg=LightGreen
hi Function ctermfg=White
hi Repeat ctermfg=White
hi Operator ctermfg=Red
hi Ignore ctermfg=Black
hi Error ctermbg=Red
hi Todo ctermbg=Yellow
hi lineNr ctermfg=Red
hi CursorLine ctermbg=DarkRed
hi Cursor ctermbg=Cyan
hi VertSplit ctermbg=Cyan
hi StatusLine ctermbg=Cyan
hi StatusLineNC ctermbg=Cyan
hi NonText ctermfg=DarkBlue
"hi SpellBad
hi SpellCap ctermbg=Black
hi SpellRare ctermbg=Black
hi SpellLocal ctermbg=Black
"
"
"Non-Colour Terminal
hi Comment term=bold
hi Constant term=underline
hi Special term=bold
hi Identifier term=underline
hi Statement term=bold
hi PreProc term=underline
hi Type term=underline
hi Function term=bold
hi Repeat term=underline
hi Error term=reverse
hi Todo term=standout
"
"Syntax
hi link String Constant
hi link Character Constant
hi link Number Constant
hi link Boolean Constant
hi link Float Number
hi link Conditional Repeat
hi link Label Statement
hi link Keyword Statement
hi link Exception Statement
hi link Include PreProc
hi link Define PreProc
hi link Macro PreProc
hi link PreCondit PreProc
hi link StorageClass Type
hi link Structure Type
hi link Typedef Type
hi link Tag Special
hi link SpecialChar Special
hi link Delimiter Special
hi link SpecialComment Special
hi link Debug Special

};->

Captain Roy


Posted by
Tristan Rentz
10 March 2013 @ 6pm

Hi all. I’ve just returned to Linux after a bit of a hiatus, and have installed Vim7.3, but am getting shitty just trying to locate .vimrc! Could you please illuminate me? It used to be so easy…


Posted by
Tristan Rentz
10 March 2013 @ 6pm

Just returned to Linux, have installed Vim7.3, and cannot for the life of me locate .vimrc! Please illuminate me; it used to be so easy..


Posted by
Ben
8 April 2013 @ 9am

Tristan, I hope you’ve found the .vimrc file by now as its been a month since you posted that. In case you haven’t, files and folders with a . in front of them are hidden. So if you type “ls”, these files won’t show up. You have to write “ls -a” to show hidden files and directories. Your .vimrc files i located in your home directory btw. To get there, type “cd ~”.


Posted by
att systems
8 April 2013 @ 6pm

Your style is unique compared to other people I have read stuff from.
Thank you for posting when you have the opportunity,
Guess I will just bookmark this blog.


Posted by
Chutsu
30 April 2013 @ 11am

What I don’t get it is why do people not use vim functions? You can compartmentalize your vim settings so nice using that method, like so:

https://github.com/chutsu/dotfiles/blob/master/vimrc


Posted by
iso 9001
6 May 2013 @ 7am

Attractive section of content. I just stumbled
upon your web site and in accession capital to assert that I acquire
in fact enjoyed account your blog posts. Anyway I’ll be subscribing to your feeds and even I achievement you access consistently quickly.


Posted by
pompy ręczne
7 May 2013 @ 11pm

This piece of writing will help the internet viewers for building up new website or even a weblog from start to end.


Posted by
timss
12 May 2013 @ 3pm

I’ve found that the key to a tidy vimrc is active use of indentation via the following and right-aligned comments:

"""" Section name {{{
    <configs>               " comment
    """ Section name {{{
        <configs>           " comment
    """ }}}
""" }}}

This is really easy to read and concise.
Take a look at my extensive configuration with super easy installation where everything is neetly organized and commented:
- https://github.com/timss/vimconf


Leave a Comment

To post code, use <code></code> tag around your code