Source

dotfiles / vim / vimrc

Full commit
" ~/.vimrc

call pathogen#infect()

"""" General settings """""""""""""""""""""""""""""""""""""""""""""""
set nocompatible
set encoding=utf-8

"filetype plugin indent on
"filetype on

set shortmess+=I                " Skip intro message
set lazyredraw

" keycode timeout is 100, mapping timeout is ∞
set notimeout ttimeout ttimeoutlen=100

set incsearch "hlsearch
set hidden                      " Abandoning a buffer makes it hidden instead of
                                " unloading it.
set showcmd
set splitright

set history=500
set cpoptions+=MJ

set tildeop                     " Makes tilde an operator instead of a command.

" Use persistent undo if available
if version >= 703
  set undodir=~/.vim/undodir
  set undofile
  set undolevels=1000
  set undoreload=10000
end

set spelllang=sv


"""" Mappings """""""""""""""""""""""""""""""""""""""""""""""""""""""
let mapleader = "-"

noremap ä :

" Bind C-h to fully dedent (clear all leading whitespace)
noremap  <C-h> :s/^\s*//<CR>
inoremap <C-h> <Esc>:s/^\s*//<CR>i

cnoremap <C-a> <Home>
nnoremap <C-e> :e 

" Various
"nnoremap <Leader>== yypVr=A==<Esc>Vk:center<CR>
nnoremap <Leader>== I <Esc>yypVr=A=<Esc>
nnoremap <Leader>. :!!<CR>
map Y y$

" open above/below, but keep column
nnoremap <Leader>o i<Esc>yypVr<Space>`^jC
nnoremap <Leader>O i<Esc>yyPVr<Space>`^kC

" Make w!! do a superuser-write of the file
cnoremap w!! w !sudo dd of=%

" Useful to quickly get rid of hlsearch
"nnoremap <Esc> :noh<CR><Esc>

" Handy shortcut for pasting -- press F8, paste stuff, move on
nmap <F8> :set paste<CR>i
imap <F8> <ESC>:set paste<CR>i<Right>
au InsertLeave * set nopaste
"set pastetoggle=<F8>

" This is a godsend when messing about with syntax rule files
map <F11> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>

" 'Dual-head mode'--split the window vertically and scrollbind the rightern
" buffer at exactly one screenful below the left one.
" TODO: Improve
map <Leader>v :set noscb<CR>:botright vsplit<CR><C-f>:set scb<CR><C-w>h:set scb<CR>


"""" Digraphs """""""""""""""""""""""""
dig HH 9552 VV 9553                  " ═ ║
dig dR 9554 Dr 9555 DR 9556          " ╒ ╓ ╔
dig dL 9557 Dl 9558 DL 9559          " ╕ ╖ ╗
dig uR 9560 Ur 9561 UR 9562          " ╘ ╙ ╚
dig uL 9563 Ul 9564 UL 9565          " ╛ ╜ ╝
dig vR 9566 Vr 9567 VR 9568          " ╞ ╟ ╠
dig vL 9569 Vl 9570 VL 9571          " ╡ ╢ ╣
dig dH 9572 Dh 9573 DH 9574          " ╤ ╥ ╦
dig uH 9575 Uh 9576 UH 9577          " ╧ ╨ ╩
dig vH 9578 Vh 9579 VH 9580          " ╪ ╫ ╬
dig (1 9581 (2 9582 (3 9583 (4 9584  " ╭ ╮ ╯ ╰  ))))
dig ll 9588 uu 9589 rr 9590 dd 9591  " ╴ ╵ ╶ ╷

"""" Text objects """""""""""""""""""""
" u/U: forward/backward 'til next uppercase character
onoremap u /\u<CR>
onoremap U ?\u<CR>


"""" Buffer management mappings """""""
" Switch to last (alternate) buffer with <Leader><Leader>, and reload current
" file with <Leader>e.
nnoremap <Leader><Leader> <C-^>
nnoremap <Leader>e :edit %<CR>
nnoremap <Leader>re :silent edit $MYVIMRC<CR>
nnoremap <Leader>rs :silent source $MYVIMRC<CR>


" Switch to buffer N with <Leader>N
nnoremap <Leader>1 :buf 1<CR>
nnoremap <Leader>2 :buf 2<CR>
nnoremap <Leader>3 :buf 3<CR>
nnoremap <Leader>4 :buf 4<CR>
nnoremap <Leader>5 :buf 5<CR>
nnoremap <Leader>6 :buf 6<CR>
nnoremap <Leader>7 :buf 7<CR>
nnoremap <Leader>8 :buf 8<CR>
nnoremap <Leader>9 :buf 9<CR>
nnoremap <Leader>0 :buf 10<CR>


"""" Indentation settings """""""""""""""""""""""""""""""""""""""""""
" Note to self: expandtab, shiftwidth, tabstop, softtabstop, autoindent,
"               smartindent, preserveindent, copyindent, shiftround, smarttab.
" ---- Use :retab for re-applying indentation rules!

set copyindent autoindent       " copy leading whitespace from previous line
set expandtab
set nosmarttab                  " lets <Tab> and <BS> perform predictably.

set breakindent

set tabstop=8 sts=0 sw=2
set preserveindent
set noshiftround

" Tab key should always enter a tab character; use <C-t> and <C-d> for
" indentation.
inoremap <Tab> <C-v><Tab>


"""" Formatting etc. """"""""""""""""""""""""""""""""""""""""""""""""
"set formatoptions+=ro           " Auto-continue comments on <CR>/o/O
set formatoptions+=n            " Indent numbered lists in comments better
set formatoptions+=l            " Don't wrap lines that were already long
if v:version >= 703 || v:version ==# 703 && has('patch541')
  set formatoptions+=j            " Remove comment leaders when joining
endif

set comments=s1:/*,mb:*,ex:*/,O://,bO:#,:%,n:>,fb:-


"""" Visuals, aesthetics """"""""""""""""""""""""""""""""""""""""""""
"set number                      " Use line numbering
set ruler                       " Show scroll percentage even if no statusline
set cursorline                  " Highlight cursor's line

set textwidth=78
set nowrap sidescroll=5         " Scroll horizontally 5 chars at a time when
                                " exceeding screen size.
set scrolloff=5                 " Keep 5 lines visible vertically

" Use pretty characters for vim's rendering of things.
set list listchars=tab:»\ ,trail:·,nbsp:␣,extends:$,precedes:^
set fillchars=vert:│,stl:─,stlnc:─

set foldmethod=marker

if version >= 703
  set colorcolumn=+2            " Highlight 'textwidth'th column
end
syntax on                       " Use syntax highlighting

" In case I end up in the GUI, make it behave more like what I'm used to.
set go= gcr+=a:blinkon0


" Add a few custom filetypes
au BufRead,BufNewFile /usr/share/X11/xkb/* setf xkb
au BufRead,BufNewFile *.md                 setf markdown

au BufRead,BufNewFile *.json               setf json
au BufRead,BufNewFile *.note,*.lecnote     setf note
au BufRead,BufNewFile *.selfml             setf selfml
au BufRead,BufNewFile *.ijs                setf j
au BufRead,BufNewFile *.om                 setf om
au BufRead,BufNewFile *.qml                setf javascript
au BufRead,BufNewFile *.glsl               setf c
au BufRead,BufNewFile *.vimp,*.penta       setf vimperator
au BufRead            */xchatlogs/*.log    setf irclog | set ro noma

" Custom filetype-dependent metadata
au FileType lua  setlocal comments=:--
au FileType j    setlocal comments=:NB.
au FileType go   setlocal nolist ts=2 noet


"""" Colour scheme """"""""""""""""""""
" pangoterm fanciness
if $REALTERM == "pangoterm"
  set t_ZH=   t_ZR=    " italics mode
  set t_SI=[5\ q t_EI=[1\ q   " insert mode bar-cursor

" let &t_ti = &t_ti . "\e[?6h\e[?69h"
" let &t_te = "\e[?69l\e[?6l" . &t_te
" let &t_CV = "\e[%i%p1%d;%p2%ds"
" let &t_CS = "y"
end

"let g:jellybeans_background_color_256 = "NONE"
"let g:jellybeans_background_color     = "02080F"
"color jellybeans
color hybrid

let _ = -1 | let NONE = 'NONE'
let format_overrides = { " ctermfg bg  cterm   guifg   guibg    gui ": [],
  \ 'CursorLine':        [    _,  232,     _ ,     _ , '#000',    _ ],
  \ 'CursorColumn':      [    _,  232,     _ ,     _ , '#000',    _ ],
  \ 'ColorColumn':       [    _,  233,     _ ,     _ , '#111',    _ ],
  \ 'VertSplit':         [  236, NONE,     _ ,     _ ,  NONE ,    _ ],
  \ 'StatusLine':        [  246, NONE,  NONE ,     _ ,  NONE , NONE ],
  \ 'StatusLineNC':      [  236, NONE,  NONE ,     _ ,  NONE , NONE ],
  \ 'LineNr':            [  238,    _,     _ , '#555',     _ ,    _ ],
  \ 'CursorLineNr':      [    3,  232,     _ , '#C93', '#000', NONE ],
  \ 'SignColumn':        [    _, NONE,     _ ,     _ ,     _ ,    _ ],
  \ 'Folded':            [    _,  233,     _ ,     _ , '#111',    _ ],
  \ 'Search':            [    _,  238,     _ ,     _ , '#111',    _ ],
  \ 'ModeMsg':           [    2,    _, 'bold', '#9C3',     _ ,    _ ],
  \ 'ErrorMsg':          [    7,    1, 'bold', '#9C3',     _ ,    _ ],
  \
  \ 'Conceal':           [   14, NONE,     _ , '#3C9',  NONE ,    _ ],
  \ 'SpecialKey':        [  236, NONE,     _ , '#333',  NONE ,    _ ],
  \
  \ 'markdownCode':      [  175,    _,     _ ,     _ ,     _ ,    _ ],
  \ 'markdownCodeBlock': [  175,    _,     _ ,     _ ,     _ ,    _ ],
  \ 'Ignore':            [    0,    _,     _ ,     _ ,     _ ,    _ ],
  \ }
" \ 'Operator':          [   73,    _,     _ ,     _ ,     _ ,    _ ],
" \ 'StatusLine':        [  237,    3,     _ , '#C93', '#222', NONE ],
" \ 'StatusLineNC':      [  234,  241,     _ , '#777', '#111', NONE ],

hi link rubyRegexp Constant

let keys = ['ctermfg', 'ctermbg', 'cterm', 'guifg', 'guibg', 'gui']
for [name, val] in items(format_overrides)
  let params = map(val, 'v:val != -1 ? keys[v:key] . "=" . v:val : ""')
  if len(params) == 0 | continue | endif
  exec 'hi ' . name . ' ' . join(params, ' ')
endfor


set conceallevel=2 concealcursor=ni
"hi Conceal ctermfg=cyan ctermbg=none


"""" Status line """"""""""""""""""""""
set laststatus=0

" default ruler (+ fancy style)
set stl=\ %-8.(%l,%c%V%)\ %P\ %#StatusLineNC#
set ruf=%#StatusLine#\ %-8.(%l,%c%V%)\ %P

" Title string
set title


""" Dump files to web server """"""""""""""""""""""""""""""""""""""""
" Uses 2html.vim to generate an HTML file and upload it to my server.
"let g:html_number_lines = 0
let g:html_line_ids      = 1
let g:html_dynamic_folds = 1
let g:html_use_encoding  = 'UTF-8'
" implementation moved to plugin/pastebox.vim
let g:pasteboxWriteCommand = 'ssh xen "cat >srv/http/up/{}"'


"""" Plug-ins """""""""""""""""""""""""""""""""""""""""""""""""""""""
" gundo
nnoremap <F9> :GundoToggle<CR>

" netrw
let g:netrw_bufsettings = 'noma nomod nu nobl nowrap ro'

" Tabularize
noremap <Leader>a=  :Tabularize /=<CR>
noremap <Leader>a:  :Tabularize /:<CR>
noremap <Leader>a\| :Tabularize /\|<CR>
noremap <Leader>as  :Tabularize /\s\+<CR>

" Signify
let g:signify_sign_add               = '+'
let g:signify_sign_change            = '~'
let g:signify_sign_delete            = '-'
let g:signify_sign_change_delete     = '±'
let g:signify_sign_delete_first_line = '‾'

let g:signify_sign_color_ctermfg_add    = 70
let g:signify_sign_color_ctermfg_delete = 160
let g:signify_sign_color_ctermfg_change = 178

" Airline
"let g:airline_left_sep               = '〉' ">▌
"let g:airline_right_sep              = '〈' "<▐
let g:airline_theme                  = 'simple'

" pandoc-syntax
let g:pandoc_syntax_user_cchars = { "atx": "#" }

hi link pandocNoFormatted markdownCodeBlock
hi link pandocCodeBlock   markdownCodeBlock
syn match pandocHeaderLine /=/ contained containedin=pandocSetexHeader conceal cchar=syn match pandocHeaderLine /-/ contained containedin=pandocSetexHeader conceal cchar=
" Notebook
let g:notebook_cmd    = 'j8'
let g:notebook_stop   = "exit ''"
let g:notebook_send0  = "''"
let g:notebook_send   = "'VIMJNOTEBOOK'"
let g:notebook_detect = '   VIMJNOTEBOOK'

func! <SID>notebookEvalRange(mode)
  '[,']NotebookEvaluate
endfunc
nnoremap <silent> <Leader>x  :set opfunc=<SID>notebookEvalRange<CR>g@
nnoremap <silent> <Leader>xx :NotebookEvaluate<CR>
vnoremap <silent> <Leader>x  :NotebookEvaluate<CR>


"""" Scratchpad area """"""""""""""""""""""""""""""""""""""""""""""""
au BufReadPost  * if &bin | %!xxd
au BufReadPost  * set ft=xxd | endif
au BufWritePre  * if &bin | %!xxd -r
au BufWritePre  * endif
au BufWritePost * if &bin | %!xxd
au BufWritePost * set nomod | endif