Saturday, July 5, 2014

Command substitution within vim

For years I have been using the following vim mapping:

map \\a :. w>> `dictname`<CR>

Here, backslash-a writes the current line (which is always a single word)
out to the appropriate file which is substituted by the command "dictname".
Apparently, vim is doing the command substitution internally in order to
know what file to write, although I cannot find this documented anywhere.

Recently, I decided to start using the backtick, like the backslash, for
macros. At some point I got around to defining:

map! `d o<div><CR></div><ESC>O

and this began to screw up the backslash-a macro because the backtick-d
kept getting substituted with "o<div>". I tried escaping the backtick
in the macro definition but nothing worked. I tried replacing `dictname`
with $(dictname) but this also fails because vim does not do the command
substitution and tries to literally write to the nonexistent file
"$(dictname)".

I have a workaround, but I would really like to understand what is happening
here.

1: Is it documented that vim does backtick substitution? I don't understand
how that is possible when the backtick is being used for motion commands
identical to the forward single quote.

2: Any suggestions on alternate means of command substitution or how to
otherwise get the output of the dictname command into vim just before
the macro is executed?

Maybe this is a place where system() should be used, but I'm unclear whether and how that can be introduced into a macro.

Thanks.

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment