Hi Pavol
On 2015-07-17 Friday at 10:47 -0400 Pavol Juhas wrote: > On Fri, Jul 17, 2015 at 09:44:55AM +0200, Roland Eggner wrote: > ... > > On 2015-07-16 Thursday at 18:52 +0000 [email protected] wrote: > ... > > > What steps will reproduce the problem? > > > > > > vim -u NONE -i NONE -N > > > :e `=$HOME . '/.vimrc'` > > > > > > What is the expected output? What do you see instead? > > > > > > Vim should open the .vimrc file in my HOME directory. Instead I see the > > > following error: > > > > > > E15: Invalid expression: /Users/pjuhas . '/.vimrc' > ... I reproduced with vim-7.4.529: :e `=$HOME . '/.vimrc'` E15: Invalid expression: /home/roland . '/.vimrc' "`=/home/roland . '/.vimrc'`" [New DIRECTORY] :e `=expand('$HOME') . '/vimrc'` :ls 1 # "`=/home/roland . '/.vimrc'`" line 1 3 %a "~/.vimrc" line 1 The usual solution for this type of error is insertion of a call to expand(), this works for me in this case too, thus I would not consider the issue as bug. > > Your ex-command bears three problems. I will start with the innermost: > > > > (1) vim: E15 “invalid expression”: > > “expand()” should help. > > Hi Roland, > > Please see :help `= in a recent version of vim. The expression > between `= and the closing backtick should be evaluated as a Vim > expression and not as a shell command. … got it -- thank you for the explanation. Despite having used vim, “:help …” and “:helpgrep …” almost daily for 9 years I was not aware of the special effect of the equal sign in `= … ` until now. Surprisingly “:help improvements-6” hints, that this has been there since early days of the vim-6 period. My patch provided in a separate mail should improve accessibility of “:help `=” by adding references at useful points in “runtime/doc/cmdline.txt” -- currently there are no such references at all. > The problem is that > > $HOME . '/.vimrc' > > is a valid Vim expression, thus the whole command should be the same > as :e /Users/pjuhas/.vimrc. If I do something similar using > a Vim variable instead of environment variable, ie, > > :let h = $HOME > :e `=h . '/.vimrc'` > > it works as expected. I think what happens is that $HOME gets > expanded before parsing the VimL expression; in other words the > expression parsed is "/Users/pjuhas . '/.vimrc'" instead of > "$HOME . '/.vimrc'". Parsed is what we type. The following evaluation is the question. The output of “:ls” given 43 lines above seems to show, that in this case the backticks and the equal sign are taken literally. Looks like the evaluation aborts on raising E15. In the E15 message the unquoted “/home/roland” cannot be a valid variable name, thus can indeed only be considered as “invalid expression”. To my experience in such cases “expand( … )” usually solves the problem. When I tried this with your test expression, it worked flawlessly, as I tried to show 52 lines above. What result do you get with “:e `=expand('$HOME') . '/vimrc'`”? > … > PS: The `= expression has an advantage that it is not further expanded > and can be safely and concisely used with any filenames. Compare: > > :let f = 'filename with special characters *#' > :execute 'edit' fnameescape(f) > :edit `=f` For me the former has the advantages • well documented • works at any place, where strings are expected in ex-commands • I use it frequently every day in vim scripts (rather rarely at the vim commandline, because I load files mostly by loading session files, by a vim command of the “gf” family, or by calling vim from another utility like mutt, git, hg, mc, zsh, …) whereas the latter • works only at places, where filenames are expected as arguments to ex-commands • to me the syntax looks obscure and against intuition -- Best regards, Roland Eggner -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
pgp6nyf_n7sLR.pgp
Description: PGP signature
