Vi and Vim Asked on August 31, 2021
I have the following mapping:
augroup MatchingQuotes
autocmd Filetype noremap! ' ''<Left>
autocmd Filetype noremap! " ""<Left>
augroup END
Is there a way to set the Filetype to "everything except vim and markdown" ? If so, how could this be done?
My current solution is as follows but I’m not sure if it’s the cleanest way to do it or if there’s a better way:
" Matching quotes
let FT_IGNORE_QUOTES = ['vim', 'markdown', 'help']
autocmd Filetype * if index(FT_IGNORE_QUOTES, &filetype) == -1 | inoremap <buffer> ' ''<Left>| endif
autocmd Filetype * if index(FT_IGNORE_QUOTES, &filetype) == -1 | inoremap <buffer> " ""<Left>| endif
Just use :h map-<expr>
instead of auto-commands.
let FT_IGNORE_QUOTES = ['vim', 'markdown', 'help']
inoremap <expr>' index(FT_IGNORE_QUOTES, &ft) < 0 ? "''<left>" : "'"
inoremap <expr>" index(FT_IGNORE_QUOTES, &ft) < 0 ? '""<left>' : '"'
Correct answer by Matt on August 31, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP