Steve Losh's .vimrc
bitbucket.org
bitbucket.org
" 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>AOr just not worry about it at all -- each person has their own way of working with Vim.
inoremap <C-e> <End>
Technical note: I's behavior changes depending on 'cpo' so you can't just map it to <C-o>^.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)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."
But serious talk:
Unless someone has loaded Emacs keybindings, shouldn't <C-a> be used to increment a number (even a hexadecimal one)? How is that heresy? Not having <C-a> makes several macros difficult.
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.
function! NyanMe() " {{{ ...
I very much hope that's just there as an easter egg for those of us who read to the bottom.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.
Go figure.
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).
"...become attached to nothing in life that you can't walk away from in 30 seconds if you spot the "Heat" around the corner."
Except I apply this to customised/complicated software rather than "things" in my life.
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.
wget -qO - bit.ly/newbox | sh
or curl -Ls bit.ly/newbox | sh
and am up and running. No sweat. I keep this stuff in Dropbox too, just in case.Also, why do you symlink your dotfiles into your cloned git repo, rather than just checking out the git repo as ~? Personally, I just move the .git directory from the clone to ~, and then "git checkout -f".
Also due to laziness I don't want to add a bunch of stuff to .gitignore, or add * and then add exceptions. I like having the symlinks.
The power of VIM as an effective and consistent text editor is far more important to me than the power of VIM as a highly configurable editor.
dropbox-update-dotfiles () {
src="$HOME/Dropbox/dotfiles"
dst="$HOME"
if [[ ! -d "$src" ]]; then
print "Directory $src not found."
fi
for f in "$src"/*~*(.swp|~|.pyc)(D); do
if [[ -h "$dst/${f:t}" ]]; then
# exists as symlink
elif [[ -e "$dst/${f:t}" ]]; then
print "WARNING: ${f:t} exists, but is not a symlink."
else
ln -sv "$f" "$dst"
fi
done
}I link my dot files as well as Documents, Pictures, Music, and Desktop directories that are also normally controlled by OSX. Having those shared across multiple computers is awesome. Sit down at a computer, and it's there.
I also have my zsh files checked in to bitbucket (https://bitbucket.org/tednaleid/shared-zshrc/) so even if the computer doesn't have dropbox (like many of the linux servers I have access to), as long as it has mercurial, I can clone the repo and be ready to go.
I try and keep my .vimrc limited to configuration and enhancement and not change how the core works. Things like rebinding builtin actions will never be seen in my .vimrc.
Everything else is gravy for me. While an extended rc is handy and I often store one where I can get to it, if I'm just editing a couple of files, vanilla + the tab size I want and a shortcut to highlighting search terms gets me going. YMMV
I tried to get into emacs, but I kept coming back to vim. Probably because the first editor I really used was a version of 'ed' back when I played MUDs.
" turn off highlighted results (set nohlsearch) when pressing enter.
" just pressing n or N will turn the highlight back again
nnoremap <cr> :noh <cr>
https://github.com/sce/dotfiles set nocp
set hidden
set ts=2
set sw=2
set autoindent
set incsearch
filetype on
filetype plugin on
map <C-J> <C-W>j
map <C-K> <C-W>k
map <C-l> <C-W>l
map <C-h> <C-W>h
For buffer management, combination of :ls, :b and :b# does the job well enough, compiling command-t plugin isn't necessary :). For listing of files there is :sexplore . For code browsing there is plain old ctags. There you go, almost 90% of environment created. Other things like surround or snipets support would be better. But I don't use them most of the time :).Then I have to ask: what exactly are you doing in that other computer?
If it's just some temporary sysadmin stuff and the like, then you surely can get by with the basic vim functionality.
Now, If you're gonna be using that other computer for a longer period, then why not just add your .vimrc there? With github, bitbucket, dropbox et al you can have your configuration pushed to the other computer in seconds.
I also find that with everybody having laptops these days, the need to use some "other computer" is much less frequent.
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.
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.
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.
But, a bit of Googling will find it (works pretty well, too): http://writequit.org/blog/?p=413
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
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. set foldmethod=marker
Or put this modeline at the top of your .vimrc: " vim: foldmethod=marker foldlevel=0There 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 }.This has been annoying me forever, but I never got around to fixing it. Not sure how the solution works, but it does!
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.
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.
" Don't move on *
nnoremap * *<c-o>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.
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
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.
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.
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.
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 ;)
When I switched to nvi I realized how wrong I was. My .nexrc contains less than ten lines. There is no syntax highlighting. I was also forced to learn real vi properly. When you do such things amazing things happen.
Sure, you know a lot more than me what makes me productive in my text editor use.
And that is traditional vi. Sure no need to go beyond that. Oh, and 640K should be enough for everybody.
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?
" ta gueule !
set noerrorbells
if has('autocmd')
autocmd GUIEnter * set vb t_vb=
endif
set noerrorbells
set visualbell
set t_vb=