On Tue, 16 Feb 2010, Ben Schmidt wrote: > > cmap <silent><script> <CR> <CR>:let <SID>project_command=@: <Bar> > > cunmap <script> <lt>CR><CR> > > > > unless you need that accessor function or other punctuation to make the > > SID thing work (see previous email).... > > > > Another one: > > 475: Invalid argument: <SNR>1_project_command=@: | cunmap <script> <CR> > > > > Now I'm confused where else I should use <SID> instead of s: or it's not > > the case? > > I think perhaps <SID> only works for functions not variables. But you > can use a variable in a function. So put something like this in your > script > > fun! set_project_command(val) > let s:project_command=val > endfun > > and make the map something like > > cmap <silent><script> <CR> <CR>:call <SID>set_project_command(@:) <Bar> > cunmap <script> <lt>CR><CR> > > Ben.
While it's nice to know, using 'cmap' and 'cunmap' seems needlessly complex. Unless I'm misinterpreting something, it seems like the OP should just use 'input()' at the proper time, rather than trying to read back the commandline after capturing the '<CR>'. I think that this script does roughly what Aarto is trying to do. (I used different mappings, since <C-F{11-20}> is 'broken' under rxvt-unicode.) (I also think that much of this is probably better done via ':make', but that's neither here nor there.) Best, Ben H """" ~/.vim/plugin/runproject.vim """" " sets up the project command function! s:SetupProject() if !exists("s:project_command") let s:project_command = expand("%:p") endif let s:project_command = input("Project command: ", s:project_command) endfunction " resets the project command to default, without running the command function! s:ResetProject() unlet! s:project_command call s:SetupProject() endfunction " runs the project command, altering it if requested function! s:RunProject(...) if !exists("s:project_command") || (a:0==1 && a:1=='alter') call s:SetupProject() endif return ':!'.s:project_command."\n" endfunction " note no <expr>, since it doesn't return a command to run map <F10> :call <SID>ResetProject()<CR> " note the <expr> and no :call or <CR> in the mappings map <expr> <F11> <SID>RunProject() map <expr> <F12> <SID>RunProject('alter') -- You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php