Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let g:WincentColorColumnBufferNameBlacklist = ['__LanguageClient__']
- let g:WincentColorColumnFileTypeBlacklist = ['command-t', 'diff', 'fugitiveblame', 'undotree', 'nerdtree', 'qf']
- let g:WincentCursorlineBlacklist = ['command-t']
- let g:WincentMkviewFiletypeBlacklist = ['diff', 'hgcommit', 'gitcommit']
- function! autocmds#attempt_select_last_file() abort
- let l:previous=expand('#:t')
- if l:previous !=# ''
- call search('\v<' . l:previous . '>')
- endif
- endfunction
- function! autocmds#should_colorcolumn() abort
- if index(g:WincentColorColumnBufferNameBlacklist, bufname(bufnr('%'))) != -1
- return 0
- endif
- return index(g:WincentColorColumnFileTypeBlacklist, &filetype) == -1
- endfunction
- function! autocmds#should_cursorline() abort
- return index(g:WincentCursorlineBlacklist, &filetype) == -1
- endfunction
- function! autocmds#should_mkview() abort
- return
- \ &buftype ==# '' &&
- \ index(g:WincentMkviewFiletypeBlacklist, &filetype) == -1 &&
- \ !exists('$SUDO_USER') " Don't create root-owned files.
- endfunction
- function! autocmds#mkview() abort
- try
- if exists('*haslocaldir') && haslocaldir()
- " We never want to save an :lcd command, so hack around it...
- cd -
- mkview
- lcd -
- else
- mkview
- endif
- catch /\<E186\>/
- " No previous directory: probably a `git` operation.
- catch /\<E190\>/
- " Could be name or path length exceeding NAME_MAX or PATH_MAX.
- endtry
- endfunction
- function! s:get_spell_settings() abort
- return {
- \ 'spell': &l:spell,
- \ 'spellcapcheck': &l:spellcapcheck,
- \ 'spellfile': &l:spellfile,
- \ 'spelllang': &l:spelllang
- \ }
- endfunction
- function! s:set_spell_settings(settings) abort
- let &l:spell=a:settings.spell
- let &l:spellcapcheck=a:settings.spellcapcheck
- let &l:spellfile=a:settings.spellfile
- let &l:spelllang=a:settings.spelllang
- endfunction
- function! autocmds#blur_window() abort
- if autocmds#should_colorcolumn()
- let l:settings=s:get_spell_settings()
- ownsyntax off
- set nolist
- if has('conceal')
- set conceallevel=0
- endif
- call s:set_spell_settings(l:settings)
- endif
- endfunction
- function! autocmds#focus_window() abort
- if autocmds#should_colorcolumn()
- if !empty(&ft)
- let l:settings=s:get_spell_settings()
- ownsyntax on
- set list
- let l:conceal_exclusions=get(g:, 'indentLine_fileTypeExclude', [])
- if has('conceal') && index(l:conceal_exclusions, &ft) == -1
- set conceallevel=1
- endif
- call s:set_spell_settings(l:settings)
- endif
- endif
- endfunction
- function! autocmds#gutterpadding() abort
- let l:signcolumn=0
- if exists('+signcolumn')
- if &signcolumn == 'yes'
- let l:signcolumn=2
- elseif &signcolumn == 'auto'
- if exists('*execute')
- let l:signs=execute('sign place buffer=' .bufnr('$'))
- else
- let l:signs=''
- silent! redir => l:signs
- silent execute 'sign place buffer=' . bufnr('$')
- redir END
- end
- if match(l:signs, 'line=') != -1
- let l:signcolumn=2
- endif
- endif
- endif
- let l:minwidth=2
- let l:gutterWidth=max([strlen(line('$')) + 1, &numberwidth, l:minwidth]) + l:signcolumn
- let l:padding=repeat(' ', l:gutterWidth - 1)
- return l:padding
- endfunction
- function! autocmds#idleboot() abort
- " Make sure we automatically call autocmds#idleboot() only once.
- augroup WincentIdleboot
- autocmd!
- augroup END
- " Make sure we run deferred tasks exactly once.
- doautocmd User WincentDefer
- autocmd! User WincentDefer
- endfunction
- " Directories where we want to perform auto-encryption on save.
- let s:encrypted={}
- let s:encrypted[expand('~/code/ansible-configs')]='vendor/git-cipher/bin/git-cipher'
- let s:encrypted[expand('~/code/wincent')]='vendor/git-cipher/bin/git-cipher'
- " Update encryptable files after saving.
- function! autocmds#encrypt(file) abort
- let l:base=fnamemodify(a:file, ':h')
- let l:directories=keys(s:encrypted)
- for l:directory in l:directories
- if stridx(a:file, l:directory) == 0
- let l:encrypted=l:base . '/.' . fnamemodify(a:file, ':t') . '.encrypted'
- if filewritable(l:encrypted) == 1
- let l:executable=l:directory . '/' . s:encrypted[l:directory]
- if executable(l:executable)
- call system(
- \ fnamemodify(l:executable, ':S') .
- \ ' encrypt ' .
- \ shellescape(a:file)
- \ )
- endif
- endif
- break
- endif
- endfor
- endfunction
- " Filetypes that we might want to apply directory-specific overrides to.
- let s:wincent_override_filetypes=[
- \ 'bnd',
- \ 'conf',
- \ 'groovy',
- \ 'html',
- \ 'java',
- \ 'javascript',
- \ 'jproperties',
- \ 'json',
- \ 'jsp',
- \ 'ignore',
- \ 'npmbundler',
- \ 'scss',
- \ 'soy',
- \ 'tsx',
- \ 'typescript',
- \ 'xml'
- \ ]
- function! autocmds#format(motion) abort
- if has('ex_extra')
- let l:v=operator#user#visual_command_from_wise_name(a:motion)
- silent execute 'normal!' '`[' . l:v . '`]gq'
- '[,']retab!
- endif
- endfunction
- if has('autocmd')
- function! s:WincentAutocmds()
- augroup WincentAutocmds
- autocmd!
- autocmd VimResized * execute "normal! \<c-w>="
- " http://vim.wikia.com/wiki/Detect_window_creation_with_WinEnter
- autocmd VimEnter * autocmd WinEnter * let w:created=1
- autocmd VimEnter * let w:created=1
- " Disable paste mode on leaving insert mode.
- autocmd InsertLeave * set nopaste
- " Make current window more obvious by turning off/adjusting some features in non-current
- " windows.
- if exists('+winhighlight')
- autocmd BufEnter,FocusGained,VimEnter,WinEnter * set winhighlight=
- autocmd FocusLost,WinLeave * set winhighlight=CursorLineNr:LineNr,EndOfBuffer:ColorColumn,IncSearch:ColorColumn,Normal:ColorColumn,NormalNC:ColorColumn,SignColumn:ColorColumn
- endif
- autocmd InsertLeave,VimEnter,WinEnter * if autocmds#should_cursorline() | setlocal cursorline | endif
- autocmd InsertEnter,WinLeave * if autocmds#should_cursorline() | setlocal nocursorline | endif
- autocmd BufEnter,FocusGained,VimEnter,WinEnter * call autocmds#focus_window()
- autocmd FocusLost,WinLeave * call autocmds#blur_window()
- if has('mksession')
- " Save/restore folds and cursor position.
- autocmd BufWritePost,BufLeave,WinLeave ?* if autocmds#should_mkview() | call autocmds#mkview() | endif
- if has('folding')
- autocmd BufWinEnter ?* if autocmds#should_mkview() | silent! loadview | execute 'silent! ' . line('.') . 'foldopen!' | endif
- else
- autocmd BufWinEnter ?* if autocmds#should_mkview() | silent! loadview | endif
- endif
- elseif has('folding')
- " Like the autocmd described in `:h last-position-jump` but we add `:foldopen!`.
- autocmd BufWinEnter * if line("'\"") > 1 && line("'\"") <= line('$') | execute "normal! g`\"" | execute 'silent! ' . line("'\"") . 'foldopen!' | endif
- else
- autocmd BufWinEnter * if line("'\"") > 1 && line("'\"") <= line('$') | execute "normal! g`\"" | endif
- endif
- autocmd BufWritePost */spell/*.add silent! :mkspell! %
- autocmd BufWritePost * call autocmds#encrypt(expand('<afile>:p'))
- augroup END
- endfunction
- call s:WincentAutocmds()
- " Wait until idle to run additional "boot" commands.
- augroup WincentIdleboot
- autocmd!
- if has('vim_starting')
- autocmd CursorHold,CursorHoldI * call autocmds#idleboot()
- endif
- augroup END
- "
- " Goyo
- "
- let s:settings={}
- function! s:goyo_enter()
- augroup WincentAutocmds
- autocmd!
- augroup END
- augroup! WincentAutocmds
- augroup WincentAutocolor
- autocmd!
- augroup END
- augroup! WincentAutocolor
- let s:settings = {
- \ 'showbreak': &showbreak,
- \ 'cursorline': &cursorline,
- \ 'showmode': &showmode
- \ }
- set showbreak=
- set nocursorline
- set noshowmode
- highlight! NonText ctermbg=bg ctermfg=bg guibg=bg guifg=bg
- if exists('$TMUX')
- silent !tmux set status off
- endif
- let b:quitting=0
- let b:quitting_bang=0
- if has('patch-7.3.544')
- autocmd QuitPre <buffer> let b:quitting=1
- cabbrev <buffer> q! let b:quitting_bang = 1 <bar> q!
- endif
- endfunction
- function! s:goyo_leave()
- let l:is_last_buffer=len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1
- if b:quitting && l:is_last_buffer
- if b:quitting_bang
- qa!
- else
- qa
- endif
- endif
- for [k, v] in items(s:settings)
- execute 'let &' . k . '=' . string(v)
- endfor
- highlight clear NonText
- highlight link NonText Conceal
- if exists('$TMUX')
- silent !tmux set status on
- endif
- call s:WincentAutocmds()
- endfunction
- autocmd! User GoyoEnter nested call <SID>goyo_enter()
- autocmd! User GoyoLeave nested call <SID>goyo_leave()
- endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement