2

My workflow is as following: I have a common project root where folders for projects branch of. In these branches I have markdown files with notes, snippets, various information. I mark todos for example with TODO:in these markdown files.

If I want to find all my todos I :cd into the project root and perform :vimgrep /TODO:/g **/*.md . That collects all my TODOs in a quickfix window.

What can I do to collect the list of all markdown files, regardless of their contents? On this particular computer I have no rights to install additional plugins, otherwise fzf's Files: would help.

3

You can use the pattern \%^ to match the start of of the file. Using this, you could populate the quickfix list with the first line of all your markdown files, even empty ones.

:vimgrep "\%^" **/*.md
| improve this answer | |
2

One trick that worked for me was

set errorformat=%f | cexpr glob('**/*.md')

The :cexpr command takes an expression and uses it to populate the quickfix list. Because the default errorformat doesn't parse plain filenames like glob returns, we set it to just include filenames.

To get something like Jake's answer and avoid setting errorformat, we could do something like this to take advantage of a default:

cexpr glob('**/*.md', v:true, v:true)->map({_, v -> v..'|1| '..v})
| improve this answer | |
2

An alternative idea: don't use the quickfix list for a simple list of files. That's what the argument list is for! You have a lot of commands for navigating it (:help :args), and it's very versatile to populate:

                            *{arglist}*
The wildcards in the argument list are expanded and the file names are sorted.
Thus you can use the command "vim *.c" to edit all the C files.  From within
Vim the command ":n *.c" does the same.

White space is used to separate file names.  Put a backslash before a space or
tab to include it in a file name.  E.g., to edit the single file "foo bar": >
    :next foo\ bar

On Unix and a few other systems you can also use backticks, for example: >
    :next `find . -name \\*.c -print`
The backslashes before the star are required to prevent "*.c" to be expanded
by the shell before executing the find program.

Thus :args **/*.md should do the trick.

| improve this answer | |
  • I like your alternative approach and TIL something new. It just doesn't fit as well in my workflow, as for most of the time I also search within files. Also it seems that for all args the file get's loaded, however I do not want to edit the majority of the files. – JohnDoe Sep 29 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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