Re: cmapping woes
On Mon, 22 May 2006 at 4:07am, Eric Arnold wrote: > On 5/21/06, Hari Krishna Dara <[EMAIL PROTECTED]> wrote: > > > > On Sun, 21 May 2006 at 3:12pm, Eric Arnold 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 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 cd call Cd_plus() > > > > > > "cnoremap cd echo getcmdpos() > > > "cnoremap cd if getcmdpos() < 3 call Cd_plus() > > > else call feedkeys('cd','n') call setcmdpos(1) end > > > > > > "cnoremap cd ( getcmdpos() == 1 ? Cd_plus() : 'cd' ) > > > "cnoremap cd Cd_plus() > > > "abbr cd Cd_plus() > > > "silent! unabbr cd > > > > You should use the new option and check if you are in the start > > > seems to be evaluated in the sandbox as with =, I report > with sadness... Actually cabbr with option would have been a great solution for you, if not for the fact that that also is evaluated in sandbox. Anyway you fould a solution, I think. -- Hari __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
Re: cmapping woes
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 =getcmdpos()==1?MyFunc():'xx' function! MyFunc() call feedkeys(":call DoIt()\", '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 =getcmdpos()==1 && getcmdtype() == ':' ? feedkeys( "call Cd_plus()",'t' ) :'cd' Having a in the mapping is pretty nasty :-) I was hoping would work like that, but no go: cnoremap cd ( getcmdpos() == 1 && getcmdtype() == ':' ? Cd_plus_start() : 'cd' ) ...which I think is due to that old issue where won't allow nested getchar() input. However this form works: function! Cd_plus_start() return ":call Cd_plus()\" endfunction cnoremap cd ( getcmdpos() == 1 && getcmdtype() == ':' ? Cd_plus_start() : 'cd' ) And the embedded in the return string isn't treated as a literal in the expression, so all seems well. Go figure. Thanks! And for your effort you've won: One 'cd' accelerator script!:-) CD_Plus.vim Description: application/octetstream
Re: cmapping woes
On 5/22/06, Eric Arnold <[EMAIL PROTECTED]> wrote: Eric, this works for me: -- cnoremap xx =getcmdpos()==1?MyFunc():'xx' function! MyFunc() call feedkeys(":call DoIt()\", 't') return '' endfu And DoIt() is executed not in sandbox. Does this work for you ? Yakov
Re: cmapping woes
On 5/22/06, Yakov Lerner <[EMAIL PROTECTED]> wrote: On 5/22/06, Eric Arnold <[EMAIL PROTECTED]> wrote: > 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 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 cd call Cd_plus() > > > > > > "cnoremap cd echo getcmdpos() > > > "cnoremap cd if getcmdpos() < 3 call Cd_plus() > > > else call feedkeys('cd','n') call setcmdpos(1) end > > > > > > "cnoremap cd ( getcmdpos() == 1 ? Cd_plus() : 'cd' ) > > > "cnoremap cd Cd_plus() > > > "abbr cd Cd_plus() > > > "silent! unabbr cd > > > > The following works for me: > > > > cnoremap cd =getcmdpos()==1?"MYCD ":'cd' > > This is nearly it. I'm actually trying to start a script from the > mapping. Can you start a script from a function in rhs ? Like this; No. This runs in the sandbox, and all sorts of things will fail in MyFunc(). cnoremap cd =getcmdpos()==1?MyFunc():'cd' func! MyFunc() ... start script here ... return "" endfun Yakov
Re: cmapping woes
On 5/22/06, Eric Arnold <[EMAIL PROTECTED]> wrote: 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 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 cd call Cd_plus() > > > > "cnoremap cd echo getcmdpos() > > "cnoremap cd if getcmdpos() < 3 call Cd_plus() > > else call feedkeys('cd','n') call setcmdpos(1) end > > > > "cnoremap cd ( getcmdpos() == 1 ? Cd_plus() : 'cd' ) > > "cnoremap cd Cd_plus() > > "abbr cd Cd_plus() > > "silent! unabbr cd > > The following works for me: > > cnoremap cd =getcmdpos()==1?"MYCD ":'cd' This is nearly it. I'm actually trying to start a script from the mapping. Can you start a script from a function in rhs ? Like this; cnoremap cd =getcmdpos()==1?MyFunc():'cd' func! MyFunc() ... start script here ... return "" endfun Yakov
Re: cmapping woes
On 5/21/06, Hari Krishna Dara <[EMAIL PROTECTED]> wrote: On Sun, 21 May 2006 at 3:12pm, Eric Arnold 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 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 cd call Cd_plus() > > "cnoremap cd echo getcmdpos() > "cnoremap cd if getcmdpos() < 3 call Cd_plus() > else call feedkeys('cd','n') call setcmdpos(1) end > > "cnoremap cd ( getcmdpos() == 1 ? Cd_plus() : 'cd' ) > "cnoremap cd Cd_plus() > "abbr cd Cd_plus() > "silent! unabbr cd You should use the new option and check if you are in the start seems to be evaluated in the sandbox as with =, I report with sadness... of the command from the function. You can then return "cd" or whatever else you want. I have actually needed this same functionality for myself, and created a plugin called cmdalias.vim. This was very complicated to do prior to 7.0, but with the new feature in 7.0, it became a very simple plugin. Never the less, it is available at: http://www.vim.org/script.php?script_id=745 -- HTH, Hari
Re: cmapping woes
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 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 cd call Cd_plus() > > "cnoremap cd echo getcmdpos() > "cnoremap cd if getcmdpos() < 3 call Cd_plus() > else call feedkeys('cd','n') call setcmdpos(1) end > > "cnoremap cd ( getcmdpos() == 1 ? Cd_plus() : 'cd' ) > "cnoremap cd Cd_plus() > "abbr cd Cd_plus() > "silent! unabbr cd The following works for me: cnoremap cd =getcmdpos()==1?"MYCD ":'cd' This is nearly it. I'm actually trying to start a script from the mapping. This starts "MYCD", but interfers with 'cd' cnoremap cd =getcmdpos()==1 ? "MYCD " :'cd' I tried adding a CR inside the = 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 = expression because of the sandbox restrictions. This seems to be the only thing that works: cnoremap cd =getcmdpos()==1 && getcmdtype() == ':' ? feedkeys( "call Cd_plus()",'t' ) :'cd' Oddly, "feedkeys()" doesn't seem to work if is used instead of = This would all be s much simpler without the sandbox. There should be a way to bypass it. Notes 1. Don't use on cabbrev (doesn't work, documented somewhere). 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
Re: cmapping woes
On Sun, 21 May 2006 at 3:12pm, Eric Arnold 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 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 cd call Cd_plus() > > "cnoremap cd echo getcmdpos() > "cnoremap cd if getcmdpos() < 3 call Cd_plus() > else call feedkeys('cd','n') call setcmdpos(1) end > > "cnoremap cd ( getcmdpos() == 1 ? Cd_plus() : 'cd' ) > "cnoremap cd Cd_plus() > "abbr cd Cd_plus() > "silent! unabbr cd You should use the new option and check if you are in the start of the command from the function. You can then return "cd" or whatever else you want. I have actually needed this same functionality for myself, and created a plugin called cmdalias.vim. This was very complicated to do prior to 7.0, but with the new feature in 7.0, it became a very simple plugin. Never the less, it is available at: http://www.vim.org/script.php?script_id=745 -- HTH, Hari __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
Re: cmapping woes
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 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 cd call Cd_plus() "cnoremap cd echo getcmdpos() "cnoremap cd if getcmdpos() < 3 call Cd_plus() else call feedkeys('cd','n') call setcmdpos(1) end "cnoremap cd ( getcmdpos() == 1 ? Cd_plus() : 'cd' ) "cnoremap cd Cd_plus() "abbr cd Cd_plus() "silent! unabbr cd The following works for me: cnoremap cd =getcmdpos()==1?"MYCD ":'cd' Notes 1. Don't use on cabbrev (doesn't work, documented somewhere). on cmap sometimes doesn't work, too. 2. I think you're better off making your own cd :command not just function. Yakov
Re: cmapping woes
On Sun, 21 May 2006, Eric Arnold 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 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. [snip] "cnoremap cd ( getcmdpos() == 1 ? Cd_plus() : 'cd' ) [snip] This one ought to work. Remove "". cnoremap cd ( getcmdpos() == 1 ? Cd_plus() : 'cd' ) HTH. -- Gerald