Tony Mechelynck wrote: > On 09/01/09 18:22, Tim Chase wrote: >> There's also not a distinction for command-line mappings to >> discern a "search" command-line from a "colon" command-line, so I >> can't use a mapping to do something like (assuming "scnoremap" >> was a search-command-line >> >> :scnoremap<cr> <cr>:set foldmethod...<cr> >> >> Perhaps this thread may spark a weekend hack by one of the >> vim-developers. :) > > Oh, but you can set up mappings for search commands as distinct from > mappings for ex-commands. Here's an example: <rejiggering after several amendments by Tony> > Better yet: > > :cnoremap <buffer> <expr> <CR> ((getcmdtype() == '/' <Bar><Bar> > getcmdtype() == '?')?"<Bslash>r:setlocal fdm=expr":"<Bslash>r") </rejiggering> > The above requires Vim 7.0 or later, and of course with expression > evaluation compiled-in.
Wonderful! it took me a little while to grok the "<Bslash>r" bits (as by default I tend to use single-quote rather than double-quote), but the result was a "duh!" sorta conclusion. For this case, I'd likely shorten it a bit more: ... getcmdtype()=~'[/?]'... I also found that I could just put "\r" in the double-quote strings and it worked fine. My updated (one-line) version: :cnoremap <buffer> <expr> <cr> (getcmdtype()=~'[/?]')?"\r:setlocal fdm=expr fde=(getline(v:lnum)=~@/)?0:1 fdl=0\r":"\r" As always, Tony, thanks for elucidating a new corner of Vim. -tim --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---
