If your Vim settings include 'r' in 'formatoptions'
(default) it will automatically insert the current comment leader after hitting [Enter] in insert mode, but this can be undesirable for abbrevs that expand to a single-line comment in languages that don't have separate single/multi-line comment characters.
How do I stop getting this when I press [Enter] after typing the abbrev characters?
# ========
#
This is what I did:
" Eat one character matching the given regex from the input stream, e.g. at
" the end of an abbr expansion. (From :help abbreviations)
func Eatchar(pat)
let c = nr2char(getchar(0))
return (c =~ a:pat) ? '' : c
endfunc
set pastetoggle=<F12>
iabbr <silent> sep # ========<F12><CR><F12><C-R>=Eatchar('\r')<CR>
This replaces the user's [Enter] key press with a generated one surrounded by generated key presses that turn paste mode off before and back on afterwards. The final <CR>
completes the <CR>=
sequence.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.