If I have full path inside a register(e.g. @a="/dir/file.txt") and I want to open the file in Ex mode.
I try :e @a that, but it doesn't work.
And I also try :e echo @a but it doesn't work either.
Obviously I can type :e CTRL-R a in Ex mode, it works.
But I'm wondering is there a way to get the content of register in Ex mode without use CTRL-R.
The :edit command takes a file specification. There are certain special characters (like % for the current file name; cp. :h cmdline-special), but the @reg notation does not work here.
Vim's evaluation rules are different than most programming languages. You need to use :execute in order to evaluate a variable (or expression); otherwise, it's taken literally; i.e. Vim uses the variable name itself as the argument.
So, the solution to your problem is
:execute 'edit' @a
If you don't want the special characters to apply to the register contents, a more robust (but longer) way is
:execute 'edit' fnameescape(@a)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With