ansible-role-common/templates/_vimrc.j2

335 lines
13 KiB
Django/Jinja
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

set rtp+=~/.fzf
" ----------------------------------------------------------------------------
" KEY MAPS
" ----------------------------------------------------------------------------
nmap \A :set formatoptions+=a<CR>:echo "autowrap enabled"<CR>
nmap \M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
nmap \T :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
nmap \a :set formatoptions-=a<CR>:echo "autowrap disabled"<CR>
" Search for the word under the cursor in the current directory
nmap <M-k> mo:Ack! "\b<cword>\b" <CR>
nmap <Esc>k mo:Ack! "\b<cword>\b" <CR>
nmap ˚ mo:Ack! "\b<cword>\b" <CR>
nmap <M-S-k> mo:Ggrep! "\b<cword>\b" <CR>
nmap <Esc>K mo:Ggrep! "\b<cword>\b" <CR>
" Fix annoyances in the QuickFix window, like scrolling too much
autocmd FileType qf setlocal number nolist scrolloff=0
autocmd Filetype qf wincmd J " Makes sure it's at the bottom of the vim window
" Commands to send common keystrokes using tmux
let g:tmux_console_pane = '0:0.0'
let g:tmux_server_pane = '0:0.0'
function TmuxPaneRepeat()
write
silent execute ':!tmux send-keys -t' g:tmux_console_pane 'C-p' 'C-j'
redraw!
endfunction
function TmuxPaneClear()
silent execute ':!tmux send-keys -t' g:tmux_server_pane 'C-j' 'C-j' 'C-j' 'C-j' 'C-j' 'C-j' 'C-j'
redraw!
endfunction
" ----------------------------------------------------------------------------
" ABBREVATIONS
" ----------------------------------------------------------------------------
" Typing `$c` on the command line expands to `:e` + the current path, so it's easy to edit a file in
" the same directory as the current file.
cnoremap $c e <C-\>eCurrentFileDir()<CR>
function! CurrentFileDir()
return "e " . expand("%:p:h") . "/"
endfunction
" ----------------------------------------------------------------------------
" OPTIONS
" ----------------------------------------------------------------------------
set autoindent " Carry over indenting from previous line
set autoread " Don't bother me when a file changes
set autowrite " Write on :next/:prev/^Z
set backspace=indent,eol,start
" Allow backspace beyond insertion point
set cindent " Automatic program indenting
set cinkeys-=0# " Comments don't fiddle with indenting
set cino= " See :h cinoptions-values
set commentstring=\ \ #%s " When folds are created, add them to this
set copyindent " Make autoindent use the same chars as prev line
set directory-=. " Don't store temp files in cwd
set encoding=utf8 " UTF-8 by default
set expandtab " No tabs
set fileformats=unix,dos,mac " Prefer Unix
set fillchars=vert:\ ,stl:\ ,stlnc:\ ,fold:-,diff:┄
" Unicode chars for diffs/folds, and rely on
" Colors for window borders
silent! set foldmethod=marker " Use braces by default
set formatoptions=tcqn1 " t - autowrap normal text
" c - autowrap comments
" q - gq formats comments
" n - autowrap lists
" 1 - break _before_ single-letter words
" 2 - use indenting from 2nd line of para
set hidden " Don't prompt to save hidden windows until exit
set history=200 " How many lines of history to save
set hlsearch " Hilight searching
set ignorecase " Case insensitive
set incsearch " Search as you type
set infercase " Completion recognizes capitalization
set laststatus=2 " Always show the status bar
set linebreak " Break long lines by word, not char
set list " Show whitespace as special chars - see listchars
set listchars=tab:»\ ,extends:,precedes:,nbsp:·,trail:· " Unicode characters for various things
set matchtime=2 " Tenths of second to hilight matching paren
set modelines=5 " How many lines of head & tail to look for ml's
silent! set mouse=nvc " Use the mouse, but not in insert mode
set nobackup " No backups left after done editing
set number " Show line numbers to start
set visualbell t_vb= " No flashing or beeping at all
set nowritebackup " No backups made while editing
set ruler " Show row/col and percentage
set scroll=4 " Number of lines to scroll with ^U/^D
set scrolloff=15 " Keep cursor away from this many chars top/bot
set sessionoptions-=options " Don't save runtimepath in Vim session (see tpope/vim-pathogen docs)
set shiftround " Shift to certain columns, not just n spaces
set shiftwidth=2 " Number of spaces to shift for autoindent or >,<
set shortmess+=A " Don't bother me when a swapfile exists
set showbreak= " Show for lines that have been wrapped, like Emacs
set showmatch " Hilight matching braces/parens/etc.
set sidescrolloff=3 " Keep cursor away from this many chars left/right
set smartcase " Lets you search for ALL CAPS
set softtabstop=2 " Spaces 'feel' like tabs
set suffixes+=.pyc " Ignore these files when tab-completing
set tabstop=2 " The One True Tab
set textwidth=100 " 100 is the new 80
set notitle " Don't set the title of the Vim window
set wildmenu " Show possible completions on command line
set wildmode=list:longest,full " List all options and complete
set wildignore=*.class,*.o,*~,*.pyc,.git,node_modules " Ignore certain files in tab-completion
" Essential for filetype plugins.
filetype plugin indent on
" ----------------------------------------------------------------------------
" CUSTOM COMMANDS AND FUNCTIONS
" ----------------------------------------------------------------------------
" ----------------------------------------------------------------------------
" PLUGIN SETTINGS
" ----------------------------------------------------------------------------
{% if usersetup_vimplugins|bool %}
" Use Pathogen for plugin management. See update.sh in this directory.
runtime bundle/vim-pathogen/autoload/pathogen.vim
call pathogen#infect()
call pathogen#helptags()
" GitGutter styling to use · instead of +/-
let g:gitgutter_sign_added = '∙'
let g:gitgutter_sign_modified = '∙'
let g:gitgutter_sign_removed = '∙'
let g:gitgutter_sign_modified_removed = '∙'
" ALE
let g:ale_sign_warning = '▲'
let g:ale_sign_error = '✗'
highlight link ALEWarningSign String
highlight link ALEErrorSign Title
" Lightline
let g:lightline = {
\ 'colorscheme': 'wombat',
\ 'active': {
\ 'left': [['mode', 'paste'], ['filename', 'modified']],
\ 'right': [['lineinfo'], ['percent'], ['readonly', 'linter_warnings', 'linter_errors', 'linter_ok']]
\ },
\ 'component_expand': {
\ 'linter_warnings': 'LightlineLinterWarnings',
\ 'linter_errors': 'LightlineLinterErrors',
\ 'linter_ok': 'LightlineLinterOK'
\ },
\ 'component_type': {
\ 'readonly': 'error',
\ 'linter_warnings': 'warning',
\ 'linter_errors': 'error'
\ },
\ }
function! LightlineLinterWarnings() abort
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? '' : printf('%d ◆', all_non_errors)
endfunction
function! LightlineLinterErrors() abort
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? '' : printf('%d ✗', all_errors)
endfunction
function! LightlineLinterOK() abort
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? '✓ ' : ''
endfunction
" Update and show lightline but only if it's visible (e.g., not in Goyo)
autocmd User ALELint call s:MaybeUpdateLightline()
function! s:MaybeUpdateLightline()
if exists('#lightline')
call lightline#update()
end
endfunction
{% endif %}
" ----------------------------------------------------------------------------
" COLORS
" ----------------------------------------------------------------------------
" Make sure colored syntax mode is on, and make it Just Work with 256-color terminals.
set background=dark
let g:rehash256 = 1 " Something to do with Molokai?
" colorscheme molokai
if !has('gui_running')
if $TERM == "xterm-256color" || $TERM == "screen-256color" || $COLORTERM == "gnome-terminal"
set t_Co=256
elseif has("terminfo")
colorscheme default
set t_Co=8
set t_Sf=[3%p1%dm
set t_Sb=[4%p1%dm
else
colorscheme default
set t_Co=8
set t_Sf=[3%dm
set t_Sb=[4%dm
endif
" Disable Background Color Erase when within tmux - https://stackoverflow.com/q/6427650/102704
if $TMUX != ""
set t_ut=
endif
endif
syntax on
" Window splits & ruler are too bright, so change to white on grey (non-GUI)
highlight StatusLine cterm=NONE ctermbg=blue ctermfg=white
highlight StatusLineTerm cterm=NONE ctermbg=blue ctermfg=white
highlight StatusLineNC cterm=NONE ctermbg=black ctermfg=white
highlight StatusLineTermNC cterm=NONE ctermbg=black ctermfg=white
highlight VertSplit cterm=NONE ctermbg=black ctermfg=white
" taglist.vim's filenames is linked to LineNr by default, which is too dark
highlight def link MyTagListFileName Statement
highlight def link MyTagListTagName Question
" Turn off horrible coloring for CDATA in XML
highlight def link xmlCdata NONE
" Some custom spell-checking colors
"highlight SpellBad term=underline cterm=underline ctermbg=NONE ctermfg=205
"highlight SpellCap term=underline cterm=underline ctermbg=NONE ctermfg=33
"highlight SpellRare term=underline cterm=underline ctermbg=NONE ctermfg=217
"highlight SpellLocal term=underline cterm=underline ctermbg=NONE ctermfg=72
" The Ignore color should be... ignorable
silent! highlight Ignore cterm=bold ctermfg=black ctermbg=bg
highlight clear FoldColumn
highlight def link FoldColumn Ignore
highlight clear Folded
highlight link Folded Ignore
highlight clear LineNr
highlight! def link LineNr Ignore
" Custom search colors
highlight clear Search
highlight Search term=NONE cterm=NONE ctermfg=white ctermbg=black
" Make hilighted matching parents less annoying
highlight clear MatchParen
highlight link MatchParen Search
" Custom colors for NERDTree
highlight def link NERDTreeRO NERDTreeFile
" Make trailing spaces very visible
"highlight SpecialKey ctermbg=Yellow guibg=Yellow
" Make menu selections visible
highlight PmenuSel ctermfg=black ctermbg=magenta
" The sign column slows down remote terminals
highlight clear SignColumn
highlight link SignColumn Ignore
" Markdown could be more fruit salady
highlight link markdownH1 PreProc
highlight link markdownH2 PreProc
highlight link markdownLink Character
highlight link markdownBold String
highlight link markdownItalic Statement
highlight link markdownCode Delimiter
highlight link markdownCodeBlock Delimiter
highlight link markdownListMarker Todo
" ----------------------------------------------------------------------------
" FILE TYPE TRIGGERS
" ----------------------------------------------------------------------------
" Reset all autocommands
augroup vimrc
autocmd!
au BufNewFile,BufRead *.cson set ft=coffee
au BufNewFile,BufRead *.glsl setf glsl
au BufNewFile,BufRead *.gyp set ft=python
au BufNewFile,BufRead *.html setlocal nocindent smartindent
au BufNewFile,BufRead *.i7x setf inform7
au BufNewFile,BufRead *.ini setf conf
au BufNewFile,BufRead *.input setf gnuplot
au BufNewFile,BufRead *.json set ft=json tw=0
au BufNewFile,BufRead *.less setlocal ft=less nocindent smartindent
au BufNewFile,BufRead *.md setlocal ft=markdown nolist
au BufNewFile,BufRead *.md,*.markdown setlocal foldlevel=999 tw=0 nocin
au BufNewFile,BufRead *.ni setlocal ft=inform nolist ts=2 sw=2 noet
au BufNewFile,BufRead *.plist setf xml
au BufNewFile,BufRead *.rb setlocal noai
au BufNewFile,BufRead *.rxml setf ruby
au BufNewFile,BufRead *.sass setf sass
au BufNewFile,BufRead *.ttml setf xml
au BufNewFile,BufRead *.vert,*.frag set ft=glsl
au BufNewFile,BufRead *.xml setlocal ft=xml ts=2 sw=2 et
au BufNewFile,BufRead *.zone setlocal nolist ts=4 sw=4 noet
au BufNewFile,BufRead *.zsh setf zsh
au BufNewFile,BufRead *templates/*.html setf htmldjango
au BufNewFile,BufRead .git/config setlocal ft=gitconfig nolist ts=4 sw=4 noet
au BufNewFile,BufRead .gitconfig* setlocal ft=gitconfig nolist ts=4 sw=4 noet
au BufNewFile,BufRead .vimlocal,.gvimlocal setf vim
au BufNewFile,BufRead .zshlocal setf zsh
au BufNewFile,BufRead /tmp/crontab* setf crontab
au BufNewFile,BufRead COMMIT_EDITMSG setlocal nolist nonumber
au BufNewFile,BufRead Makefile setlocal nolist
au FileType gitcommit setlocal nolist ts=4 sts=4 sw=4 noet
au FileType inform7 setlocal nolist tw=0 ts=4 sw=4 noet foldlevel=999
au FileType json setlocal conceallevel=0 foldmethod=syntax foldlevel=999
au FileType make setlocal nolist ts=4 sts=4 sw=4 noet
au FileType markdown syn sync fromstart
au Filetype gitcommit setlocal tw=80
augroup END
" ----------------------------------------------------------------------------
" HOST-SPECIFIC VIM FILE
" ----------------------------------------------------------------------------
" Now load specifics to this host
if filereadable(expand("~/.vimlocal"))
source ~/.vimlocal
endif
" vim:set tw=100: