Restructure vim config

This commit is contained in:
2016-07-05 21:29:27 +01:00
parent 5465bef85d
commit e26b13c742
6 changed files with 334 additions and 299 deletions

8
plugin/autocmds.vim Normal file
View File

@@ -0,0 +1,8 @@
augroup reopen_at_last_cursor
autocmd!
" Reopening a file at last curson position
au FocusGained * set relativenumber
au FocusLost * set norelativenumber
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
\ | exe "normal! g'\"" | endif
augroup END

80
plugin/functions.vim Normal file
View File

@@ -0,0 +1,80 @@
" Strip trailing whitespace
function! <SID>StripWhitespace()
let l = line(".")
let c = col(".")
%s/\s\+$//e
call cursor(l, c)
endfunction
command! StripWhitespace :call <SID>StripWhitespace()
augroup strip_white_space
" Strip whitespace on buffer write
autocmd!
autocmd BufWritePre * :call <SID>StripWhitespace()
augroup END
" Show highlight group under cursor
map \hi :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") .
\ '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
" Stringify
" Make a code block in to a C string literal
function! <SID>Stringify()
" Escape existing escape characters
execute 's/\\/\\\\/ge'
" Escape quotes
execute 's/"/\\"/ge'
" Prepend quote
execute 's/^/"/g'
" Append carriage return, quote
execute 's/$/\\n"/g'
noh
endfunction
map <silent> <leader>s :call <SID>Stringify()<CR>
" Make a C string literal in to a code block
function! <SID>Destringify()
" Remove final quote and carriage return
execute 's/\\n"\s*$//ge'
" Remove first quote
execute 's:^\(\s*\)":\1:ge'
" Remove quote escapes
execute 's/\\"/"/ge'
" Remove escapes of escapes characters
execute 's/\\\\/\\/ge'
noh
endfunction
map <silent> <leader>S :call <SID>Destringify()<CR>
" Invoke terminal command without prompt and then redraw.
command! -nargs=+ Silent execute 'silent <args>' | redraw!
" Set the tab width for the current filetype
function! <SID>TabWidth(width)
execute "set tabstop=".a:width
execute "set shiftwidth=".a:width
execute "set softtabstop=".a:width
echo "Tab width is now ".a:width
endfunction
command! -nargs=1 TabWidth :call <SID>TabWidth(<f-args>)
" Toggle task list bullet
function! <SID>TaskToggle()
" Get current line
let l:line = getline('.')
" Get the ' ' or 'x' character from within the task bullet
let l:pattern = '[-\*+] \[\zs[ x]\ze]'
let l:char = matchstr(l:line, l:pattern)
" Toggle the ' ' or 'x' character
if l:char == 'x'
let l:char = ' '
else
let l:char = 'x'
endif
" Replace the current line with a new one
call setline(line('.'), substitute(l:line, l:pattern, l:char, ''))
endfunction
command! TaskToggle :call <SID>TaskToggle()
nnoremap <leader>x :TaskToggle<CR>

59
plugin/mappings.vim Normal file
View File

@@ -0,0 +1,59 @@
" YouCompleteMe
nnoremap <leader>fx :YcmCompleter FixIt<CR>
nnoremap <leader>jd :YcmCompleter GoTo<CR>
nnoremap <leader>gt :YcmCompleter GetType<CR>
nnoremap <leader>gp :YcmCompleter GetParent<CR>
nnoremap <leader>gd :YcmCompleter GetDoc<CR>
nnoremap <leader>sd :YcmShowDetailedDiagnostic<CR>
" DoxygenToolkit
nnoremap <leader>d :Dox<CR>
" Treat long lines as line containing breaks
nnoremap j gj
nnoremap k gk
" Quick write
map <leader>w :w!<CR>
" Switch panes
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" Quick tabs
exec "nmap <leader>tn :tabnew "
nmap <leader>tc :tabclose<CR>
nmap <leader>to :tabonly<CR>
exec "nmap <leader>tm :tabmove "
" Clear search highlights
map <leader><Space> :noh<CR>
" Quick clipboard yank/put
map <leader>y "+y
map <leader>Y "+Y
map <leader>p "+p
map <leader>P "+P
" Jump to current location list item
nmap <leader>ll :ll<CR>
" Jump to next location list item
nmap <leader>ln :lnext<CR>
" Jump to previous location list item
nmap <leader>lp :lprevious<CR>
" Quickly access spelling menu
imap <C-s> <C-g>u<C-X>s
nmap <C-s> i<C-g>u<C-X>s
" Disable 'Q' from opening Ex mode
nmap Q <nop>
" Disable 'K' from loading man pages in normal mode
nmap K <nop>
" Disable 'K' from loading man pages in visual mode
vmap K <nop>
" Split line at the cursor
nnoremap [j i<CR><Esc>
nnoremap ]j a<CR><Esc>

61
plugin/options.vim Normal file
View File

@@ -0,0 +1,61 @@
" Enable all mouse features
set mouse=a
" Don't show completeopt preview buffer
set completeopt-=preview
" Set window title to titlestring
set title
" Show relative line numbers & current line number
set number
" Keep cursor from buffer edges
set scrolloff=8
" Turn backup off
set nobackup nowritebackup noswapfile
" Wrap to whole words
set wrap linebreak nolist
" Don't add 2 spaces after end of sentence
set nojoinspaces
" Use Unix as standard file type
set fileformats=unix,dos,mac
" Allow : in filenames to allow gf to specify line numbers
set isfname-=:
" Highlight search matches & show search matches while typing
set hlsearch
" Set ignore search case unless mixed
set ignorecase smartcase
" Allow buffers with changes to be hidden
set hidden
" Open new splits on the other side of the axis
set splitbelow splitright
" Indicates a fast terminal connection
set ttyfast
" Set syntax as default fold method
set foldmethod=syntax foldlevel=20
" Automatically write changes to files
set autowrite
" Format text
" r - insert comment leader on 'o' and 'O'
" q - allow formatting with 'gq'
set formatoptions+=rq
" Enable modeline
set modeline
" Don't redraw during execution macros, registers, commands, etc.
set lazyredraw