cmdline regex ques

28 views
Skip to first unread message

M Kelly

unread,
Oct 4, 2019, 1:13:42 PM10/4/19
to vim_use
Hi,

Does anyone know what would be the vim regex for getcmdline() =~ for both 'q' and 'q!' ?
ie, something like:
cnoreabbrev <expr> q  (getcmdtype() == ':' && getcmdline() =~ '\s*q\s*$') ?  'call Quit()' : 'q'
cnoreabbrev <expr> q! (getcmdtype() == ':' && getcmdline() =~ '\s*q!\s*$') ? 'call QuitBang()' : 'q!'
But this clearly isn't right because the q! cmd is picked up by the q here.
I think we need an exact match on the string between whitespace ?

thx for everything vim,
-m

M Kelly

unread,
Oct 4, 2019, 5:27:03 PM10/4/19
to vim_use
Hi,

I guess it evaluates as I type ?  So no real way around this.
Perhaps a cmap <CR> could trigger a cmdline substitution ?
Maybe there is such a plugin already.

thx,
-m

M Kelly

unread,
Oct 5, 2019, 6:17:56 PM10/5/19
to vim_use
Hi,

I was able to use the 'Konfekt/vim-alias' plugin for this -

:Alias q call\ Quit()
:Alias q! call\ QuitBang()

thx again everyone,
-m
Reply all
Reply to author
Forward
0 new messages