mirror of
https://github.com/Matir/skel.git
synced 2026-05-26 05:29:09 -07:00
217 lines
5.3 KiB
VimL
217 lines
5.3 KiB
VimL
" Allow full use of vim options
|
|
set nocompatible
|
|
|
|
" Setup paths
|
|
set backupdir=~/.cache/vim/backup//
|
|
set directory=~/.cache/vim/swap//
|
|
set undodir=~/.cache/vim/undo//
|
|
if !isdirectory($HOME . '/.cache/vim/swap')
|
|
silent !mkdir -p ~/.cache/vim/{backup,swap,undo}
|
|
endif
|
|
|
|
" Make sure files get completely written, but don't write backups
|
|
set nobackup
|
|
set writebackup
|
|
|
|
" Whitespace/indent options
|
|
set autoindent
|
|
set copyindent
|
|
set tabstop=2
|
|
set softtabstop=2
|
|
set shiftwidth=2
|
|
set expandtab
|
|
set shiftround
|
|
set backspace=indent,eol,start
|
|
" Shift-tab to go backwards in insert mode
|
|
" Does not work with YCM
|
|
inoremap <S-Tab> <C-d>
|
|
|
|
" Line numbering, ruler
|
|
set number
|
|
set ruler
|
|
|
|
" Setup viminfo for recording positions, etc.
|
|
set viminfo='10,\"100,:20,%,n~/.viminfo
|
|
" Jump back when editing a file
|
|
function! ResCur()
|
|
" Don't jump in git commits since they're generated.
|
|
if &ft == 'gitcommit'
|
|
return
|
|
endif
|
|
if line("'\"") <= line("$")
|
|
normal! g`"
|
|
return
|
|
endif
|
|
endfunction
|
|
augroup resCur
|
|
autocmd!
|
|
autocmd BufWinEnter * call ResCur()
|
|
augroup END
|
|
|
|
" File options
|
|
set encoding=utf-8
|
|
" Syntax highlighting, look and feel
|
|
syntax on
|
|
set background=dark
|
|
if has('gui_running')
|
|
set guifont=Inconsolata\ Medium\ 12
|
|
else
|
|
let g:solarized_termcolors=256
|
|
let g:solarized_termtrans=1
|
|
endif
|
|
if $TERM ==? 'rxvt-unicode-256color'
|
|
" I have .Xresources setup for solarized
|
|
let g:solarized_use16=1
|
|
endif
|
|
silent! colorscheme solarized8
|
|
" Default ASM syntax for ft support
|
|
let asmsyntax="nasm"
|
|
" Too risky to allow file modelines
|
|
set nomodeline
|
|
" Automatically re-read changed files
|
|
set autoread
|
|
" fsync() after writing files
|
|
set fsync
|
|
" Text width 80
|
|
set textwidth=80
|
|
" Write via sudo
|
|
cnoremap sudow w !sudo tee % >/dev/null
|
|
|
|
" Search options
|
|
set incsearch
|
|
set ignorecase
|
|
set smartcase
|
|
" Optional highlighting
|
|
nmap <leader>hs :set hlsearch! hlsearch?<CR>
|
|
|
|
" Toggle paste mode
|
|
nmap <silent> <F4> :set invpaste<CR>:set paste?<CR>
|
|
imap <silent> <F4> <ESC>:set invpaste<CR>:set paste?<CR>
|
|
|
|
" Mediocre Hex editing in vim
|
|
" Source: http://vim.wikia.com/wiki/Improved_hex_editing
|
|
" TODO: move to an include
|
|
nnoremap <C-H> :Hexmode<CR>
|
|
command -bar Hexmode call ToggleHex()
|
|
function ToggleHex()
|
|
" hex mode should be considered a read-only operation
|
|
" save values for modified and read-only for restoration later,
|
|
" and clear the read-only flag for now
|
|
let l:modified=&mod
|
|
let l:oldreadonly=&readonly
|
|
let &readonly=0
|
|
let l:oldmodifiable=&modifiable
|
|
let &modifiable=1
|
|
if !exists("b:editHex") || !b:editHex
|
|
" save old options
|
|
let b:oldft=&ft
|
|
let b:oldbin=&bin
|
|
" set new options
|
|
setlocal binary " make sure it overrides any textwidth, etc.
|
|
let &ft="xxd"
|
|
" set status
|
|
let b:editHex=1
|
|
" switch to hex editor
|
|
%!xxd
|
|
else
|
|
" restore old options
|
|
let &ft=b:oldft
|
|
if !b:oldbin
|
|
setlocal nobinary
|
|
endif
|
|
" set status
|
|
let b:editHex=0
|
|
" return to normal editing
|
|
%!xxd -r
|
|
endif
|
|
" restore values for modified and read only state
|
|
let &mod=l:modified
|
|
let &readonly=l:oldreadonly
|
|
let &modifiable=l:oldmodifiable
|
|
endfunction
|
|
|
|
" Options for syntastic
|
|
let g:syntastic_enable_signs = 1
|
|
let g:syntastic_auto_loc_list = 2
|
|
let g:syntastic_check_on_wq = 0
|
|
let g:syntastic_go_checkers = ['govet', 'errcheck', 'go']
|
|
let g:syntastic_python_checkers=['flake8']
|
|
" Because XXE
|
|
let g:syntastic_xml_checkers=['']
|
|
let g:syntastic_xslt_checkers=['']
|
|
autocmd BufReadPost *
|
|
\ if &readonly
|
|
\| let b:syntastic_mode = 'passive'
|
|
\| else
|
|
\| silent! unlet b:syntastic_mode
|
|
\| endif
|
|
|
|
" Have F5 run the tests and display errors
|
|
nnoremap <silent> <F5> :SyntasticCheck<CR> :Errors<CR>
|
|
|
|
" Load vim-ycm if installed on the system level
|
|
" Currently only works on debian-based systems...
|
|
" It also does not play nicely with virtual envs, so we skip it then
|
|
if isdirectory("/usr/share/vim-youcompleteme") && empty($VIRTUAL_ENV)
|
|
let g:ycm_gopls_binary_path='gopls'
|
|
let g:ycm_autoclose_preview_window_after_insertion=1
|
|
set runtimepath+=/usr/share/vim-youcompleteme
|
|
endif
|
|
|
|
" Enable vim-bracketed-paste mode
|
|
" From
|
|
" https://github.com/ConradIrwin/vim-bracketed-paste/blob/master/plugin/bracketed-paste.vim
|
|
if exists("g:loaded_bracketed_paste")
|
|
finish
|
|
endif
|
|
let g:loaded_bracketed_paste = 1
|
|
|
|
let &t_ti .= "\<Esc>[?2004h"
|
|
let &t_te = "\e[?2004l" . &t_te
|
|
|
|
function! XTermPasteBegin(ret)
|
|
set pastetoggle=<f29>
|
|
set paste
|
|
return a:ret
|
|
endfunction
|
|
|
|
execute "set <f28>=\<Esc>[200~"
|
|
execute "set <f29>=\<Esc>[201~"
|
|
map <expr> <f28> XTermPasteBegin("i")
|
|
imap <expr> <f28> XTermPasteBegin("")
|
|
vmap <expr> <f28> XTermPasteBegin("c")
|
|
cmap <f28> <nop>
|
|
cmap <f29> <nop>
|
|
|
|
" Include a .vimrc.local if it exists
|
|
if filereadable(glob("~/.vimrc.local"))
|
|
source ~/.vimrc.local
|
|
endif
|
|
|
|
" Options for vimoutliner
|
|
autocmd Filetype votl setlocal sts=4
|
|
|
|
" Highlight whitespace at end of file
|
|
highlight ExtraWhitespace ctermbg=red guibg=red
|
|
autocmd Syntax * syn match ExtraWhitespace /\s\+$\| \+\ze\t/ containedin=ALL
|
|
|
|
" Color column at end of lines
|
|
set colorcolumn=+1
|
|
highlight ColorColumn ctermbg=black guibg=lightgrey
|
|
|
|
" Remove smart quotes
|
|
command Unsmartquote %s/“\|”/"/g
|
|
|
|
" Markdown options
|
|
autocmd Filetype markdown set expandtab shiftwidth=4
|
|
|
|
" Python options
|
|
autocmd Filetype python set expandtab shiftwidth=4
|
|
|
|
" Makefile options
|
|
autocmd BufRead,BufNewFile Makefile* set noexpandtab
|
|
|
|
" Enable filetype support
|
|
" Needs to be at end of vimrc
|
|
filetype plugin indent on
|