Skip to content

Instantly share code, notes, and snippets.

@robinp
Last active May 8, 2024 17:00
Show Gist options
  • Save robinp/0af93eae6ef661d5157e2d769fe280b0 to your computer and use it in GitHub Desktop.
Save robinp/0af93eae6ef661d5157e2d769fe280b0 to your computer and use it in GitHub Desktop.
" Generated using ChatGPT, until https://github.com/neovim/neovim/issues/28544 fix gets released.
" Put in init.vim, select visual range in terminal, and call :VCB.
" Make sure that errorformat is set well (experiment with :cexpr "path/to/file:123 etc" or your actual format and see if quickfix gets it right)
function! VisualRangeToQuickfix() abort
" Get visually selected lines
let l:start = line("'<")
let l:end = line("'>")
" Get the current buffer number
let l:bufnr = bufnr('%')
" Extract the lines as a list
let l:lines = getline(l:start, l:end)
" Populate the Quickfix list using the errorformat
cexpr join(l:lines, "\n")
endfunction
command! -range VCB call VisualRangeToQuickfix()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment