From :help backtick-expansion
:
*backtick-expansion* *`-expansion*
On Unix and a few other systems you can also use backticks for the file name
argument, for example: >
:next `find . -name ver\\*.c -print`
:view `ls -t *.patch \| head -n1`
The backslashes before the star are required to prevent the shell from
expanding "ver*.c" prior to execution of the find program. The backslash
before the shell pipe symbol "|" prevents Vim from parsing it as command
termination.
So, if you want to edit a filename given by the output of a shell command, you could write:
:tabe `your shell command`
Vim should open the file given by the output of your shell command in a new tab.
Note that if your shell command contains a pipe, it must be escaped to prevent Vim from parsing it as a command termination.
Besides, I'm not sure, but I think that if the output contains special characters, it won't work as expected and you will have the error E79: Cannot expand wildcards
.
Again, not sure, but I suspect it's because after getting the output of the shell command, if Vim sees some special characters, it tries to perform an expansion on them but sometimes the pattern can be illegal (see :h e79
for more information).
In this case, :help `=
might help you:
*`=*
You can have the backticks expanded as a Vim expression, instead of as an
external command, by putting an equal sign right after the first backtick,
e.g.: >
:e `=tempname()`
The expression can contain just about anything, thus this can also be used to
avoid the special meaning of '"', '|', '%' and '#'.
This syntax seems more reliable, maybe because Vim doesn't perform any expansion after evaluating the expression which follows the =
sign.
Thus, you could also write:
:tabe `=system('your shell command')`
Note that with this 2nd syntax, you don't need to escape a pipe character.
However, as @muru explained, I don't think that what you are trying to achieve is possible, because no matter the syntax you use, your shell alias abs
doesn't echo the path to a file, it simply launches a new Vim session.
But maybe you could export an environment variable in a file sourced by your shell like ~/.bashrc
:
export ABS=/project/userid/trees/soft/abs.pl
And then type in Vim:
:tabe $ABS
If the session was launched from the shell, Vim should know the environment variable and expand automatically $ABS
.
Another working case is given in your last comment: you want to open the file given by the shell command ls -1 | tail -1
in a new tab.
You could achieve this with:
:tabe `ls -1 \| tail -1`
or
:tabe `=system('ls -1 | tail -1')`
mA
(you can replaceA
by any capital letter). Then at any time you can use'A
to reopen this file (even if you closed vim). You can use:marks
to see all of your bookmarks. See:h bookmark
for more information.:tabnew | !abs
starts a new Vim instance after opening a new tab, instead of opening a tab with that file loaded. (Compare: what will happen if you run just:!abs
?)