view vim/vimrc @ 108:14307ff18bc1

Using piecrustmarkdown syntax.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 15 May 2012 17:08:56 -0700
parents a755319f124e
children 539d84664c27
line wrap: on
line source

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" Ludovic Chabant's ~/.vimrc
"
" http://ludovic.chabant.com
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Global Setup {{{

" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible

" Set a variable that says we already sourced this file, for those few
" settings we don't want to re-apply.
if exists('g:sourced_vimrc')
    let g:resourcing_vimrc = 1
endif
let g:sourced_vimrc = 1

" Get the platform we're running on.
if has("win32") || has("win64") || has("dos32")
    let s:vim_platform = "windows"
else
    let s:vim_platform = "unix"
endif

" Get our vim directory. 
let s:vim_home = expand("<sfile>:h")

" Disable some plugins.
let g:pathogen_disabled = []
call add(g:pathogen_disabled, 'vimroom')
call add(g:pathogen_disabled, 'minibufexpl')

" Load pathogen.
call pathogen#infect()

" Hide the toolbar in MacVim/gVIM, and set a nice window size.
if has("gui_running") && !exists('g:resourcing_vimrc')
    set guioptions=-t
    set lines=50
    set columns=135
endif

" }}}

" General Settings {{{

" Disable modelines.
set modelines=0

" Don't unload abandoned buffers.
set hidden

" Show line numbers.
set number

" Show what mode we're in, and what command we're typing.
set showmode
set showcmd

" Keep the cursor off the top/bottom edges.
set scrolloff=3

" Smart auto-indenting.
set autoindent
set smartindent

" Use confirmation dialog.
set confirm

" Don't use annoying sounds.
set visualbell

" Remember lots of commands.
set history=1000

" Try to reduce flickering.
set lazyredraw

" Show matching braces but not for too long.
set showmatch
set matchtime=2

" Show soft-broken/wrapped lines with a prefix.
set showbreak=→

" Use incremental search, with highlighting,
" case-insensitive unless we actually type some
" mixed-case stuff.
set incsearch
set hlsearch
set ignorecase
set smartcase

" Always show window status lines.
set laststatus=2

" Enable using the mouse like some everyday guy.
set mouse=a

" Show interesting stuff at the bottom of the window.
set showcmd
set ruler

" Make sure splitting windows is done in a way that makes sense.
set splitbelow
set splitright

" Don't pollute the hard-drive with *~ files. Only
" create them in hidden backup/temp directories while
" we edit the file, and then get rid of it.
set nobackup
set writebackup
execute('set backupdir='.s:vim_home.'/backup')
execute('set directory='.s:vim_home.'/temp')

" Better command-line completion, but don't show some
" stuff we don't care about.
set wildmenu
set wildignore+=.DS_Store,Thumbs.db,*.so,*.dll,*.exe

" Always display the tab-page line.
set showtabline=2

" Set the file-formats.
set ffs=unix,mac,dos

" Tabs and indenting are 4 characters, and tabs behave like
" spaces during editing. They're smart, too, and when you
" press <TAB> it actually inserts a soft-tab so everything's
" indented the same.
set tabstop=4
set shiftwidth=4
set softtabstop=4
set smarttab
set expandtab

" Default encoding
set encoding=utf-8

" Clipboard buffer.
set clipboard=unnamed

" Smoot terminal experience.
set ttyfast

" Allow backspacing over anything.
set backspace=indent,eol,start

" Going left and right let you go to other lines.
set whichwrap+=<,>,h,l

" How to show invisible characters
set listchars=eol:$,tab:>-,trail:-,extends:>,precedes:<,nbsp:%,conceal:.

" Folds are defined by markers in the text.
set foldmethod=marker

" Nice auto-complete menu.
set completeopt=longest,menuone,preview

" And now, for some system-dependent settings:
" - font to use
if s:vim_platform == "windows"
    set guifont=Consolas:h12
else
    set guifont=Monaco:h12
endif

" Syntax highlighting.
syntax on

" Change the current directory to the home directory.
if !exists('g:resourcing_vimrc')
    cd ~/
endif

" Default color scheme.
if has('gui_running')
    set background=light
else
    set background=dark
endif
colorscheme badwolf

" Enable file type detection.
filetype indent plugin on

" }}}

" Auto-Commands {{{

" Only show the highlighted cursor line in the current window.
augroup CursorLine
    au!
    au WinLeave * set nocursorline
    au WinEnter * set cursorline
augroup END

" }}}

" Plugin Settings {{{

" We'll set our own mappings.
let g:ctrlp_map = ''

" Ctrl-P should manage the working directory.
let g:ctrlp_working_path_mode = 2

" Ctrl-P should however ignore some stuff.
let g:ctrlp_custom_ignore = {
  \ 'dir':  '\.git$\|\.hg$\|\.svn$',
  \ 'file': '\.exe$\|\.so$\|\.dll$'
  \ }

" Make Ctrl-P cache stuff in our temp directory.
let g:ctrlp_cache_dir = s:vim_home.'/cache'

" }}}

" File-Specific Settings {{{

if has("autocmd")

    augroup VimRCFileTypeSettings
        au!
    
        " Nice text width for text files.
        autocmd FileType text,markdown setlocal textwidth=80

        " Who the hell changes my matchpairs?
        autocmd FileType php setlocal matchpairs-=<:>

        " File I know are markdown: personal notes & PieCrust pages.
        autocmd BufRead,BufNewfile */Dropbox/Personal/SimpleNote/* set ft=markdown
        autocmd BufRead,BufNewFile */_content/**/*.html set ft=piecrustmarkdown

    augroup END

endif

" }}}

" Mappings {{{

let mapleader=","

" Visual line navigation
noremap <up> g<up>
noremap <down> g<down>
noremap <home> g<home>
noremap <end> g<end>

" Buffer navigation
noremap <C-Tab>   :bnext<cr>
noremap <C-S-Tab> :bprevious<cr>

" Window navigation
nnoremap <C-up> :wincmd k<cr>
nnoremap <C-down> :wincmd j<cr>
nnoremap <C-left> :wincmd h<cr>
nnoremap <C-right> :wincmd l<cr>

" Open NERDtree.
nnoremap <F2> :NERDTreeToggle %:p:h<cr>

" Switch buffers.
nnoremap <F3> :execute ("buffer " . bufname("#"))<cr>

" Common typos.
nnoremap ; :

" Split windows
nnoremap <leader>s :split<cr>
nnoremap <leader>v :vsplit<cr>

" Edit & source the VIMRC.
nnoremap <leader>ev :vsplit $MYVIMRC<cr>
nnoremap <leader>sv :source $MYVIMRC<cr>

" Easier things to type
nnoremap <leader>w :w<cr>
nnoremap <leader>q :q<cr>

" Toggle invisible characters
nnoremap <leader>i :set list!<cr>

" Clear search matches
nnoremap <leader><space> :noh<cr>:call clearmatches()<cr>

" Ctrl-P mappings.
nnoremap <silent> <C-p> :CtrlP<cr>
nnoremap <silent> <C-o> :CtrlPBuffer<cr>
nnoremap <silent> <C-i> :CtrlPMRU<cr>

" Switch between FR and US keyboard layouts.
nnoremap <leader>fr :setlocal keymap=french<cr>
nnoremap <leader>us :setlocal keymap=<cr>

" Toggle spell check according to current keyboard layout.
nnoremap <leader>sp :call <SID>ToggleSpellCheck()<cr>

" Simple way to close a buffer without closing the window.
nnoremap <leader>bd :bprevious<cr>:bdelete #<cr>

" Toggle folds with <space>.
nnoremap <space> za

" Create folds with <space> (in visual mode).
vnoremap <space> zf

" File-type switching.
nnoremap <leader>ftmd :set ft=markdown<cr>

" Quick search and replace.
nnoremap <leader>s :%s/\<<C-r><C-w>\>//g<left><left>
vnoremap <leader>s :s/<C-r>///g<left><left>

" }}}

" Abbreviations {{{

iabbrev @@      ludovic@chabant.com
iabbrev ccopy   Copyright &copy;2011 Ludovic Chabant, all rights reserved.
iabbrev ssig    --<cr>l u d o .<cr>. 8 0 17 80

" }}}

" Status Line {{{

set statusline=%f    " Path.
set statusline+=%m   " Modified flag.
set statusline+=%r   " Readonly flag.
set statusline+=%w   " Preview window flag.

set statusline+=\    " Space.

set statusline+=%#redbar#                       " Highlight the following as a warning.
set statusline+=%{SyntasticStatuslineFlag()}    " Syntastic errors.
set statusline+=%*                              " Reset highlighting.

set statusline+=%=   " Right align.

" Mercurial information.
set statusline+=%{lawrencium#statusline('[',']')}
set statusline+=\    " Space.

" File format, encoding and type.  Ex: "(unix/utf-8/python)"
set statusline+=(
set statusline+=%{&ff}                        " Format (unix/DOS).
set statusline+=/
set statusline+=%{strlen(&fenc)?&fenc:&enc}   " Encoding (utf-8).
set statusline+=/
set statusline+=%{&ft}                        " Type (python).
set statusline+=)

" Line and column position and counts.
set statusline+=\ (line\ %l\/%L,\ col\ %03c)

" }}}

" Functions {{{

function! s:ToggleSpellCheck() abort
    if &spell ==? 'nospell'
        if &keymap ==? 'french'
            setlocal spell spelllang=fr_fr
        else
            setlocal spell spelllang=en_us,en_ca
        endif
    else
        setlocal spell nospell
    endif
endfunction

" }}}

" Temporary stuff {{{

" Enable debugging Lawrencium
let g:lawrencium_debug = 1
let g:lawrencium_trace = 0

" Enable debugging PieCrust
let g:piecrust_debug = 1
let g:piecrust_trace = 0

" }}}