On 5/21/06, Yakov Lerner <[EMAIL PROTECTED]> wrote:
On 5/22/06, Eric Arnold <[EMAIL PROTECTED]> wrote:
> I've been trying to map "cd" if it's the first two characters on the
> :ex line. I've tried all the combinations I can think of. On
> several of them, I seem to be getting errors as if <expr> is run in
> the sandbox (that dog won't hunt). The only one that works at all is
> the first simple mapping, but that gets painful, of course, when you
> want to use "cd" in a search, etc.
>
> Anybody know any good tricks?
>
>
> silent! cunmap cd
>
> cnoremap <silent> cd call Cd_plus()<CR>
>
> "cnoremap <silent> cd echo getcmdpos()<CR>
> "cnoremap <silent> cd if getcmdpos() < 3 <bar> call Cd_plus() <bar>
> else <bar> call feedkeys('cd','n') <bar> call setcmdpos(1) <bar> end
> <CR>
> "cnoremap <silent> <expr> cd ( getcmdpos() == 1 ? Cd_plus() : 'cd' )
> "cnoremap <silent> <expr> cd Cd_plus()
> "abbr <silent> <expr> cd Cd_plus()
> "silent! unabbr cd
The following works for me:
cnoremap cd <c-R>=getcmdpos()==1?"MYCD ":'cd'<cr>
This is nearly it. I'm actually trying to start a script from the
mapping. This starts "MYCD", but interfers with 'cd'
cnoremap cd <c-R>=getcmdpos()==1 ? "MYCD " :'cd'<cr><CR>
I tried adding a CR inside the <C-R>= expression after MYCD, but it
seems that any control chars returned from an expression are escaped
as literals i.e. you see
:MYCD<0d>
show up as the result.
I can't run the script directly from inside the <C-R>= expression
because of the sandbox restrictions.
This seems to be the only thing that works:
cnoremap cd <c-R>=getcmdpos()==1 && getcmdtype() == ':' ? feedkeys(
"call Cd_plus()<c-v><cr>",'t' ) :'cd'<cr>
Oddly, "feedkeys()" doesn't seem to work if <expr> is used instead of <C-R>=
This would all be soooo much simpler without the sandbox. There
should be a way to bypass it.
Notes
1. Don't use <silent> on cabbrev (doesn't work, documented somewhere).
<silent> on cmap sometimes doesn't work, too.
Yeh, I noticed it seems to inhibit the display of the replaced string.
2. I think you're better off making your
own cd :command not just function.
Yakov