I'd like to be able to define my own functions that add certain kinds of line to the quickfix list, or set it to those in its entirety, without having to go via the filesystem with a made-up errorfile format that I tell vim how to parse (errorfmt).

I've seen setqflist and getqflist, but the only other questions or discussion I've seen about this has been people wanting to remove entries, and so the answer ends up being filter - which doesn't tell me how to format an entry if I want to add one.

So, if I'm to call setqflist(my_errs), how should I define my_errs?

2 Answers 2


getqflist() and setqflist() are sort of opposites. Printing out the results of getqflist() will give you and idea of the structure setqflist() is looking for.

call setqflist(getqflist())

Recent versions of Vim (8+) also allow you to use lines & efm to parse a list of lines with a different format than the current 'errorformat'.

For more information see :h setqflist() & :h getqflist()


I have this function. The format of setloclist is the same as of setqflist. Hope you find it helpful.

You need to set in the argument action 'a' for add.

function! Matches(pat)
let buffer=bufnr("") "current buffer number
let b:lines=[]
"the right way to escape!!
execute ":%g/\\V" . escape(a:pat,'/\?') . "/let b:lines+=[{'bufnr':" . 'buffer' . ", 'lnum':" . "line('.')" . ", 'text': escape(getline('.'),'\"')}]"
"call setloclist(0, [], ' ', {'items': b:lines}) 
call setloclist(0,b:lines)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.