Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2019
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 9.51 KB | None | 0 0
  1.   let g:WincentColorColumnBufferNameBlacklist = ['__LanguageClient__']
  2.   let g:WincentColorColumnFileTypeBlacklist = ['command-t', 'diff', 'fugitiveblame', 'undotree', 'nerdtree', 'qf']
  3.   let g:WincentCursorlineBlacklist = ['command-t']
  4.   let g:WincentMkviewFiletypeBlacklist = ['diff', 'hgcommit', 'gitcommit']
  5.  
  6.   function! autocmds#attempt_select_last_file() abort
  7.     let l:previous=expand('#:t')
  8.     if l:previous !=# ''
  9.       call search('\v<' . l:previous . '>')
  10.     endif
  11.   endfunction
  12.  
  13.    function! autocmds#should_colorcolumn() abort
  14.      if index(g:WincentColorColumnBufferNameBlacklist, bufname(bufnr('%'))) != -1
  15.        return 0
  16.      endif
  17.      return index(g:WincentColorColumnFileTypeBlacklist, &filetype) == -1
  18.    endfunction
  19.  
  20.   function! autocmds#should_cursorline() abort
  21.     return index(g:WincentCursorlineBlacklist, &filetype) == -1
  22.   endfunction
  23.  
  24.   function! autocmds#should_mkview() abort
  25.     return
  26.           \ &buftype ==# '' &&
  27.           \ index(g:WincentMkviewFiletypeBlacklist, &filetype) == -1 &&
  28.           \ !exists('$SUDO_USER') " Don't create root-owned files.
  29.   endfunction
  30.  
  31.   function! autocmds#mkview() abort
  32.     try
  33.       if exists('*haslocaldir') && haslocaldir()
  34.         " We never want to save an :lcd command, so hack around it...
  35.         cd -
  36.         mkview
  37.         lcd -
  38.       else
  39.         mkview
  40.       endif
  41.     catch /\<E186\>/
  42.       " No previous directory: probably a `git` operation.
  43.     catch /\<E190\>/
  44.       " Could be name or path length exceeding NAME_MAX or PATH_MAX.
  45.     endtry
  46.   endfunction
  47.  
  48.   function! s:get_spell_settings() abort
  49.     return {
  50.           \   'spell': &l:spell,
  51.           \   'spellcapcheck': &l:spellcapcheck,
  52.           \   'spellfile': &l:spellfile,
  53.           \   'spelllang': &l:spelllang
  54.           \ }
  55.   endfunction
  56.  
  57.   function! s:set_spell_settings(settings) abort
  58.     let &l:spell=a:settings.spell
  59.     let &l:spellcapcheck=a:settings.spellcapcheck
  60.     let &l:spellfile=a:settings.spellfile
  61.     let &l:spelllang=a:settings.spelllang
  62.   endfunction
  63.  
  64.  function! autocmds#blur_window() abort
  65.    if autocmds#should_colorcolumn()
  66.      let l:settings=s:get_spell_settings()
  67.      ownsyntax off
  68.      set nolist
  69.      if has('conceal')
  70.        set conceallevel=0
  71.      endif
  72.      call s:set_spell_settings(l:settings)
  73.    endif
  74.  endfunction
  75.  
  76.  function! autocmds#focus_window() abort
  77.    if autocmds#should_colorcolumn()
  78.      if !empty(&ft)
  79.        let l:settings=s:get_spell_settings()
  80.        ownsyntax on
  81.        set list
  82.        let l:conceal_exclusions=get(g:, 'indentLine_fileTypeExclude', [])
  83.        if has('conceal') && index(l:conceal_exclusions, &ft) == -1
  84.          set conceallevel=1
  85.        endif
  86.        call s:set_spell_settings(l:settings)
  87.      endif
  88.    endif
  89.  endfunction
  90.  
  91.   function! autocmds#gutterpadding() abort
  92.     let l:signcolumn=0
  93.     if exists('+signcolumn')
  94.       if &signcolumn == 'yes'
  95.         let l:signcolumn=2
  96.       elseif &signcolumn == 'auto'
  97.         if exists('*execute')
  98.           let l:signs=execute('sign place buffer=' .bufnr('$'))
  99.         else
  100.           let l:signs=''
  101.           silent! redir => l:signs
  102.           silent execute 'sign place buffer=' . bufnr('$')
  103.           redir END
  104.         end
  105.         if match(l:signs, 'line=') != -1
  106.           let l:signcolumn=2
  107.         endif
  108.       endif
  109.     endif
  110.  
  111.     let l:minwidth=2
  112.     let l:gutterWidth=max([strlen(line('$')) + 1, &numberwidth, l:minwidth]) + l:signcolumn
  113.     let l:padding=repeat(' ', l:gutterWidth - 1)
  114.     return l:padding
  115.   endfunction
  116.  
  117.   function! autocmds#idleboot() abort
  118.     " Make sure we automatically call autocmds#idleboot() only once.
  119.     augroup WincentIdleboot
  120.       autocmd!
  121.     augroup END
  122.  
  123.     " Make sure we run deferred tasks exactly once.
  124.     doautocmd User WincentDefer
  125.     autocmd! User WincentDefer
  126.   endfunction
  127.  
  128.   " Directories where we want to perform auto-encryption on save.
  129.   let s:encrypted={}
  130.   let s:encrypted[expand('~/code/ansible-configs')]='vendor/git-cipher/bin/git-cipher'
  131.   let s:encrypted[expand('~/code/wincent')]='vendor/git-cipher/bin/git-cipher'
  132.  
  133.   " Update encryptable files after saving.
  134.   function! autocmds#encrypt(file) abort
  135.     let l:base=fnamemodify(a:file, ':h')
  136.     let l:directories=keys(s:encrypted)
  137.     for l:directory in l:directories
  138.       if stridx(a:file, l:directory) == 0
  139.         let l:encrypted=l:base . '/.' . fnamemodify(a:file, ':t') . '.encrypted'
  140.         if filewritable(l:encrypted) == 1
  141.           let l:executable=l:directory . '/' . s:encrypted[l:directory]
  142.           if executable(l:executable)
  143.             call system(
  144.                   \   fnamemodify(l:executable, ':S') .
  145.                   \   ' encrypt ' .
  146.                   \   shellescape(a:file)
  147.                   \ )
  148.           endif
  149.         endif
  150.         break
  151.       endif
  152.     endfor
  153.   endfunction
  154.  
  155.  " Filetypes that we might want to apply directory-specific overrides to.
  156.  let s:wincent_override_filetypes=[
  157.        \   'bnd',
  158.        \   'conf',
  159.        \   'groovy',
  160.        \   'html',
  161.        \   'java',
  162.        \   'javascript',
  163.        \   'jproperties',
  164.        \   'json',
  165.        \   'jsp',
  166.        \   'ignore',
  167.        \   'npmbundler',
  168.        \   'scss',
  169.        \   'soy',
  170.        \   'tsx',
  171.        \   'typescript',
  172.        \   'xml'
  173.        \ ]
  174.  
  175.  
  176.  function! autocmds#format(motion) abort
  177.    if has('ex_extra')
  178.      let l:v=operator#user#visual_command_from_wise_name(a:motion)
  179.      silent execute 'normal!' '`[' . l:v . '`]gq'
  180.      '[,']retab!
  181.    endif
  182.  endfunction
  183.  
  184.  if has('autocmd')
  185.    function! s:WincentAutocmds()
  186.      augroup WincentAutocmds
  187.        autocmd!
  188.  
  189.        autocmd VimResized * execute "normal! \<c-w>="
  190.  
  191.        " http://vim.wikia.com/wiki/Detect_window_creation_with_WinEnter
  192.        autocmd VimEnter * autocmd WinEnter * let w:created=1
  193.        autocmd VimEnter * let w:created=1
  194.  
  195.        " Disable paste mode on leaving insert mode.
  196.        autocmd InsertLeave * set nopaste
  197.  
  198.        " Make current window more obvious by turning off/adjusting some features in non-current
  199.        " windows.
  200.        if exists('+winhighlight')
  201.          autocmd BufEnter,FocusGained,VimEnter,WinEnter * set winhighlight=
  202.          autocmd FocusLost,WinLeave * set winhighlight=CursorLineNr:LineNr,EndOfBuffer:ColorColumn,IncSearch:ColorColumn,Normal:ColorColumn,NormalNC:ColorColumn,SignColumn:ColorColumn
  203.        endif
  204.        autocmd InsertLeave,VimEnter,WinEnter * if autocmds#should_cursorline() | setlocal cursorline | endif
  205.        autocmd InsertEnter,WinLeave * if autocmds#should_cursorline() | setlocal nocursorline | endif
  206.        autocmd BufEnter,FocusGained,VimEnter,WinEnter * call autocmds#focus_window()
  207.        autocmd FocusLost,WinLeave * call autocmds#blur_window()
  208.  
  209.        if has('mksession')
  210.          " Save/restore folds and cursor position.
  211.          autocmd BufWritePost,BufLeave,WinLeave ?* if autocmds#should_mkview() | call autocmds#mkview() | endif
  212.          if has('folding')
  213.            autocmd BufWinEnter ?* if autocmds#should_mkview() | silent! loadview | execute 'silent! ' . line('.') . 'foldopen!' | endif
  214.          else
  215.            autocmd BufWinEnter ?* if autocmds#should_mkview() | silent! loadview | endif
  216.          endif
  217.        elseif has('folding')
  218.          " Like the autocmd described in `:h last-position-jump` but we add `:foldopen!`.
  219.          autocmd BufWinEnter * if line("'\"") > 1 && line("'\"") <= line('$') | execute "normal! g`\"" | execute 'silent! ' . line("'\"") . 'foldopen!' | endif
  220.        else
  221.          autocmd BufWinEnter * if line("'\"") > 1 && line("'\"") <= line('$') | execute "normal! g`\"" | endif
  222.        endif
  223.  
  224.        autocmd BufWritePost */spell/*.add silent! :mkspell! %
  225.  
  226.        autocmd BufWritePost * call autocmds#encrypt(expand('<afile>:p'))
  227.  
  228.      augroup END
  229.    endfunction
  230.  
  231.    call s:WincentAutocmds()
  232.  
  233.    " Wait until idle to run additional "boot" commands.
  234.    augroup WincentIdleboot
  235.      autocmd!
  236.      if has('vim_starting')
  237.        autocmd CursorHold,CursorHoldI * call autocmds#idleboot()
  238.      endif
  239.    augroup END
  240.  
  241.  
  242.    "
  243.    " Goyo
  244.    "
  245.  
  246.    let s:settings={}
  247.  
  248.    function! s:goyo_enter()
  249.      augroup WincentAutocmds
  250.        autocmd!
  251.      augroup END
  252.      augroup! WincentAutocmds
  253.  
  254.      augroup WincentAutocolor
  255.        autocmd!
  256.      augroup END
  257.      augroup! WincentAutocolor
  258.  
  259.      let s:settings = {
  260.            \   'showbreak': &showbreak,
  261.            \   'cursorline': &cursorline,
  262.            \   'showmode': &showmode
  263.            \ }
  264.  
  265.      set showbreak=
  266.      set nocursorline
  267.      set noshowmode
  268.  
  269.      highlight! NonText ctermbg=bg ctermfg=bg guibg=bg guifg=bg
  270.  
  271.      if exists('$TMUX')
  272.        silent !tmux set status off
  273.      endif
  274.  
  275.      let b:quitting=0
  276.      let b:quitting_bang=0
  277.      if has('patch-7.3.544')
  278.        autocmd QuitPre <buffer> let b:quitting=1
  279.        cabbrev <buffer> q! let b:quitting_bang = 1 <bar> q!
  280.      endif
  281.    endfunction
  282.  
  283.    function! s:goyo_leave()
  284.      let l:is_last_buffer=len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1
  285.      if b:quitting && l:is_last_buffer
  286.        if b:quitting_bang
  287.          qa!
  288.        else
  289.          qa
  290.        endif
  291.      endif
  292.  
  293.      for [k, v] in items(s:settings)
  294.        execute 'let &' . k . '=' . string(v)
  295.      endfor
  296.  
  297.      highlight clear NonText
  298.      highlight link NonText Conceal
  299.  
  300.      if exists('$TMUX')
  301.        silent !tmux set status on
  302.      endif
  303.  
  304.      call s:WincentAutocmds()
  305.    endfunction
  306.  
  307.    autocmd! User GoyoEnter nested call <SID>goyo_enter()
  308.    autocmd! User GoyoLeave nested call <SID>goyo_leave()
  309.  endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement