0

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
3
  • 1
    Other than wrapping the right-hand side of the autocommand in a function, i can’t think of anything
    – D. Ben Knoble
    Jul 16, 2020 at 2:24
  • 1
    Alternately, create the mappings globally (no autocommand) and then unmap them in ftplugins that dont need them
    – D. Ben Knoble
    Jul 16, 2020 at 2:25
  • "Alternately, create the mappings globally (no autocommand) and then unmap them in ftplugins that dont need them" In that case, it will remove them globally, IOW in all other buffers... Jul 16, 2020 at 8:52

1 Answer 1

3

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>' : '"'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.