1

Vim does support a nice option to accept a file with list of files that are then opened in a Quickfix list. Rough example, I find all files in ~ that are smaller than 1KB and pass this to Vim:

find ~ -type f -size -1k > /tmp/1 && vim -q /tmp/1

I would love to use that as zsh suffix alias:

alias V='> /tmp/1 && vim -q /tmp/1'

So that I can:

find ~ -type f -size -1k V

I use several convenience suffixes:

alias -g H='| head -n'
alias -g X='| xargs -d"\n"'

So that I can:

git log H 5

And finally I'm approaching the Question itself.

It makes me sad that I cannot use mktemp to create that temporary file. Tried all the stupid rookie shell script tricks:

find . | tee QL=$(mktemp) && vim -q $QL

I assume the solution is so simple I'd be put to shame.

At the moment I use:

find ... | xargs -d"\n" vim --

But this only fills in a list of buffers, and doesn't populate Quickfix of Location list, even though I think a command may be passed to Vim with -c to do so. There's a warning "Vim: Warning: Input is not from a terminal", and then after you quit Vim, terminal fails prints ^D ^M instead of Ctrl-C Ctrl-D afterwards, though this may be fixed by adding ttyctl -f to .zshrc, but in Vim itself Tab and Backspace keys misbehave in Ex mode which is very annoying.

  • 1
    If no luck here you may want to try the vi/vim stackexchange: vi.stackexchange.com Probably there are some vim-specific solutions to achieve what you want. – Wildcard Dec 16 '15 at 21:05
  • Does it have to be a postfix alias? A function named, for example, vfind, could do the job just as well, and could be just as easy to use. – muru Dec 16 '15 at 21:27
  • @muru It's not just find, I may want to use an ls or ls | grep. – phil pirozhkov Dec 17 '15 at 12:57
2

As long as what you posted is currently working for you thus far,

find ~ -type f -size -1k > /tmp/1 && vim -q /tmp/1

And you merely want to be rid setting up the intermediary file > /tmp/1 && and /tmp/1, see if this works for you:

vim -q <( find ~ -type f -size -1k )

Explanation

  • from your original code, you seem to be using find to generate desired file list with your particular criteria, then it was saved to /tmp/1 which was merely an intermediary file just so that vim -q filelist could be done, because vim -q expects a file argument
  • <( commands... ) is one of Bash's process substitutions , automatically runs a command and saves output to a system temp just for this purpose /dev/fd/63 if you are curious
  • vim -q then thinks it is getting a file, and for all intents and purposes, it actually is, so it works

Additional tips

If you do not absolutely have to use vim's quickfix feature, but merely just want a way to quickly edit multiple files, remember you can send vim multiple file arguments (vim file1 file2...) so if we modify your original find, we could:

find ~ -type f -size -1k -exec vim {} +

Within vim

  • :args will show in the status bar, the argument list, like: file1 [file2] file3 if you are currently editing file2
  • :n to navigate to next file in argument list
  • :wn to write next meaning save this file and auto open next file
  • :prev to go to previous file
  • Probably I didn't put this clear, but my intention is to be able to add a V after an arbitrary command, and be able to have the results of that command open in Vim's quickfix list ( or list of buffers, but this creates those keyboard mapping issues ). I'm aware of process substitution, but in this case it cannot solve the 'postfix alias' issue. – phil pirozhkov Dec 17 '15 at 12:56
0

After a long while I'm now able to answer my own question.

Top down:

alias -g V='| tee $(rm fifo.tmp; mkfifo fifo.tmp && echo fifo.tmp) &; vim $(< fifo.tmp ) && rm fifo.tmp'

That is a zsh alias that allows for:

find . -name TODO V

or

ls | grep asciidoc V

and get all the files opened as buffers in Vim.

Somehow this doesn't work without tee, e.g. replacing | tee with > does not open any buffers in Vim.

What we do here is we create a pipe named fifo.tmp, tell tee to redirect output from previous command to it and send this to background; meanwhile we read this pipe in a subshell and put the output as list of files to be opened by Vim.

This however doesn't work well with file names that contain whitespace.

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.