8 ms·
Steve Losh's .vimrc
- xutopia 15y agoFor 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/ http://stevelosh.com/projects/
- zmanji 15y agoI 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 15y agoSome 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.
- xerxes2001 15y agoCan we now have a long discussion about profanity in dotfiles?
- skimbrel 15y agoThere should be more of it.
- johncoltrane 15y ago" ta gueule ! set noerrorbells if has('autocmd') autocmd GUIEnter * set vb t_vb= endif set noerrorbells set visualbell set t_vb=
- LeafStorm 15y agoThat'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.
- oops 15y agoWhat editor do you use now?
- ldh 15y agoDoes that computer have a network connection? Just store your plugins and settings in a git repo (a good idea anyway) and pull them down on whatever machine you're using.
- agscala 15y agoThis is what I do. I can clone a git repo, run an install script, and have my typical vim setup running in a trivial amount of time.
- stevelosh 15y agoSame here. cd hg clone http://bitbucket.org/sjl/dotfiles .dotfiles ln -s `pwd`/.dotfiles/vim/.vimrc ~/.vimrc cd - My full Vim config is now installed, plugins included thanks to Mercurial's subrepos. But really, I don't find myself editing files directly on servers all that often. And when I do I usually prefer bcvi anyway, because I can use MacVim instead of Vim through a terminal (which I hate because of all the shadowed keys).
- ansible 15y agoRather than type in the symbolic link commands, I just have a config script that I run (also checked into version control) that will move the old .vim directory, .bashrc, and other files out of the way, and install links to the version controlled file instead. Easy.
- mmavnn 15y agofunction! NyanMe() " {{{ ... I very much hope that's just there as an easter egg for those of us who read to the bottom.
- stevelosh 15y agoActually 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.
- tuxcanfly 15y agoThis plugin[0] apparently plays an ascii version 'bad apple' music video. Inside vim. Go figure. [0] http://www.vim.org/scripts/script.php?script_id=3477 http://www.vim.org/scripts/script.php?script_id=3477
- michaelty 15y ago1.9 MB compressed...
- gerggerg 15y agohow bout 2 lines? http://jsfiddle.net/MHj9N/ http://jsfiddle.net/MHj9N/
- xer0x 15y agoAscii Nyan cat!! Thank-you! My mind just melted.
- TeMPOraL 15y agoSeems like vim is finally getting its own Nyan Mode? (http://nyan-mode.buildsomethingamazing.com http://nyan-mode.buildsomethingamazing.com).
- michaelty 15y agoI love reading these files and finding something new to use. gdefault is definite going in.
- gaving 15y agoUgh. 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 15y agoI'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.
- rplnt 15y agoDoes this affect performance in any way? 1k+ lines is quite a lot.
- stevelosh 15y agoIn 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.
- sashahart 15y agovimrc affects startup time, but like any program it isn't the lines but the work done which will make it slow or fast. How slowly does your computer read a 1000-line text file? vim is fast, setting some parameters in vimrc doesn't change that. Avoiding configuration that will make your life easier out of fears about performance is premature optimization. If you have a ton of autocmds for frequent events, things can slow down. I also find that things can get slow when LOTS of calls are made to a language other than Vimscript. But fundamentally, run Eclipse and Netbeans and gedit and emacs - vim should compare favorably even with a ton of config. If you want to actually profile your startup time, try this on a recent version of vim: vim --startuptime=vim.log
- aidenn0 15y agoIn my experience a huge .vimrc loading tons of plugins is not much. It's completely dwarfed by the overhead of starting X11 gvim, for example.
- bobbyi 15y agoI find semicolon and comma to be very useful so I am surprised when I see people remap them or use them as leader.
- marshray 15y agoI'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 15y agoI think you want :set showcmd—"Show partial command in the last line of the screen".
- marshray 15y agoTHAT'S IT! My long lost friend is back! Thank you!
- deleted 15y ago[deleted]
- kgroll 15y agoHere'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 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 15y agoHere is the code in a more readable gist without fixed width: https://gist.github.com/1377245 https://gist.github.com/1377245
- shortlived 15y agoWhat do the triple open and close curly braces represent?
- stevelosh 15y agoThey're fold markers. When I open my vimrc in Vim it looks like this: http://d.pr/YKCM http://d.pr/YKCM
- shortlived 15y agoWhy doesn't my Vim fold things automatically? What options am I missing?
- nickknw 15y agoEither set foldmethod=marker Or put this modeline at the top of your .vimrc: " vim: foldmethod=marker foldlevel=0
- stevelosh 15y ago`foldmethod` and friends. There are a bunch of different methods for folding (indentation, manual markers, custom syntax-based folding, etc), and which one you want usually depends on the file type. I have a bunch of autocommands for different files that set the foldmethod appropriately. For example: augroup ft_vim au! au FileType vim setlocal foldmethod=marker foldmarker={{{,}}} augroup END augroup ft_js au! au FileType javascript setlocal foldmethod=marker foldmarker={,} augroup END This makes Vim fold using markers for Vim and Javascript files. The Vim markers are the usual {{{ and }}}, but Javascript has it's own "built-in" markers we can take advantage of, so it uses { and }.
- moonboots 15y agoVim folds http://vimdoc.sourceforge.net/htmldoc/fold.html http://vimdoc.sourceforge.net/htmldoc/fold.html
- nickknw 15y agoI 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
- JoshTriplett 15y ago"C-w =" equalizes the size of splits. That works fine if you already had them near-equal, but I frequently shrink or maximize split windows, and I don't want them equalizing every time the window resizes.
- stevelosh 15y agoYou could bind a key to :setlocal winfixwidth, and press that when you want a certain window to not be resized. Or just not worry about it at all -- each person has their own way of working with Vim.
- graywh 15y agoThe comment is cute, but doesn't it make more sense to just map to End itself since A is essentially a shortcut for <End>a inoremap <C-e> <End> Technical note: I's behavior changes depending on 'cpo' so you can't just map it to <C-o>^.
- swah 15y ago(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)
- deleted 15y ago[deleted]
- riffraff 15y agoI like PulseCursorLine, but I wonder why only on N and n? (e.g. not on *)
- stevelosh 15y agoBecause 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>
- dbbo 15y agoAnyone 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 15y agoWhich doesn't make it less useful. And for those of use who don't know sjl, this was useful.
- dbbo 15y agoDid 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?
- factorizer 15y agovimscript 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 15y agoI 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 15y agoUsing 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 15y agoThe 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.
- spatten 15y agoIf you want to learn how to do this yourself, let Steve know here: http://leanpub.com/learnvimscriptthehardway http://leanpub.com/learnvimscriptthehardway
- sashahart 15y agoI also have a huge vim configuration: https://github.com/sashahart/.vim 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 15y agoI'm stealing "nnoremap <CR> o<ESC>" immediately. Thanks!
- RusAlexander 15y agoBefore this link, my .vimrc was 184 lines. After reading this config it's 250 lines. Thanks Steve for 66 lines of new awesome solutions.
- robbles 15y agoinoremap # 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 15y agoThis 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".
- stevelosh 15y agoIt's (sort of) explained in :help smartindent.
- JoshTriplett 15y agonnoremap <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.
- klauern 15y agoIf 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/.vimrc#cl-357 https://bitbucket.org/sjl/dotfiles/src/27ec8da23760/vim/.vim... But, a bit of Googling will find it (works pretty well, too): http://writequit.org/blog/?p=413 http://writequit.org/blog/?p=413
- sramov 15y agoGod 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 15y agoI 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 15y agoMy 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 15y agoI 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 ;)