dotfiles/vim/vimrc.symlink

289 lines
6.5 KiB
Text

" Max's .vimrc
""""""""""""""""""""""
" Plugins
""""""""""""""""""""""
execute pathogen#infect()
""""""""""""""""""""""
" Basic editing config
""""""""""""""""""""""
set term=xterm-256color
set nocompatible
colorscheme maxbucknell
" Leader
let mapleader = "\<space>"
" Don't wrap lines
set nowrap
" Line numbering
set relativenumber
set number
" Write before commands
set autowrite
" Open splits in better places
set splitbelow
set splitright
" Quicker window movement
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-h> <C-w>h
nnoremap <C-l> <C-w>l
" Set editor shell to bash, for Syntastic compatibility
set shell=bash
" Find files
nnoremap <leader>t :call PickFile()<cr>
nnoremap <leader>b :call PickBuffer()<cr>
nnoremap <leader>n :call PickFileVerticalSplit()<cr>
" Tab config options
set expandtab
set tabstop=2
set shiftwidth=2
set softtabstop=2
set autoindent
" So done with this
set nobackup
set nowritebackup
set noswapfile
" What the hell is ex mode
nnoremap Q <nop>
" Faster highlight removal than ;noh
nnoremap <silent> <leader>/ :noh<cr>
" I am lazy and I don't like holding shift.
noremap ; :
noremap ;; ;
"Remove caps for dash
cnoremap dash Dash
" Gain root privs when writing
cnoremap w!! w !sudo tee % > /dev/null
" Paste!
noremap <leader>v "*gp
noremap <leader>V "*gP
noremap <leader>c "*y
noremap <leader>C "*Y
" Quick exit insert mode
inoremap hh <esc>
inoremap hhh h<esc>
inoremap <esc> <nop>
" Bad arrow keys
inoremap <up> <nop>
inoremap <down> <nop>
inoremap <left> <nop>
inoremap <right> <nop>
noremap <up> <nop>
noremap <down> <nop>
noremap <left> <nop>
noremap <right> <nop>
" Move lines up and down
noremap - ddp
noremap _ ddkP
" Uppercase an entire word with <c-u>
nnoremap <leader>u viwU
" Show me when my lines are too long
" I wish to limit my lines to 80 characters long. However, Vim creates
" the n+1th character when you have n characters in a line. Hence, when
" my line is 80 characters long, I see the red line. So, this is set to
" 82, meaning that I only see the line when my lines actually are too long.
call matchadd('ColorColumn', '\%82v', 100)
" Prevent K from being annoying
noremap K <nop>
" Edit and Reload .vimrc files
nmap <silent> <Leader>ev :e $MYVIMRC<CR>
nmap <silent> <Leader>es :so $MYVIMRC<CR>
" Search options
" Show partial matches while searching
set incsearch
" Highlight other matches in the file
set hlsearch
" Show the next search result.
" By Damian Conway.
"
" This rewires n and N to do the highlighing...
nnoremap <silent> n n:call HLNext(0.2)<cr>
nnoremap <silent> N N:call HLNext(0.2)<cr>
" Blink the next match
function! HLNext (blinktime)
let [bufnum, lnum, col, off] = getpos('.')
let matchlen = strlen(matchstr(strpart(getline('.'),col-1),@/))
let target_pat = '\c\%#'.@/
let ring = matchadd('MBSearchNext', target_pat, 101)
redraw
exec 'sleep ' . float2nr(a:blinktime * 1000) . 'm'
call matchdelete(ring)
redraw
endfunction
" Disable match-paren
" It has really bad colours and it displays terribly.
set noshowmatch
" Make searches case sensitive only if an upper case character has been typed
set ignorecase smartcase
" Prevent Vim from clobbering the scrollback buffer. See
" http://www.shallowsky.com/linux/noaltscreen.html
set t_ti= t_te=
" Highlight current line
set cursorline
" Ensure that the cursor never touches top or bottom of screen
set scrolloff=10
" Allow backspacing over everything in insert mode
set backspace=indent,eol,start
" display incomplete commands
set showcmd
" Allow hidden buffers
set hidden
" Enable highlighting for syntax
syntax on
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" Insert only one space when joining lines that contain sentence-terminating
" punctuation like `.`.
set nojoinspaces
" If a file is changed outside of vim, automatically reload it without asking
set autoread
" Show trailing whitespace, since it's a crime
set list
set listchars=trail:·,tab:‣\
" Turn off code folding
set foldmethod=manual
set nofoldenable
let g:vim_markdown_folding_disabled=1
" Always show status bar
set laststatus=2
" Pastetoggle to let Vim paste things without auto stuff
set pastetoggle=<F2>
"""""""""""""""""
" Custom autocmds
"""""""""""""""""
augroup vimrcEx
" Clear all autocmds in the group
autocmd!
autocmd FileType text setlocal textwidth=78
" Jump to last cursor position unless it's invalid or in an event handler
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
" Language whitespace settings
autocmd FileType json,c,xml,java,php,python setlocal shiftwidth=4 softtabstop=4
autocmd FileType ruby,haml,eruby,yaml,html,javascript,sass,cucumber setlocal ai sw=2 sts=2 et
autocmd FileType make setlocal noet sw=8 sts=8 ts=8
" Hard wrap prose
autocmd FileType markdown setlocal tw=80 fo=t1
" Create files when opened
autocmd BufNewFile * write
augroup END
"""""""""""""
" STATUS LINE
"""""""""""""
" set statusline=%<[%n]:\ %f\ %5l,%3c\ (%{&ft})
set statusline=[%f] " filename
set statusline+=\ [%l,\ %c] "line and column number
set statusline+=\ %y " filetype
set statusline+=\ %{SyntasticStatuslineFlag()} " syntastic errors
"""""""""""""""""""""
" Configure Syntastic
"""""""""""""""""""""
let g:syntastic_enable_signs = 0
let g:syntastic_javascript_checkers = ['eslint']
let g:syntastic_stl_format='[%t errors, first: %F]'
"""""""""""""""
" MISC KEY MAPS
"""""""""""""""
noremap <leader>y "*y
nnoremap <leader><leader> <c-^>
" Move around splits with <c-hjkl>
nnoremap <c-j> <c-w>j
nnoremap <c-k> <c-w>k
nnoremap <c-h> <c-w>h
nnoremap <c-l> <c-w>l
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" MULTIPURPOSE TAB KEY
" Indent if we're at the beginning of a line. Else, do completion.
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
" inoremap <tab> <c-r>=InsertTabWrapper()<cr>
" inoremap <s-tab> <c-n>
" I don't like the quote concealing
let g:vim_json_syntax_conceal = 0
" Show syntax highlighting groups for word under cursor
nmap <leader>\ :call <SID>SynStack()<CR>
function! <SID>SynStack()
if !exists("*synstack")
return
endif
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val,"name")')
endfunc