Skip to content

Instantly share code, notes, and snippets.

@AndrewRadev
Created October 1, 2024 19:25
Show Gist options
  • Save AndrewRadev/83c89e171e58f093ae68cee145c803be to your computer and use it in GitHub Desktop.
Save AndrewRadev/83c89e171e58f093ae68cee145c803be to your computer and use it in GitHub Desktop.
Load marks into the quickfix list
command! Cmarks call s:Cmarks()
function! s:Cmarks() abort
let items = []
" Global marks:
let marklist = getmarklist()
" Local marks:
let marklist += getmarklist(bufnr())
for mark in marklist
let name = mark.mark[1]
if name !~ '[a-zA-Z]'
continue
endif
if has_key(mark, 'file')
let filename = fnamemodify(mark.file, ':p')
else
let filename = expand('%:p')
endif
if !filereadable(filename)
" A mark could have been saved in a temporary file
continue
endif
let [buffer, line, col, _] = mark.pos
let text = readfile(filename)[line - 1]
call add(items, {
\ 'filename': filename,
\ 'buffer': buffer,
\ 'text': name..' | '..text,
\ 'lnum': line,
\ 'col': col || 1,
\ })
endfor
call setqflist([], 'r', {'title': 'Marks', 'items': items})
copen
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment