~gpanders/dotfiles

f87729cffb28c3569026dd25698a1356fc86c8b9 — Greg Anders 2 years ago 17302f4
Add autoformat plugin and touch up some ftplugins

Remove 'if &filetype' guards from ftplugins -- at worst they prevent
ftplugin "chaining" (e.g. the liquid ftplugin sources the html ftplugin)
and at best they.... don't really do anything.
M vim/.vim/after/ftplugin/c.vim => vim/.vim/after/ftplugin/c.vim +0 -4
@@ 1,10 1,6 @@
" C filetype plugin
" Author: Greg Anders <greg@gpanders.com>

if &filetype !=# 'c' && &filetype !=# 'cpp'
  finish
endif

" Set comment string
setlocal commentstring=//%s


M vim/.vim/after/ftplugin/cpp.vim => vim/.vim/after/ftplugin/cpp.vim +0 -4
@@ 1,10 1,6 @@
" cpp filetype plugin
" Author: Greg Anders <greg@gpanders.com>

if &filetype !=# 'cpp'
  finish
endif

if isdirectory('/Library/Developer/CommandLineTools')
  let &l:path = glob('/Library/Developer/CommandLineTools/usr/include/c++/*') . ',' . &path
endif

M vim/.vim/after/ftplugin/crontab.vim => vim/.vim/after/ftplugin/crontab.vim +0 -4
@@ 1,8 1,4 @@
" crontab
if &filetype !=# 'crontab'
  finish
endif

setlocal nobackup
setlocal nowritebackup


M vim/.vim/after/ftplugin/css.vim => vim/.vim/after/ftplugin/css.vim +1 -18
@@ 1,29 1,12 @@
" css filetype plugin
" Author: Greg Anders <greg@gpanders.com>

if &filetype !=# 'css'
  finish
endif

let b:undo_ftplugin = get(b:, 'undo_ftplugin', '')

let g:css_format_on_write = 1

if executable('prettier')
  setlocal formatprg=prettier\ %
  setlocal formatprg=prettier\ --parser\ css
endif

if !empty(&l:formatprg)
  let b:undo_ftplugin .= '|setl fp<'
  augroup ftplugin.css
    autocmd!
    autocmd BufWritePre <buffer>
          \ if g:css_format_on_write |
          \   let view = winsaveview() |
          \   execute '%!' . &l:formatprg |
          \   call winrestview(view) |
          \   unlet view |
          \ endif
  augroup END
  let b:undo_ftplugin .= '|exe "au! ftplugin.css * <buffer>"'
endif

M vim/.vim/after/ftplugin/gitcommit.vim => vim/.vim/after/ftplugin/gitcommit.vim +0 -4
@@ 1,10 1,6 @@
" git commit filetype plugin
" Author: Greg Anders <greg@gpanders.com>

if &filetype !=# 'gitcommit'
  finish
endif

" enable spell check
setlocal spell
setlocal textwidth=72

M vim/.vim/after/ftplugin/help.vim => vim/.vim/after/ftplugin/help.vim +0 -4
@@ 1,10 1,6 @@
" help filetype plugin
" Author: Greg Anders <greg@gpanders.com>

if &filetype !=# 'help' || !&readonly
  finish
endif

noremap <silent> <buffer> <CR> g<C-]>
noremap <silent> <buffer> <C-J> /<Bar>\S\{-}<Bar><CR>:nohlsearch<CR>
noremap <silent> <buffer> <C-K> ?<Bar>\S\{-}<Bar><CR>:nohlsearch<CR>

M vim/.vim/after/ftplugin/html.vim => vim/.vim/after/ftplugin/html.vim +8 -2
@@ 1,6 1,12 @@
" html filetype plugin
" Author: Greg Anders <greg@gpanders.com>

if &filetype !=# 'html'
  finish
let b:undo_ftplugin = get(b:, 'undo_ftplugin', '')

if executable('prettier')
  setlocal formatprg=prettier\ --parser\ html
endif

if !empty(&l:formatprg)
  let b:undo_ftplugin .= '|setl fp<'
endif

M vim/.vim/after/ftplugin/mail.vim => vim/.vim/after/ftplugin/mail.vim +0 -4
@@ 2,10 2,6 @@
" Author: Greg Anders
" Date: 2018-12-02

if &filetype !=# 'mail'
  finish
endif

setlocal formatoptions+=wa
setlocal wrapmargin=0
setlocal nonumber

M vim/.vim/after/ftplugin/man.vim => vim/.vim/after/ftplugin/man.vim +0 -4
@@ 1,10 1,6 @@
" man filetype plugin
" Author: Greg Anders <greg@gpanders.com>

if &filetype !=# 'man'
  finish
endif

nnoremap <buffer> <silent> <C-J> /\C\%>1l\f\+([1-9][a-z]\=)\ze\_.\+\%$<CR>:<C-U>nohlsearch<CR>
nnoremap <buffer> <silent> <C-K> ?\C\%>1l\f\+([1-9][a-z]\=)\ze\_.\+\%$<CR>:<C-U>nohlsearch<CR>


M vim/.vim/after/ftplugin/markdown.vim => vim/.vim/after/ftplugin/markdown.vim +0 -4
@@ 1,10 1,6 @@
" Markdown filetype plugin
" Author: Greg Anders <greg@gpanders.com>

if &filetype !=# 'markdown'
  finish
endif

compiler pandoc

setlocal textwidth=80

M vim/.vim/after/ftplugin/python.vim => vim/.vim/after/ftplugin/python.vim +0 -4
@@ 1,8 1,4 @@
" Python specific settings
if &filetype !=# 'python'
  finish
endif

let b:undo_ftplugin = get(b:, 'undo_ftplugin', '')

" If a valid formatter executable is found, autoformat the buffer when writing

M vim/.vim/after/ftplugin/qf.vim => vim/.vim/after/ftplugin/qf.vim +0 -4
@@ 1,5 1,1 @@
if &filetype !=# 'qf'
  finish
endif

nnoremap <silent> <buffer> q :q<CR>

M vim/.vim/after/ftplugin/rust.vim => vim/.vim/after/ftplugin/rust.vim +0 -4
@@ 1,8 1,4 @@
" Rust
if &filetype !=# 'rust'
  finish
endif

if executable('rustfmt')
  setl formatprg=rustfmt


M vim/.vim/after/ftplugin/sh.vim => vim/.vim/after/ftplugin/sh.vim +0 -4
@@ 1,8 1,4 @@
" Sh
if &filetype !=# 'sh'
  finish
endif

" Z! execute line as shell command
" Inspired by the Shdo buffers from vim-dirvish
nnoremap <buffer> Z! ^"zyg_:!<C-R>z<CR>

M vim/.vim/after/ftplugin/tags.vim => vim/.vim/after/ftplugin/tags.vim +3 -5
@@ 1,10 1,9 @@
" tags filetype plugin
" Author: Greg Anders <greg@gpanders.com>

if &filetype !=# 'tags'
  finish
endif
let b:undo_ftplugin = get(b:, 'undo_ftplugin', '')

setlocal tabstop=99
setlocal nomodifiable

" Jump to tag on current line


@@ 13,5 12,4 @@ nnoremap <buffer> <CR> 0:tag <C-R><C-W><CR>
" Open tag on current line in preview window
nnoremap <buffer> p 0<C-W>}

let b:undo_ftplugin = get(b:, 'undo_ftplugin', '')
let b:undo_ftplugin .= '|setl ma<|unm <buffer> <CR>'
let b:undo_ftplugin .= '|setl ts< ma<|unm <buffer> <CR>'

M vim/.vim/after/ftplugin/tex.vim => vim/.vim/after/ftplugin/tex.vim +0 -4
@@ 1,8 1,4 @@
" LaTeX
if &filetype !=# 'tex'
  finish
endif

let g:tex_flavor = 'latex'

setlocal nocursorline

M vim/.vim/after/ftplugin/vhdl.vim => vim/.vim/after/ftplugin/vhdl.vim +0 -4
@@ 1,10 1,6 @@
" VHDL filetype plugin
" Author: Greg Anders <greg@gpanders.com>

if &filetype !=# 'vhdl'
  finish
endif

setlocal commentstring=--%s
setlocal tagcase=ignore


M vim/.vim/after/ftplugin/vim.vim => vim/.vim/after/ftplugin/vim.vim +0 -4
@@ 1,8 1,4 @@
" Vim
if &filetype !=# 'vim'
  finish
endif

setlocal foldmethod=marker

" Z: execute current line or visually selected region in command mode

M vim/.vim/after/ftplugin/vimwiki.vim => vim/.vim/after/ftplugin/vimwiki.vim +0 -5
@@ 1,12 1,7 @@
" Vimwiki
if &filetype !=# 'vimwiki'
  finish
endif

setlocal textwidth=80
setlocal spell
setlocal complete+=k
setlocal concealcursor=nc

let b:undo_ftplugin = 'setl tw< spell< cpt<'


M vim/.vim/after/ftplugin/xxd.vim => vim/.vim/after/ftplugin/xxd.vim +0 -4
@@ 2,10 2,6 @@
" Author: Greg Anders <greg@gpanders.com>
" Written: 24 Dec 2018

if &filetype !=# 'xxd'
  finish
endif

normal! 11|

" Number of bytes per line. xxd default is 16

M vim/.vim/after/ftplugin/yaml.vim => vim/.vim/after/ftplugin/yaml.vim +7 -5
@@ 1,11 1,13 @@
" yaml filetype plugin
" Author: Greg Anders <greg@gpanders.com>

if &filetype !=# 'yaml'
  finish
endif
let b:undo_ftplugin = get(b:, 'undo_ftplugin', '')

setl textwidth=80
setlocal textwidth=80

let b:undo_ftplugin = get(b:, 'undo_ftplugin', '')
let b:undo_ftplugin .= '|setl tw<'

if executable('prettier')
  setlocal formatprg=prettier\ --parser\ yaml
  let b:undo_ftplugin .= ' fp<'
endif

M vim/.vim/after/ftplugin/zsh.vim => vim/.vim/after/ftplugin/zsh.vim +0 -4
@@ 1,10 1,6 @@
" zsh filetype plugin
" Author: Greg Anders <greg@gpanders.com>

if &filetype !=# 'zsh'
  finish
endif

let b:undo_ftplugin = get(b:, 'undo_ftplugin', '')

" Z! execute line as shell command

A vim/.vim/after/plugin/autoformat.vim => vim/.vim/after/plugin/autoformat.vim +13 -0
@@ 0,0 1,13 @@
" autoformat configuration
" Author: Greg Anders <greg@gpanders.com>
" Date: 2019-04-03

if !exists('g:loaded_autoformat')
  finish
endif

let g:autoformat_filetypes = [
      \ 'liquid',
      \ 'html',
      \ 'css',
      \ ]

M vim/.vim/after/plugin/projectionist/vim.vim => vim/.vim/after/plugin/projectionist/vim.vim +2 -2
@@ 23,11 23,11 @@ call extend(g:projectionist_heuristics, {
      \   },
      \   'ftplugin/*.vim': {
      \     'type': 'ftplugin',
      \     'template': ['" {} filetype plugin', '" Author: Greg Anders <greg@gpanders.com>', '', 'if &filetype !=# ''{}''', "\tfinish", 'endif']
      \     'template': ['" {} filetype plugin', '" Author: Greg Anders <greg@gpanders.com>', '', 'let b:undo_ftplugin = get(b:, ''undo_ftplugin'')', '']
      \   },
      \   'after/ftplugin/*.vim': {
      \     'type': 'ftplugin',
      \     'template': ['" {} filetype plugin', '" Author: Greg Anders <greg@gpanders.com>', '', 'if &filetype !=# ''{}''', "\tfinish", 'endif']
      \     'template': ['" {} filetype plugin', '" Author: Greg Anders <greg@gpanders.com>', '', 'let b:undo_ftplugin = get(b:, ''undo_ftplugin'')', '']
      \   },
      \   'compiler/*.vim': {
      \     'type': 'compiler',

A vim/.vim/plugin/autoformat.vim => vim/.vim/plugin/autoformat.vim +23 -0
@@ 0,0 1,23 @@
" Auto format files on write
" Author: Greg Anders <greg@gpanders.com>
" Date: 2019-04-03

if exists('g:loaded_autoformat')
  finish
endif
let g:loaded_autoformat = 1

if !exists('g:autoformat_filetypes')
  let g:autoformat_filetypes = []
endif

augroup plugin.autoformat
  autocmd!
  autocmd BufWritePre *
        \ if !empty(&l:formatprg) && index(g:autoformat_filetypes, &ft) > -1 |
        \   let view = winsaveview() |
        \   execute '%!' . &l:formatprg |
        \   call winrestview(view) |
        \   unlet view |
        \ endif
augroup END

M vim/.vim/plugin/vimwiki/vimwiki.vim => vim/.vim/plugin/vimwiki/vimwiki.vim +1 -1
@@ 16,7 16,7 @@ let g:vimwiki_conceal_pre = 1
" Extend wikis with default values
if !empty(get(g:, 'vimwiki_list', []))
  function! s:extend(index, wiki)
    if get(a:wiki, 'syntax', '') ==# 'markdown'
    if get(a:wiki, 'syntax') ==# 'markdown'
      " Settings for markdown wikis
      call extend(a:wiki, {
            \ 'ext': '.md',