On 5/22/06, Yakov Lerner <[EMAIL PROTECTED]> wrote:
On 5/22/06, Eric Arnold <[EMAIL PROTECTED]> wrote:

Eric, this works for me:
----------
cnoremap xx <c-r>=getcmdpos()==1?MyFunc():'xx'<cr>

function! MyFunc()
    call feedkeys(":call DoIt()\<cr>", 't')
    return ''
endfu
------------
And DoIt() is executed not in sandbox.
Does this work for you ?

Yakov


Yes, this is a better version of :

cnoremap cd <c-R>=getcmdpos()==1 && getcmdtype() == ':' ? feedkeys(
"call Cd_plus()<c-v><cr>",'t' ) :'cd'<cr>

Having a <c-v><cr> in the mapping is pretty nasty :-)

I was hoping <expr> would work like that, but no go:

cnoremap <expr> cd ( getcmdpos() == 1 && getcmdtype() == ':' ?
Cd_plus_start() : 'cd' )

...which I think is due to that old issue where <expr> won't allow
nested getchar() input.  However this form works:


function! Cd_plus_start()
  return ":call Cd_plus()\<cr>"
endfunction

cnoremap <expr> cd ( getcmdpos() == 1 && getcmdtype() == ':' ?
Cd_plus_start() : 'cd' )

And the <CR> embedded in the return string isn't treated as a literal
in the <expr> expression, so all seems well.  Go figure.

Thanks!  And for your effort you've won:

   One 'cd' accelerator script!    :-)

Attachment: CD_Plus.vim
Description: application/octetstream

Reply via email to