~gpanders/dotfiles

7d07e36224780c10a92b8ae354b4fc9e00d613c8 — Greg Anders 1 year, 10 months ago 060c7c1
Variety of vim changes/improvements

- Add go ftplugin
- Fix bug in fzy#tags() function
- Ensure LSP command actually exists in ALE LSP buffers
- Update Scratch command to work with external commands
A vim/.vim/after/ftplugin/go.vim => vim/.vim/after/ftplugin/go.vim +9 -0
@@ 0,0 1,9 @@
" go filetype plugin
" Author: Greg Anders <greg@gpanders.com>

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

if executable('gofmt')
    setlocal formatprg=gofmt
    let b:undo_ftplugin .= '|setl fp<'
endif

M vim/.vim/after/plugin/ale.vim => vim/.vim/after/plugin/ale.vim +5 -1
@@ 69,10 69,14 @@ if get(g:, 'ale_completion_enabled')
endif

function! s:lsp_setup()
    if empty(filter(ale#linter#Get(&filetype), {_, v -> !empty(v.lsp)}))
    let buf = bufnr('')
    let lsps = filter(ale#linter#Get(&filetype), {_, v -> 
                \ !empty(v.lsp) && ale#engine#IsExecutable(buf, ale#linter#GetExecutable(buf, v))})
    if empty(lsps)
        return
    endif

    let b:ale_lsp_enabled = 1
    setlocal omnifunc=ale#completion#OmniFunc
    nnoremap <buffer> <C-]> :<C-U>ALEGoToDefinition<CR>
    nnoremap <buffer> <C-W>] :<C-U>ALEGoToDefinitionInSplit<CR>

M vim/.vim/autoload/ft/markdown.vim => vim/.vim/autoload/ft/markdown.vim +1 -3
@@ 5,16 5,14 @@ function! ft#markdown#formatexpr()
        return 1
    endif

    let view = winsaveview()
    let range = v:lnum . ',' . (v:lnum + v:count - 1)
    exe range . '!' . &l:formatprg
    " Join wrapped links
    silent exe 'keepjumps keeppatterns ' . range . 'g/\[[^]]*$/.,/\%(\[.*\)\@<!]/j'
    " Convert *italics* (used by pandoc) to _italics_ (which I prefer)
    silent exe 'keepjumps keeppatterns ' . range . 's/\*\@<!\*\([^*]\+\)\*\*\@!/_\1_/ge'
    " Convert {.language} to just language
    " Convert ```{.language} to just ```language
    silent exe 'keepjumps keeppatterns ' . range . 's/[~`]\{3,}\zs\s*{\.\(\w\+\)}/\1/ge'
    call winrestview(view)
endfunction

function! ft#markdown#toc()

M vim/.vim/autoload/fzy.vim => vim/.vim/autoload/fzy.vim +1 -2
@@ 37,6 37,5 @@ function! fzy#tags()
    let tags = map(taglist('.'), {_, v -> printf('%-40s %-10s %s', v.name, v.kind, v.filename)})
    let file = tempname()
    call writefile(tags, file)
    call s:fzy('cat ' . file, {t -> execute('tag ' . split(t)[0])}, 'tags')
    call delete(file)
    call s:fzy('cat ' . file, {t -> execute('tag ' . split(t)[0]) && delete(file)}, 'tags')
endfunction

M vim/.vim/autoload/scratch.vim => vim/.vim/autoload/scratch.vim +15 -14
@@ 1,15 1,16 @@
function! scratch#open(command, ...)
  let lines = substitute(execute(a:command), '\n\zs\s*\d\+:\s*', '', 'g')
  new
  put =lines
  let b:lines = lines
  nnoremap <silent> <buffer> q <C-W>q
  if a:0
    execute 'vglobal/' . a:1 . '/delete'
  endif
  silent %substitute/\%^\_s*\n\|\_s*\%$
  let height = min([line('$'), 20])
  execute height . 'wincmd_'
  setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile
  0
" Source: https://gist.github.com/romainl/eae0a260ab9c135390c30cd370c20cd7
function! scratch#open(cmd) abort
    for win in filter(range(1, winnr('$')), 'getwinvar(v:val, "scratch")')
        execute win . 'windo close'
    endfor
    if a:cmd =~ '^!'
        let cmd = a:cmd =~' %' ? substitute(a:cmd, ' %', ' ' . expand('%:p'), '') : a:cmd
        let output = system(matchstr(cmd, '^!\zs.*'))
    else
        let output = execute(a:cmd)
    endif
    vnew
    let w:scratch = 1
    setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile
    call setline(1, split(output, "\n"))
endfunction

M vim/.vim/plugin/scratch.vim => vim/.vim/plugin/scratch.vim +2 -4
@@ 1,11 1,9 @@
" Provide a :Scratch command to view output of any ex command in a scratch
" Provide a :Scratch command to view output of any command in a scratch
" buffer
" Author: Greg Anders <greg@gpanders.com>
" Date: 2019-03-03

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

command! -nargs=+ Scratch call scratch#open(<f-args>)
command! -nargs=1 -complete=command Scratch call scratch#open(<q-args>)