8000 dotvim/vimrc at master · somini/dotvim · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
1775 lines (1731 loc) · 55.8 KB

vimrc

File metadata and controls

1775 lines (1731 loc) · 55.8 KB
" somini.vimrc
" Legacy Stuff {{{
set nocompatible "Vim, not vi
" Force UTF-8 for insane systems
set encoding=utf-8
scriptencoding utf-8
set fileencodings=ucs-bom,utf-8,default,latin1
set backspace=indent,eol,start "Backspace works as intended
set showcmd "Show the command line as you type
set noshowmode " Redundant with Airline
set modeline "Enable modeline
if has('autocmd')
filetype plugin indent on "Enable filetype detection
endif
set updatetime=500 "ms
" Timeouts and stuff, Esc is instantaneous but can also be used in mappings
set notimeout
set ttimeout
set ttimeoutlen=100 "ms
if v:version > 703 || v:version == 703 && has("patch541")
set formatoptions+=j " Delete comment character when joining commented lines
endif
" i_C-u shouldn't delete so much
inoremap <C-u> <C-g>u<C-u>
" Baffling default
nnoremap Y y$
" GUI Options {{{
" Needs to be set here, to influence GUI loading
" set guioptions-=M "Don't load $VIMRUNTIME/menu.vim
" set guioptions-=f "Don't fork from the shell
" }}}
autocmd VimEnter * call s:SetupLegacy()
function! s:SetupLegacy()
" Matchit
sunmap a%
endfunction
set tagcase=match " https://github.com/vim/vim/issues/712
" }}}
" Pathogen {{{
runtime 3rd_party/vim-pathogen/autoload/pathogen.vim
if !exists('*pathogen#infect')
let s:error_marker = expand('<sfile>:p:h').'/.novimrc'
if !filereadable(s:error_marker) " Warn only the first time
echohl WarningMsg
echo "Can't load pathogen, won't change any options!"
echo "Try running `git submodule update` or clone the repo recursively"
echohl None
" Create the marker file
silent execute 'tabnew '.s:error_marker
silent write!
silent tabclose
endif
augroup vimrc_pathogen | autocmd!
autocmd VimEnter * echohl ErrorMsg | exec 'echo "'.'Fix the vim folder and `rm '.s:error_marker.'`"' | echohl None
augroup END
colorscheme blue "Ugly-ass colors to hammer the point home
finish
endif
" Plugin Blacklist {{{
" The big one, commited into git and the host-specific one
let s:plugin_blacklist = expand(expand('<sfile>:p:h').'/plugin_blacklist')
" The host-specific one is defined as a function of the big one
let s:plugin_blacklist_host = s:plugin_blacklist . '_host'
let s:blacklist = []
for f in [s:plugin_blacklist, s:plugin_blacklist_host]
if filereadable(f)
let s:blacklist += readfile(f)
endif
endfor
unlet f
if !empty(s:blacklist)
let g:pathogen_blacklist = s:blacklist
endif
"}}}
execute pathogen#infect('1st_party/{}','3rd_party/{}')
"}}}
" Utilities {{{
let g:user_dir=expand("<sfile>:p:h")
"SetToggle: Toggle complex options {{{
function! SetToggle(option, value)
" Check if the option contains value
if stridx(getwinvar(winnr(), '&'.a:option), a:value) == -1
let l:operator='+='
else "Exists, remove it
let l:operator='-='
endif
execute 'set '.a:option.l:operator.a:value
endfunction
" }}}
"IsEmptyBuffer: Check if the current buffer is empty {{{
function! IsEmptyBuffer()
if line('$') == 1 && getline(1) ==# '' && !&modified
return 1
else
return 0
endif
endfunction
"}}}
" Command line configuration
" Complete the longest common prefix, then use <Tab> to cycle
" through the various matches.
set wildmenu
set wildmode=longest:full,list:full
set wildignorecase "Ignore case
" Insert completion configuration
" Keep the same-ish configuration from the command line
" The SuperTab plugin helps with the rest
set complete=.,w,b,u,U,t,i
set completeopt=menu,preview,longest
set isfname-== " Remove = from filenames. Breaks files with = on the name
set lazyredraw "Don't update the screen in the middle of macros, etc
set autoread "Re-read files if they haven't been changed in vim
" More information with less clicks
nnoremap <C-g> 2<C-g>
" Keep the cursor still when joining lines
nnoremap J m`J``
" Edit a register on the command line
function! s:ChangeRegister()
let l:reg_regex = '[a-z]'
echohl Question
echo 'Choose register('.l:reg_regex.'): '
echohl None
let l:c = nr2char(getchar())
if l:c =~? l:reg_regex
let l:reg = tolower(l:c)
return ":let @".l:reg." = \<C-r>=string(getreg(".string(l:reg)."))\<CR>\<Left>"
else
echohl WarningMsg
echo 'Register invalid: "'.strtrans(l:c).'"'
echohl None
endif
endfunction
nnoremap <expr> <Leader>r <SID>ChangeRegister()
" Setup the leader keys
let g:mapleader = '\'
let g:maplocalleader = ','
" Nice unicode modified character
let s:modified_glyph = '☢'
" Move lines {{{
nnoremap <silent> + :move +1<CR>
nnoremap <silent> - :move -2<CR>
vnoremap <silent> + :call <SID>MoveCurrentBlock(1)<CR>gv
vnoremap <silent> - :call <SID>MoveCurrentBlock(-1)<CR>gv
function! s:MoveCurrentBlock(offset) range
" Only on V-Line visual mode
if !a:offset || a:offset == 0 || visualmode() !=# 'V'
return
endif
let l:range = a:lastline - a:firstline + 1
if a:offset > 0
let l:move = a:lastline + a:offset
else
let l:move = a:firstline + a:offset - 1
endif
if l:move > line('$')
return
endif
execute a:firstline.','.a:lastline.'move '.l:move
endfunction
"}}}
" Keep buffer locations {{{
if v:version >= 700
" Save current view settings on a per-window, per-buffer basis. {{{
function! s:AutoSaveWinView()
if !exists("w:vimrc_bufview")
let w:vimrc_bufview = {}
endif
let w:vimrc_bufview[bufnr("%")] = winsaveview()
endfunction
"}}}
" Restore current view settings. {{{
function! s:AutoRestoreWinView()
let l:buf = bufnr("%")
if exists("w:vimrc_bufview") && has_key(w:vimrc_bufview, l:buf)
let l:v = winsaveview()
let atStartOfFile = l:v.lnum == 1 && l:v.col == 0
if atStartOfFile && !&diff
call winrestview(w:vimrc_bufview[l:buf])
endif
unlet w:vimrc_bufview[l:buf]
endif
endfunction
"}}}
augroup vimrc_winview | autocmd!
" When switching buffers, preserve window view.
autocmd BufLeave * call <SID>AutoSaveWinView()
autocmd BufEnter * call <SID>AutoRestoreWinView()
augroup END
endif
"}}}
" Non-file Buffer {{{
let g:nonfile_filetypes_standalone = [
\ 'help',
\ 'man',
\ ]
let g:nonfile_filetypes_standalone_regex = '\V'.join(g:nonfile_filetypes_standalone,'\|')
let g:nonfile_filetypes_modal = [
\ 'nerdtree',
\ 'startify',
\ ]
let g:nonfile_filetypes_modal_regex = '\V'.join(g:nonfile_filetypes_modal,'\|')
let g:nonfile_filetypes = g:nonfile_filetypes_standalone + g:nonfile_filetypes_modal
let g:nonfile_filetypes_regex = '\V'.join(g:nonfile_filetypes,'\|')
"}}}
" Root Markers {{{
" Account for git submodules
let g:root_markers_vcs = [
\ '.git',
\ '.git/',
\ '.hg/',
\ '.svn/',
\ '.bzr/',
\ '_darcs/',
\]
let g:root_markers_other = [
\ '.RootMarker',
\ 'Makefile',
\ 'Rakefile',
\ 'setup.py', 'requirements.txt',
\]
let g:root_markers = g:root_markers_vcs + g:root_markers_other
"}}}
" Change Indentation {{{
nnoremap <silent> <Leader>ci :call <SID>stab()<CR>
function! s:stab()
let l:in = input('Indentation Value: ')
if !empty(l:in) && l:in =~# '\v[\+\-]?\d*'
" Do it!
call s:stab_change(l:in, 0)
else
echohl WarningMsg
echo 'Pattern not a match'
call s:stab_check()
echohl None
endif
endfunction
function! s:stab_change(val, check)
let l:tabs = a:val =~# '^-' "NoExpandTab, unless you say so
let l:value = abs(a:val)
let &l:expandtab = l:tabs
let &l:tabstop = l:value
let &l:shiftwidth = l:value
" Refresh the indent guides
IndentGuidesToggle
IndentGuidesToggle
if a:check
call s:stab_check()
endif
endfunction
function! s:stab_check()
setlocal expandtab? tabstop? shiftwidth?
endfunction
function! s:stab_command(...)
if a:0 == 1
call s:stab_change(a:000[0], 1)
else
call s:stab_check()
endif
endfunction
command! -nargs=? Stab call s:stab_command(<args>)
"}}}
" }}}
" Clipboard {{{
set clipboard=unnamedplus " Sync the unnamed register with the system clipboard
augroup vimrc_clipboard | autocmd!
autocmd VimEnter * call s:SetupClipboard()
augroup END
" Setup the clipboard using EasyClip helpers {{{
function! s:SetupClipboard()
" Insert mode {{{
" C-q does what C-v did, insert raw characters
inoremap <C-q> <C-v>
" C-v pastes
if exists('g:loaded_EasyClip') && g:loaded_EasyClip == 1
" Make sure EasyClip is loaded, otherwise use a fallback
imap <C-v> <Plug>EasyClipInsertModePaste
else
execute 'imap <script> <C-v> <C-g>u' . paste#paste_cmd['i']
endif
"}}}
" Command mode {{{
" C-y pastes
if exists('g:loaded_EasyClip') && g:loaded_EasyClip
" Make sure EasyClip is loaded, otherwise use a fallback
cmap <C-y> <Plug>EasyClipCommandModePaste
else
cnoremap <C-y> <C-r>+
endif
"}}}
endfunction
"}}}
" yY yanks the line minus the <CR> at the end
" just like dD from EasyClip
nnoremap yY m`0y$``
" Duplicate lines, upwards and downwards
" TODO: A count should create X copies
nnoremap <silent> yp :copy +0<CR>
nnoremap <silent> yP :copy -1<CR>
"}}}
" Command Line {{{
" EMACS/Readline compatible (mostly)
" <C-b>: Move <1 character {{{
cnoremap <C-b> <Left>
cnoremap <C-x><C-b> <C-b>
"}}}
" <C-f>: Move >1 character {{{
cnoremap <C-f> <Right>
cnoremap <C-x><C-f> <C-f>
"}}}
" <A-f>: Move >1 word {{{
cnoremap <A-f> <C-Right>
"}}}
" <A-b>: Move <1 word {{{
cnoremap <A-b> <C-Left>
"}}}
" <C-a>: Start of Line {{{
cnoremap <C-a> <Home>
cnoremap <C-x><C-a> <C-a>
"}}}
"<C-e>: End of line
" <C-d>: Delete >1 character {{{
cnoremap <C-d> <C-r>=CommandLine_Helper_DeleteForward()<CR><Del>
cnoremap <C-x><C-d> <C-d>
"}}}
" <C-k>: Delete line >cursor {{{
cnoremap <C-k> <C-\>eCommandLine_KillForward()<CR>
cnoremap <C-x><C-k> <C-k>
"}}}
"<C-u>: Delete line <cursor
" Helper Functions {{{
function! s:CommandLine_Is_End()
return getcmdpos() - 1 == strlen(getcmdline())
endfunction
function! CommandLine_Helper_DeleteForward()
" If the cursor is at the end of the command line,
" insert a character to be deleted by the <Del>
return s:CommandLine_Is_End() ? 'x' : ''
endfunction
function! CommandLine_KillForward()
let l:line = getcmdline()
let l:cur = getcmdpos()
let l:s_from = 0
let l:s_to = l:cur - 1
return strpart(l:line, l:s_from, l:s_to)
endfunction
"}}}
"}}}
" Data Safety and Managing {{{
nnoremap <silent> <Leader>w :call <SID>WriteCurrentBuffer()<CR>
function! s:WriteCurrentBuffer()
let l:dir = expand('%:h:p')
if !isdirectory(l:dir)
echom 'Making directory: '.l:dir
call mkdir(l:dir, 'p')
endif
if &readonly
SudoWrite
else
if exists('b:resolved_symlink')
write!
unlet! b:resolved_symlink
else
write
endif
endif
endfunction
set history=1000 " Disk space is REALLY cheap
function! CheckDir(dir) "{{{
if !isdirectory(a:dir)
call mkdir(a:dir,"p")
endif
endfunction "}}}
set fileformats=unix,dos,mac "ALL the formats, by this order
" Vim Info {{{
set viminfo='150 "Save the marks for this much files !must exist!
set viminfo+=f0 "Don't save '0 to '9
set viminfo+=! "Save upper-case variables
set viminfo+=h "Don't activate search highlight on start
set viminfo+=s50 "Don't save registers larger than this Kb
set viminfo+=<100 "nor larger than these lines
" set viminfo+=r$SKIP_PATH_PREFIX
" set viminfo+=n$VIMINFO_FILENAME !must be the last one!
augroup vimrc_viminfo | autocmd!
autocmd VimEnter * call s:SetupViminfo()
augroup END
function! s:SetupViminfo() "{{{
" Only if there was a setup
if !exists('g:viminfo_old') || !exists('g:viminfo_new')
return
endif
if filereadable(g:viminfo_old) "Make sure it's there
" Read the info in the old viminfo file
execute 'rviminfo!' g:viminfo_old
call delete(g:viminfo_old)
endif
if filereadable(g:viminfo_new) "Make sure it's there
" This runs after the viminfo is read, so just read it again
execute 'rviminfo!' g:viminfo_new
endif
wviminfo "Merge both files
rviminfo!
" Return to status quo
unlet g:viminfo_old g:viminfo_new
endfunction
"}}}
" }}}
" Undo {{{
set undofile
" set undodir=OS_specific
set undolevels=1500 " Undo forever
" }}}
" Views {{{
" set viewdir=OS_specific
set viewoptions+=slash " The One True Path Separator
set viewoptions+=unix " The One True Format
"}}}
" Swap Files {{{
" set directory=OS_specific
" }}}
" Backup Files {{{
set backup writebackup "Backup and delete old file
set backupcopy=yes " Keep the inodes on Linux
" set backupdir=OS_specific
" Don't backup this file patterns
let &backupskip=expand($VIMRUNTIME).'/*'
set backupext=.vim.bak
" }}}
" Sessions {{{
set sessionoptions-=help "Don't store the help windows
set sessionoptions-=options "Don't store options in sessions
set sessionoptions+=slash "The One True Path Separator
set sessionoptions+=unix "The One True Format
" }}}
" Follow symlinks {{{
" NOTE: this happens with directory symlinks anyway (due to Vim's chdir/getcwd
" magic when getting filenames).
" Sources:
" - https://github.com/blueyed/dotfiles
" - https://github.com/tpope/vim-fugitive/issues/147#issuecomment-7572351
" - http://www.reddit.com/r/vim/comments/yhsn6/is_it_possible_to_work_around_the_symlink_bug/c5w91qw
function! s:vimrc_follow_symlinks(...)
unlet! b:resolved_symlink
if exists('w:no_resolve_symlink') && w:no_resolve_symlink
return
endif
if &ft == 'help'
return
endif
let fname = a:0 ? a:1 : expand('%')
if fname =~ '^\w\+:/'
" Do not mess with 'fugitive://' etc.
return
endif
let fname = simplify(fname)
let resolvedfile = resolve(fname)
if resolvedfile == fname
return
endif
let resolvedfile = fnameescape(resolvedfile)
let sshm = &shm
set shortmess+=A " silence ATTENTION message about swap file (would get displayed twice)
redraw " Redraw now, to avoid hit-enter prompt.
exec 'file ' . resolvedfile
let &shm=sshm
unlet! b:git_dir
call fugitive#detect(resolvedfile)
if &modifiable
" Only display a note when editing a file, especially not for `:help`.
redraw " Redraw now, to avoid hit-enter prompt.
echomsg 'Resolved symlink: =>' resolvedfile
let b:resolved_symlink = 1
endif
endfunction
command! -bar FollowSymlink call s:vimrc_follow_symlinks()
command! ToggleFollowSymlink let w:no_resolve_symlink = !get(w:, 'no_resolve_symlink', 0) | echo "w:no_resolve_symlink =>" w:no_resolve_symlink
augroup vimrc_symlinks | autocmd!
autocmd BufReadPost * nested call s:vimrc_follow_symlinks()
augroup end
" }}}
" }}}
" Appearance {{{
set background=dark
if &t_Co >= 256 || has('gui_running') " Something nice
colorscheme harlequin
else "Sensible fallback
colorscheme evening
endif
set background=dark "Again, for some reason
if has("syntax")
syntax enable
endif
set laststatus=2 "Always show the statusline
set hlsearch "Highlight searches ...
nohlsearch "but not when starting up
set sidescroll=1 "Scroll 1 line at a time, horizontally
set scrolloff=5
set sidescrolloff=10
" Toggle line wrapping
nnoremap <silent> <Leader>tw :setlocal wrap!<CR>
"{{{ Non-Printable Characters
let &showbreak = ' ↪'
set list "Show non-printable characters
let &listchars = 'tab: '
"Alternate tab: ≈~
set listchars+=trail:•
set listchars+=precedes:⇇,extends:⇉
set listchars+=nbsp:·
" set listchars+=eol:¶
"}}}
" Numbers {{{
set numberwidth=1 " Minimal width of the number column
set nonumber norelativenumber " No line numbers by default ...
"... but toggle them with:
nnoremap <silent> <Leader>tn :call <SID>ToggleNumber()<CR>
nnoremap <silent> <Leader>tN :call <SID>ToggleRelativeNumber()<CR>
" Functions {{{
" Let the toggle number mapping toggle all numbers, and persist the relative
" number option with a script variable
function! s:ToggleNumber()
if &number
let s:vimrc_relativenumber = &relativenumber
setlocal nonumber norelativenumber
else
setlocal number
let &l:relativenumber = (exists('s:vimrc_relativenumber')) ? s:vimrc_relativenumber : 0 "OFF
endif
endfunction
function! s:ToggleRelativeNumber()
if &number
setlocal relativenumber!
else
let s:vimrc_relativenumber = exists('s:vimrc_relativenumber') ? !s:vimrc_relativenumber : 1 "ON
endif
endfunction
"}}}
"}}}
" Folds {{{
nnoremap <silent> <Leader>tf :call <SID>ToggleFolds()<CR>
function! s:ToggleFolds()
let l:lvl = foldlevel('.')
if l:lvl + 1 > &l:foldcolumn
" Extent the column to the new distance
let &l:foldcolumn = l:lvl + 1
else
if &l:foldcolumn > 0
set foldcolumn=0
else
let &l:foldcolumn = foldlevel('.') + 1
endif
endif
endfunction
"}}}
" Cursor Line and Column {{{
set nocursorline nocursorcolumn
nnoremap <silent> <Leader>tc :setlocal cursorline!<CR>
nnoremap <silent> <Leader>tC :setlocal cursorcolumn!<CR>
"}}}
"}}}
" Windowing Systems {{{
set noequalalways " Don't resize the windows on resize
function! s:vimrc_fullscreen()
echohl WarningMsg
echo 'Fullscreen: Needs OS specific mappings!'
echohl None
endfunction
" This should be remapped on OS specific places
nnoremap <Plug>ToggleFullscreen :call <SID>vimrc_fullscreen()<CR>
nmap <silent> <F11> <Plug>ToggleFullscreen
" Close the bottom windows on <C-w><C-q>. This aliases an alias for `ZQ`
nnoremap <silent> <Plug>(vimrc-close-bwin) :lclose<CR>:cclose<CR>:pclose<CR>:UndotreeHide<CR>
nmap <silent> <C-w><C-q> <Plug>(vimrc-close-bwin)
"}}}
" Navigation {{{
nnoremap <Space> <C-d>
nnoremap <S-Space> <C-u>
nmap g<Space> <S-Space>
nnoremap <silent> <C-Left> :bprevious<CR>
nnoremap <silent> <C-Right> :bnext<CR>
" Tabs {{{
nmap <A-h> <Plug>AirlineSelectPrevTab
nmap <A-l> <Plug>AirlineSelectNextTab
nmap <silent> <A-S-h> :tabmove -1<CR>
nmap <silent> <A-S-l> :tabmove +1<CR>
nmap <A-1> <Plug>AirlineSelectTab1
nmap <A-2> <Plug>AirlineSelectTab2
nmap <A-3> <Plug>AirlineSelectTab3
nmap <A-4> <Plug>AirlineSelectTab4
nmap <A-5> <Plug>AirlineSelectTab5
nmap <A-6> <Plug>AirlineSelectTab6
nmap <A-7> <Plug>AirlineSelectTab7
nmap <A-8> <Plug>AirlineSelectTab8
nmap <A-9> <Plug>AirlineSelectTab9
nnoremap <A-q> :tabclose<CR>
"}}}
set hidden "Don't prompt when changing buffers
" Alt-jk to move around {{{
if has('gui_running')
nnoremap <A-j> <C-e>
nnoremap <A-k> <C-y>
else
nnoremap <Esc>j <C-e>
nnoremap <Esc>k <C-y>
endif
"}}}
"On visual-block let the cursor go to "illegal" places (Half-tabs, past the end, etc)
set virtualedit=block
" Jumps {{{
" <C-o>: Go back to
" The opposite of <C-o>, aliased by SuperTab
nnoremap g. <C-i>
nnoremap <silent> g: :call <SID>goto_jump()<CR>
function! s:goto_jump()
" http://vim.wikia.com/wiki/Jumping_to_previously_visited_locations
jumps
let j = input('Jump to: ')
if j != ''
let pattern = '\v\c^\+'
let l:cmd = 'normal! '
if j =~ pattern
let j = substitute(j, pattern, '', 'g')
let l:cmd .= j . "\<C-i>"
else
let l:cmd .= j . "\<C-o>"
endif
let l:cmd .= 'zzzv'
execute l:cmd
endif
endfunction
"}}}
" "Smart" Apostrophe {{{
nnoremap ' `
nnoremap ` '
"}}}
" "Smart" Zero {{{
nnoremap 0 ^
nnoremap ^ 0
"}}}
" Smart Underscore {{{
function! SmartUnderscore()
let l:line = line('.')
let l:col = col('.')
execute 'normal! ^'
let l:soft = col('.')
execute 'normal! 0'
let l:hard = col('.')
if l:col != l:soft
call cursor(l:line, l:soft)
else
call cursor(l:line, l:hard)
endif
endfunction
nnoremap <silent> _ :<C-u>call SmartUnderscore()<CR>
"}}}
" Quickfix and Location List {{{
autocmd FileType qf call s:vimrc_listings()
function! s:vimrc_listings()
redir => buf
silent file
redir END
if match(buf, '\cQuickfix') > -1
" Quickfix
nnoremap <silent> <buffer> q :cclose<CR>
nnoremap <silent> <buffer> <CR> <CR>
nnoremap <silent> <buffer> l <CR>:cclose<CR>
nnoremap <silent> <buffer> L <CR>:wincmd w<CR>
nnoremap <silent> <buffer> gg :crewind<CR>:wincmd w<CR>
nnoremap <silent> <buffer> j :cnext<CR>
nnoremap <silent> <buffer> J :cnext<CR>:wincmd w<CR>
nnoremap <silent> <buffer> <A-j> j
nnoremap <silent> <buffer> k :cprevious<CR>
nnoremap <silent> <buffer> K :cprevious<CR>:wincmd w<CR>
nnoremap <silent> <buffer> <A-k> k
nnoremap <silent> <buffer> G :clast<CR>:wincmd w<CR>
else
" Location List
nnoremap <silent> <buffer> q :lclose<CR>
nnoremap <silent> <buffer> <CR> <CR>
nnoremap <silent> <buffer> l <CR>:lclose<CR>
nnoremap <silent> <buffer> L <CR>:wincmd w<CR>
nnoremap <silent> <buffer> gg :lrewind<CR>:wincmd w<CR>
nnoremap <silent> <buffer> j :lnext<CR>
nnoremap <silent> <buffer> J :lnext<CR>:wincmd w<CR>
nnoremap <silent> <buffer> <A-j> j
nnoremap <silent> <buffer> k :lprevious<CR>
nnoremap <silent> <buffer> K :lprevious<CR>:wincmd w<CR>
nnoremap <silent> <buffer> <A-k> k
nnoremap <silent> <buffer> G :llast<CR>:wincmd w<CR>
endif
endfunction
" Quickfix Manipulation
nnoremap <silent> [q :cprevious<CR>zzzv
nnoremap <silent> ]q :cnext<CR>zzzv
" Location List Manipulation
nnoremap <silent> [l :lprevious<CR>zzzv
nnoremap <silent> ]l :lnext<CR>zzzv
"}}}
"}}}
" Diff & Splits {{{
" Diffs {{{
set diffopt+=iwhite "Ignore whitespace on diffs
" Jump to the next hunk, but choose how
nnoremap <silent> ]c :call <SID>HunkMoveTo(1)<CR>
nnoremap <silent> [c :call <SID>HunkMoveTo(0)<CR>
function! s:HunkMoveTo(next)
let l:cmd = ''
if &diff
execute 'normal! '.(a:next ? ']c' : '[c')
return
endif
if exists('b:sy') && len(b:sy.hunks) > 0
" Use Signify
let l:cmd = "\<Plug>".'(signify-'. (a:next ? 'next' : 'prev') .'-hunk)'
elseif exists('b:gitgutter_tracked')
" Use GitGutter
let l:cmd = "\<Plug>".'GitGutter'. (a:next ? 'Next' : 'Prev') .'Hunk'
endif
" Center and open folds
let l:cmd .= 'zzzv'
execute 'normal ' . l:cmd
endfunction
nnoremap <silent> du :<C-r>diffupdate<CR>
" After changing something in a diff, move to the next diff
nmap do do]c
nmap dp dp]c
" Diff the current file
" TODO: Do something similar for signify
nnoremap <silent> <Leader>d :Gdiff<CR>
" One-shot diff of the current file
" This is plugin-specific
nnoremap <silent> <Leader>D :call DiffOneShot()<CR>
function! DiffOneShot()
" Git Gutter
if exists('g:gitgutter_enabled') && g:gitgutter_enabled == 0
call s:DiffOneShot_GitGutter()
elseif exists('b:sy') && b:sy.active == 0
call s:DiffOneShot_Signify()
endif
endfunction
"}}}
" Splits {{{
set splitright " New splits to the right
set nosplitbelow " New splits on top
"}}}
"}}}
" Search {{{
set ignorecase smartcase "Sane defaults
set incsearch "Start searching right away
" Use <C-l> to clear the highlighting of :set hlsearch.
" <C-l> Already clears the screen, it's just a bonus
" Refresh the statusline too
nnoremap <silent> <C-l> :nohlsearch<CR>:AirlineRefresh<CR><C-l>
" Center on search
" Make sure it works on folds
nnoremap * *zvzz
nnoremap n nzvzz
nnoremap N Nzvzz
" Don't mess with search directions, n is ALWAYS forward
augroup vimrc_setup_search | autocmd!
autocmd VimEnter * call s:vimrc_setup_search()
augroup end
function! s:vimrc_setup_search()
nmap # *NN
nmap g# g*NN
if exists('g:loaded_visualstar') && g:loaded_visualstar == 1
xmap # *NN
xmap g# g*NN
endif
endfunction
" 'g/' to start a full-file search and replace for the current pattern
" Also works on visual mode
nnoremap g/ :<C-u>%s@<C-r>/@@<Left>
xnoremap g/ :s@<C-r>/@@<Left>
" '&' to repeat last ':s', use flags too
nnoremap & :&&<CR>
xnoremap & :&&<CR>
"}}}
" Mouse {{{
set mouse=a "Enable the mouse in all modes
set selectmode= "But no select mode, ever
set mousemodel=extend "Just like xterm, everywhere
set nomousefocus "Don't move the mouse to switch windows
" But toggle this setting, sometimes it's cool
nnoremap <silent> <Leader>tm :set mousefocus!<CR>
set mousehide "Hide the pointer when writing
"}}}
" Help {{{
" <F1> for choosing help
nnoremap <F1> :help<Space>
" g<F1> to close the help, regardless of current buffer
if exists(':helpclose') "Newer vim
nnoremap <silent> <C-F1> :helpclose<CR>
else
nmap <silent> <C-F1> <F1><CR><F1>
endif
nmap g<F1> <C-F1>
" <F1> on Insert mode does the same
imap <F1> <C-o><F1>
imap <C-F1> <C-o><C-F1>
"}}}
" Spell {{{
let g:spelling_filetypes = [
\ 'text',
\ 'mkd', 'markdown',
\ 'rst',
\ 'asciidoc',
\ 'gitcommit',
\ 'help',
\ 'mail'
\]
let g:spelling_filetypes_comma = join(g:spelling_filetypes,',')
let g:spelling_filetypes_regex = '\V'.join(g:spelling_filetypes,'\|')
" Toggle spell checking
nnoremap <silent> <Leader>tS :call SpellLoop_ToggleSpell()<CR>
set nospell "Disable it by default
set spelllang=en "Just a sensible default
set spellfile= "Auto-discover
" set spellcapcheck="[.?!]\_[\])'" \t]\+" "Check capitals on start of sentences
set spellsuggest=fast "Works reasonably enough, but it's really fast, especially for English
set spellsuggest+=25 "Show at most this suggestions
let g:loaded_spellfile_plugin = 1 "Don't ask for downloading spellfiles
function! s:vimrc_text()
" Initialize the spelling plugins
call lexical#init({"spell": 1})
call SpellLoop_Init()
" FIXME: Integrate SpellCheck into syntastic
nnoremap <silent> <buffer> Q :SpellLCheck!<CR>
" `==` formats the entire buffer properly, instead of indenting
" Keep the current location and leverage the "textobj-entire" plugin
nmap <silent> <buffer> == m`gqa<CR>'`
runtime scripts/text_wrapping.vim
runtime scripts/text_mappings.vim
endfunction
augroup vimrc_spelling | autocmd!
" Mark this files as "text"
execute 'autocmd FileType' g:spelling_filetypes_comma 'call s:vimrc_text()'
" Disable indent guides
let g:indent_guides_exclude_filetypes = g:spelling_filetypes
augroup END
"}}}
" Whitespace Management {{{
set autoindent smartindent "Indent in smart, language-specific ways
set shiftround "Align to the nearest "shiftwidth"
" Enter {{{
" On normal mode, Enter put a new line after the current one
nnoremap <silent> <CR> :put =''<CR>
" And S-Enter puts it before
nnoremap <silent> <S-CR> :put! =''<CR>
" Synonym for terminals
nmap g<CR> <S-CR>
"}}}
" Tab {{{
set smarttab "Use 'shiftwidth' with tabs
" Tab to indent text by shiftwidth columns
" C-Tab to indent text by 1 column, using spaces
function! IndentLine(cols)
if a:cols > 0
let l:pat = '^'
let l:subs = repeat(' ',a:cols)
elseif a:cols < 0
" The last x spaces, where x < -a:cols
" If that doesn't match, just ^
" TODO: Remove tabs?
let l:pat = '\v^\s{-}\zs {1,'.-a:cols.'}\ze\S|^'
let l:subs = ''
else
return "Do nothing
endif
if exists(':keeppatterns')
let l:keeppatterns = 'keeppatterns '
else
let l:keeppatterns = ''
let l:old_search = @/
endif
execute l:keeppatterns 'substitute' '/'.l:pat.'/'.l:subs.'/'
if empty(l:keeppatterns)
let @/ = l:old_search
endif
endfunction
command! -nargs=? -range IndentLine <line1>,<line2>call IndentLine(<f-args>)
nnoremap <Tab> >>
nnoremap <S-Tab> <<
nnoremap <silent> <C-Tab> :IndentLine 1<CR>
nnoremap <silent> <C-S-Tab> :IndentLine -1<CR>
nmap g<Tab> <C-Tab>
nmap g<S-Tab> <C-S-Tab>
" On visual mode, keep the indented text select
vnoremap <Tab> >gv
vnoremap <S-Tab> <gv
vnoremap <C-Tab> :IndentLine 1<CR>gv
vnoremap <C-S-Tab> :IndentLine -1<CR>gv
vmap g<Tab> <C-Tab>
vmap g<S-Tab> <C-S-Tab>
"
"}}}
" Split the line at this point (replaces current char)
" gS reshuffles the resulting lines
nnoremap <silent> gs r<CR>
nmap <silent> gS gs-j
" Tabularize on Steroids {{{
function! TabularizeThisN(ask)
if exists('g:tabular_loaded')
let l:cmd = ':Tabularize'
if a:ask != 1 && exists('*TabularizeHasPattern') && TabularizeHasPattern()
" Reuse the last Tabularize command
let l:cmd .= "\<CR>"
else
let l:cmd .= "\<Space>"
endif
return l:cmd
endif
endfunction
" Double leader to always ask for a new pattern
nnoremap <expr> <Leader><Tab> TabularizeThisN(0)
nnoremap <expr> <Leader><Leader><Tab> TabularizeThisN(1)
"}}}
"}}}
" 2Leader Commands{{{
" cd: Change dir to the current file
nnoremap <silent> <Leader><Leader>cd :lcd %:h<CR>:pwd<CR>
" CD: Change dir to current file. Works globally
nnoremap <silent> <Leader><Leader>CD :cd %:h<CR>:pwd<CR>
" b : Show a list of buffers and use CtrlP functionalities
nnoremap <silent> <Leader><Leader>b :CtrlPBuffer<CR>
" m : Show a list of marks, and prompt for one
nnoremap <silent> <Leader><Leader>m :marks<CR>:mark<Space>
" Vim: Yo dawg, etc {{{
function! s:IsVimRcFile()
let l:cfull = fnamemodify(expand('%'),':p')
let l:cdir = fnamemodify(expand('%'),':p:h')
let l:cname = fnamemodify(expand('%'),':t')
if index([expand($MYVIMRC),expand($MYGVIMRC)], l:cfull) != -1
return 1
elseif l:cdir ==# g:user_dir && l:cname =~# '\v\Cg?vimrc(\.\w+)?'
return 1
else
return 0
endif
endfunction
function! s:vimrc_edit(vimrc)
if expand('%:p') ==# expand(a:vimrc)
return
endif
execute IsEmptyBuffer() ? 'edit' : 'tabnew' a:vimrc
tabmove 0 "Move the tab to the leftmost position
endfunction
" ve: Edit your vimrc
" vE: Edit your gvimrc
nnoremap <silent> <Leader><Leader>ve :call <SID>vimrc_edit($MYVIMRC)<CR>
nnoremap <silent> <Leader><Leader>vE :call <SID>vimrc_edit($MYGVIMRC)<CR>
function! s:vimrc_write()
if s:IsVimRcFile()
silent write
endif
endfunction
" vs: Source your vimrc right here
nnoremap <silent> <Leader><Leader>vs :call <SID>vimrc_write()<CR>:source $MYVIMRC<CR>:AirlineRefresh<CR>
"}}}
"}}}
" Plugin Configuration {{{
0