Saturday, July 5, 2014

Re: Command substitution within vim

On Saturday, July 5, 2014 5:14:08 PM UTC-5, cjsmall wrote:
> 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>".

That would be because your :map! command applies also to command-line mode, because you did not specify a specific mode for it to apply in (for example, :imap or :inoremap). This causes a problem because your first mapping, for normal-mode, is allowing recursive mappings. I.e. you used ":map" instead of ":noremap".

I suggest cleaning up you mappings to specify the specific mode you want, and also to disallow recursive map triggers unless you WANT them to trigger mappings recursively. For example, these two mappings of yours are probably intended to be:

nnoremap \\a :. w>> `dictname`<CR>
inoremap `d o<div><CR></div><ESC>O

>
> 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.
>

That would be :help backtick-expansion. It works in command-line and also within the expression register. Using it for motion commands is in normal mode and completely different, Vim won't expand it there, but you're also not using it in that way.

--
--
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: