On Mon, March 19, 2012 07:14, howardb21 wrote:
>> Abbreviations are used in Insert mode, Replace mode and Command-line
>> mode.
>
> Yes I know all that. But there is no `search only' mode for defining
> abbreviations. Abbreviations can be valuable in search mode, but an
> annoyance in command line mode. There is no way to to do this:
>
> iab ihr rhs
> sab ihr rhs
>
> which would define an abbreviation for insert and search modes, but
> NOT for command line mode. And that is what I want. Putting it another
> way, I want any and all abbreviations disabled in command line mode,
> but I may well want
> them working in insert, and replace mode or when searching (in
> `search' mode).
You can work around it:
function! Abbreviate(lhs, rhs)
if getcmdtype() =~ '[/?]'
return a:rhs
else
return a:lhs
endif
endfu
function! Abbr(args)
if len(split(a:args)) < 2
echo "Need 2 arguments"
return
endif
let lhs = matchstr(a:args, '^\s*\zs\S*')
let rhs = matchstr(a:args, '^\s*\S*\s\+\zs.*')
exe printf(':cnorea %s <c-\>eAbbreviate(''%s'',''%s'')<cr>', lhs, lhs,
rhs)
endfu
com! -nargs=+ Sab :call Abbr(<q-args>)
And then use :Sab foo foobar
regards,
Christian
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php