~gpanders/dotfiles

ref: fe3c3c6d5c840bb713a7160d9c2d0b7f5885ea99 dotfiles/vim/.vim/after/ftplugin/css.vim -rw-r--r-- 673 bytes
fe3c3c6dGreg Anders Clean up plugins and use more consistent conventions 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
" 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\ %
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