How to disable abbreviations in : mode

42 views
Skip to first unread message

howard Schwartz

unread,
Mar 16, 2012, 11:31:51 PM3/16/12
to vim...@googlegroups.com
I would like to temporarily disable abbreviations so they work in insert and
search mode, but not in command line mode. Unfortunately if you define an
abbreviation in ex mode with cab you also enable it in search mode.

Something like this works, for starters:

nnoremap : :set paste<CR>:


That disables them in command mode. But now I have to enable them back again,
somehow when I leave command mode and return to normal mode. I could use an
autocmmand to set and then unset paste, when entering and leaving a cmd
window, but there are no autocommands for entering and leaving command mode.

Any ideas?


Michael Ludwig

unread,
Mar 18, 2012, 12:40:35 PM3/18/12
to vim...@googlegroups.com
howard Schwartz schrieb am 16.03.2012 um 20:31 (-0700):
>
> nnoremap : :set paste<CR>:
>
> That disables them in command mode. But now I have to enable them
> back again, somehow when I leave command mode and return to normal
> mode.

Not sure that's answering your question, but maybe pastetoggle?

:help 'pastetoggle'
set pastetoggle=<F5>

Michael

Bee

unread,
Mar 18, 2012, 1:40:45 PM3/18/12
to vim_use
:help :ab
:help :iab
:help :cab

2. Abbreviations *abbreviations* *Abbreviations*

Abbreviations are used in Insert mode, Replace mode and Command-line
mode.

:ab[breviate] [<expr>] {lhs} {rhs}
add abbreviation for {lhs} to {rhs}. If {lhs} already existed it is
replaced with the new {rhs}. {rhs} may contain spaces.

:ia[bbrev] [<expr>] [lhs] [rhs]
same as ":ab", but for Insert mode only. {not in Vi}

:ca[bbrev] [<expr>] [lhs] [rhs]
same as ":ab", but for Command-line mode only. {not in Vi}

howardb21

unread,
Mar 19, 2012, 2:14:36 AM3/19/12
to vim_use


On Mar 18, 10:40 am, Bee <beeyaw...@gmail.com> 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).

Christian Brabandt

unread,
Mar 19, 2012, 5:14:24 AM3/19/12
to vim...@googlegroups.com

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

Reply all
Reply to author
Forward
0 new messages