How can I insert the file name of the active file buffer into a command?
When I invoke a command that needs a file name, I am often doing so from a file buffer and want the name of that file while typing the command into the minibuffer.
I'm looking for a hypothetical C-x… that I can type during forming a command line in the minibuffer.
So if, while the current buffer is a file named Lorem Ipsum.txt
, I type this:
M-x grep RET 'foo' SPC C-x … RET
the M-xgrepRET presents a minibuffer prompting for the grep
command. In response, I've typed the regex pattern argument ('foo') and inserted the filename argument (C-x…). That minibuffer will end up as:
grep -nH -e 'foo' 'Lorem Ipsum.txt'
What existing command gets the current file buffer's file name like this? What is its default key binding?
M-n
. It doesn't work everywhere, but works in a lot of places. Also, since you're grepping, you might like lgrep and rgrep, which are a little more interactive, I think.