My workflow revolves around having NerdTree opened with a quickfix at the the bottom and one file opened in a buffer.

I often grep within my file only by using the % shortcut in my grep command.

I then navigate to quickfix or NerdTree to look at something and rerun my grep command slightly tweaked. At this point the command no longer works as @% does not contain the name of my file anymore.

Could I keep entering non-modifiable buffers from updatding @%?

1 Answer 1


"% is a read-only register. I doubt there is anything you can do to the register.

Instead of simply using % in your grep command, e.g. :grep 'foo' %, use <c-r> to put in the contents of the register, e.g. :grep 'foo' <c-r>%. This will paste/put the name of the file in the grep command. To tweak your grep simply do q: and go and edit your last grep (press return to run).

For more help see:

:h c_CTRL-R
:h c_%
:h q%

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.