Jack Baty - the archives

Years of jackbaty.com - archived

Vim Again

A few of you started talking about Vim again recently and it made me want to clean up my own neglected configuration. There went my Saturday, but it was worth it. I’m still in love with Vim, and I thought I’d share some of the highlights from this latest round.

Recommended Plugins

After much mucking about with my .vimrc file, I’ve gotten it to a state I’m fairly happy with. I deleted years of cruft and only left in the things I really use, plus a few nice additions discovered while Googling about.

" My current .vimrc file
" Jack Baty
" jack@jackbaty.com
" Twitter: @jackbaty



" Environment {
    set nocompatible    " We don't want vi compatibility.
    filetype off        " off until after pathogen runs
    call pathogen#runtime_append_all_bundles()  " easy plugin bundling
" }

" General and UI {
    filetype plugin indent on
    syntax on
    set modelines=0             " I don't use modelines
    set encoding=utf-8
    colorscheme solarized       " http://ethanschoonover.com/solarized
    set background=dark
    set scrolloff=3             " keep at least 3 lines visible around cursor
    set nu                      " Line numbers on
    set autoindent              " indent stays same as last line
    set showmode                " so we know which mode we're in
    set showcmd                 " so we can see what we're doing
    set hidden                  " don't ask me to save all the time
    set wildmenu                " much better filename completion
    set wildmode=list:longest
    set visualbell              " don't beep
    set novisualbell            " don't blink 
    set noerrorbells            " no noise please
    set cursorline              " highlight current line
    set ttyfast                 " better scrolling
    set ruler                   " handy information about line, etc at bottom
    set backspace=indent,eol,start
    set laststatus=2            " always show status line.
    set ignorecase              " case-insensitive search...
    set smartcase               " ...unless there's some uppercase present
    set gdefault                " default to /g flag during substitutions
    set incsearch               " incremental search as you type 
    set showmatch               " indicate matching brackets and parens
    set hlsearch                " highlight search hits
    set textwidth=79            " wrap width
    set colorcolumn=85          " indicate where I should stop typing
    set timeoutlen=250  " Time to wait after ESC (default causes an annoying delay)
" }




" Formatting and behavior {
    set ts=4                    " Tabs are 4 spaces
    set bs=4                    " Backspace over everything in insert mode
    set shiftwidth=4            " Tabs under smart indent
    set expandtab
    set formatoptions=tcqr
    set cindent
    set smarttab                " better tab behavior
    set confirm                 " easier confirmation
    set lines=50 columns=100
    set grepprg=grep\ -nH\ $*
    set backupdir=~/.bak,.,~    " Keep all backups in ~/.bak
    set directory=~/.bak,.,~
" }


" Mappings and Shortcuts {
    let mapleader=","           " no one uses / do they?
    nnoremap ; :  
    " new split (vertical)
    nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<cr> 
    " hard wrap
    nnoremap Q gqip 
    nnoremap <leader>md  :set filetype=markdown<cr>
    inoremap jj <esc> " instead of escape
    "nice split window stuff
    nnoremap <leader>w <c-w>v<c-w>l
    nnoremap <c-h> <c-w>h 
    nnoremap <c-j> <c-w>j 
    nnoremap <c-k> <c-w>k 
    nnoremap <c-l> <c-w>l
    nmap <silent> ,/ :nohlsearch<cr>
    :nmap <leader>Pm :PreviewMarkdown<cr>
    map <f2> :NERDTreeToggle<cr>
    " Quickly edit/reload the vimrc file
    nmap <silent> <leader>ev :e $MYVIMRC<cr>
    nmap <silent> <leader>sv :so $MYVIMRC<cr>
    nnoremap <leader><space> :noh<cr> 
    " change to current directory
    cmap cd. lcd %:p:h    
" }


au! BufNewFile,BufRead *.txt set filetype=markdown  " text files are markdown

" Plugins {

    " NERDTree {
        let NERDTreeKeepTreeInNewTab=1
    }

" } 

The combination of installing new plugins, tweaking .vimrc, and using latest MacVim has reminded me how great text editing can be. I’ve retained the muscle memory from using Vim for years, which really helps. I enjoy using BBEdit, but some power editing in Vim makes me feel extra nerdy - in a good way.

Update: I just discovered that QuickCursor works with MacVim as well, which is totally handy.