Open file name that is inside the register in Ex mode in Vim -
if have full path inside register(e.g. @a="/dir/file.txt") , want open file in ex mode.
i try :e @a that, doesn't work.
and try :e echo @a doesn't work either.
obviously can type :e ctrl-r a in ex mode, works.
but i'm wondering there way content of register in ex mode without use ctrl-r.
the :edit command takes file specification. there special characters (like % current file name; cp. :h cmdline-special), @reg notation not work here.
vim's evaluation rules different programming languages. need use :execute in order evaluate variable (or expression); otherwise, it's taken literally; i.e. vim uses variable name argument.
so, solution problem is
:execute 'edit' @a if don't want special characters apply register contents, more robust (but longer) way is
:execute 'edit' fnameescape(@a)
Comments
Post a Comment