Saturday, December 24, 2011

Re: nmap yiw mapping when <2 characters

2011/12/24 Tim Chase <vim@tim.thechases.com>:
> On 12/24/11 08:48, Dan S wrote:
>>
>> I'm trying to get a mapping to work irrespective of the number
>> of characters in the document. The following is a simplified
>> example which does the rather strange task of copying the
>> current word, then pasting it and appending a question mark:
>>
>> :nmap<buffer>  <F3>  yiw pa?<Esc>
>>
>> Note this is only for demo purposes, in my application I pass
>> the yanked text to a function that does something useful. The
>> above map works, *but* never does anything when the buffer is
>> completely empty or only has one character in it.
>
>
> Without knowing what your function does, it's a little hard to prognosticate
> your intent.  However, you might be interested in using
>
>  expand('<cword>')
>
> within your function.  It grabs the word under the cursor for use in an
> expression, and has the added benefit that it doesn't tromp on your scratch
> register.
>
> I believe what's happening is that either the "yiw" is failing, or the space
> is failing which triggers an internal "something exceptional happened"
> causing the rest of the mapping to stop execution, much like happens with
> repeated macro-execution.

Excellent, that's what I'm looking for - thanks!

(What I'm making is a call to a particular programming language's
help-lookup command [namely, supercollider].)

Best
Dan

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

No comments: