~gpanders/dotfiles

e4a6a31961dc29c136be3bf6d2c2f3bd44058989 — Greg Anders 2 years ago 43959b4
Improve and cleanup filetype plugins

* Combine C and C++ filetypes - having both was entirely redundant
* Add a tags ftplugin to make tags files act like tags browsers
* Add a few new projections for Cmake and C-family files
* Add a few new mappings:
  - <Space>t for :tags
  - <Space>r for :registers
  - <Space>m for :marks
  - <Space>M for :marks ABCDE...wxyz
M vim/.vim/after/ftplugin/c.vim => vim/.vim/after/ftplugin/c.vim +12 -11
@@ 1,5 1,7 @@
" C
if &filetype !=# 'c'
" C filetype plugin
" Author: Greg Anders <greg@gpanders.com>

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



@@ 12,19 14,18 @@ setlocal complete+=i,d
" Set include pattern
setlocal include=^\\s*#\\s*include

" Use improved :Man command as keywordprg
setlocal keywordprg=:Man

" Include headers on Unix
if has('unix')
  if get(g:, 'os', '') ==# 'Darwin'
    setlocal path+=/usr/local/opt/llvm/include/c++/v1
  else
    setlocal path+=/usr/include
  endif
  setlocal path=.,/usr/local/include,/usr/include,,
endif

let b:undo_ftplugin .= '|setl cms< cpt< inc< path< kp<'
let b:undo_ftplugin .= '|setl cms< cpt< inc< path<'

" Use improved :Man command as keywordprg
if exists(':Man')
  setlocal keywordprg=:Man
  let b:undo_ftplugin .= ' kp<'
endif

if executable('clang-format')
  setlocal formatprg=clang-format

D vim/.vim/after/ftplugin/cpp.vim => vim/.vim/after/ftplugin/cpp.vim +0 -35
@@ 1,35 0,0 @@
" C++ filetype plugin
" Author: Greg Anders <greg@gpanders.com>

if &filetype !=# 'cpp'
  finish
endif

" Set comment string
setlocal commentstring=//%s

" Include macros in completion
setlocal complete+=i,d

" Set include pattern
setlocal include=^\\s*#\\s*include

" Use improved :Man command as keywordprg
setlocal keywordprg=:Man

" Include headers on Unix
if has('unix')
  if get(g:, 'os', '') ==# 'Darwin'
    setlocal path+=/usr/local/opt/llvm/include/c++/v1
  else
    setlocal path+=/usr/include
  endif
endif

let b:undo_ftplugin .= '|setl cms< cpt< inc< path< kp<'

if executable('clang-format')
  setlocal formatprg=clang-format
  let b:undo_ftplugin .= ' fp<'
endif


M vim/.vim/after/ftplugin/python.vim => vim/.vim/after/ftplugin/python.vim +3 -0
@@ 13,6 13,9 @@ nmap <buffer> gz <Plug>(PytermOpen)
" Don't complete from include files (there are too many!)
setlocal complete-=i

" Use flake8 as makeprg for linting
compiler flake8

" Show boundary at 80 characters
let &l:colorcolumn = join(range(80, 336), ',')


A vim/.vim/after/ftplugin/tags.vim => vim/.vim/after/ftplugin/tags.vim +17 -0
@@ 0,0 1,17 @@
" tags filetype plugin
" Author: Greg Anders <greg@gpanders.com>

if &filetype !=# 'tags'
  finish
endif

setlocal nomodifiable

" Jump to tag on current line
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>'

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

if &filetype !=# 'vhdl'
  finish
endif

setl commentstring=--%s
setlocal commentstring=--%s
setlocal tagcase=ignore

" VHDL is case insensitive
setlocal ignorecase
setlocal nosmartcase

if executable('ghdl')
  compiler ghdl
endif

let b:undo_ftplugin = 'setl cms<'
let b:undo_ftplugin = 'setl cms< tc< ic< scs<'

M vim/.vim/after/plugin/dispatch.vim => vim/.vim/after/plugin/dispatch.vim +1 -1
@@ 21,7 21,7 @@ augroup Dispatch
  autocmd FileType c,cpp let b:dispatch = 'clang-tidy -quiet %:S'

  " Python
  autocmd FileType python let b:dispatch = 'pylint -f parseable -s no -- %:S'
  autocmd FileType python let b:dispatch = 'pytest --tb=short -q'

  " TeX
  autocmd FileType tex let b:dispatch = 'chktex -q -v0 -- %:S'

M vim/.vim/after/plugin/projectionist.vim => vim/.vim/after/plugin/projectionist.vim +10 -0
@@ 45,4 45,14 @@ let g:projectionist_heuristics = {
      \   'after/compiler/*.vim': {
      \     'type': 'compiler',
      \   }
      \ },
      \ 'CMakeLists.txt&build/': {
      \   '*': { 'dispatch': '-dir=build -- make -f build/Makefile' },
      \ },
      \ 'include/': {
      \   '*.h':   { 'path': 'include' },
      \   '*.hpp': { 'path': 'include' },
      \   '*.c':   { 'path': 'include' },
      \   '*.cc':  { 'path': 'include' },
      \   '*.cpp': { 'path': 'include' },
      \ }}

M vim/.vim/plugin/minpac.vim => vim/.vim/plugin/minpac.vim +1 -0
@@ 73,6 73,7 @@ function! s:PackInit()
    " Language specific
    " Python
    call minpac#add('davidhalter/jedi-vim')
    call minpac#add('drgarcia1986/python-compilers.vim')

    " LaTeX
    call minpac#add('lervag/vimtex')

A vim/.vim/plugin/polyglot.vim => vim/.vim/plugin/polyglot.vim +9 -0
@@ 0,0 1,9 @@
" vim-polyglot configuration
" This file is executed BEFORE vim-polyglot is loaded
" Author: Greg Anders <greg@gpanders.com>
" Date: 2019-03-06

" Disable things
let g:polyglot_disabled = [
      \ 'python-compiler',
      \ ]

M vim/.vim/vimrc => vim/.vim/vimrc +25 -4
@@ 207,6 207,7 @@ set smarttab
set softtabstop=4
set splitbelow
set splitright
set tagcase=smart
set virtualedit+=block

" Enable undofile if possible


@@ 435,15 436,35 @@ nnoremap <silent> <C-L> :<C-U>nohlsearch<Bar>diffupdate<CR><C-L>
vnoremap <silent> <C-L> :<C-U>nohlsearch<Bar>diffupdate<CR>gv<C-L>

" \c changes directory to current buffer's directory
nnoremap <silent> \c :<C-U>cd %:h<Bar>echo 'Changed directory to ' . getcwd()<CR>
nnoremap <silent> \c :cd %:p:h<Bar>echo 'Changed directory to ' . getcwd()<CR>

" ,c changes local buffer directory to project directory (if the buffer is in
" a recognized Projectionist project) or the current buffer's directory
nnoremap <expr> ,c ":" . (exists(":Plcd")?"Plcd":"lcd %:h") . "\<Bar>echo 'Changed directory of current window to ' . getcwd()\<CR>"
" ,c changes local working directory to buffer's directory
nnoremap <silent> ,c :lcd %:p:h<Bar>echo 'Changed directory to ' . getcwd()<CR>

" Format whole buffer with formatprg without changing cursor position
nnoremap <Space>gq mzHmygggqG`yzt`z

" Show tag stack
nnoremap <Space>t :tags<CR>

" Navigate through tag stack
nnoremap <expr> >t ":\<C-U>" . (v:count ? v:count : '') . "tag\<CR>"

" This is the same as CTRL-T, but it's nice to have symmetry
nnoremap <expr> <t ":\<C-U>" . (v:count ? v:count : '') . "pop\<CR>"

" Show registers
nnoremap <Space>r :registers<CR>

" Show marks
nnoremap <Space>m :marks<CR>:norm! `

" Show only user placed marks (A-Z and a-z)
let alphabet = join(map(
      \ range(char2nr('A'), char2nr('Z')) + range(char2nr('a'), char2nr('z')),
      \ 'nr2char(v:val)'), '')
execute 'nnoremap <Space>M :marks ' . alphabet . '<CR>'

" }}}

" Visual mode mappings {{{