vim-matchup
vim-matchup copied to clipboard
Feature request: Vim global variable with list of supported filetypes ('abaqus', 'ada', 'aspvbs',...)
How to get the list of all supported filetypes?
Maybe I install in future Tree-sitter, but till then I want in not-supported-filetypes to map i% and a% to an echo that remembers me that this plugin is still not enabled. Thus I coded below hunk. There I copy-pasted from docs the content of g:matchup_supported_filetypes. But if in future that list changes, for example if javascript becomes supported, then I would have to manually edit that list.
Requests:
- [ ] Make the plugin itself provide the list of supported filetypes in a Vim global variable, for example
g:matchup_supported_filetypes - [ ] Or if there's a better approach I am totally open. Maybe
if index(g:matchup_supported_filetypes, &filetype) < 0is not the Vim-ish way, maybe I mix</n/v/x/o>noremapand</n/v/x/o>map,...
" Current filetype support (:h matchup-overview)
" > The following built-in vim filetype plugins
" currently provide support for match-up: >
let g:matchup_supported_filetypes = [
\ 'abaqus', 'ada', 'aspvbs', 'c', 'clojure', 'cobol', 'config',
\ 'context', 'csc', 'csh', 'dtd', 'dtrace', 'eiffel', 'eruby',
\ 'falcon', 'fortran', 'framescript', 'haml', 'hamster', 'hog',
\ 'html', 'ishd', 'j', 'jsp', 'kconfig', 'liquid', 'lua', 'make',
\ 'matlab', 'mf', 'mp', 'ocaml', 'pascal', 'pdf', 'perl', 'php',
\ 'plaintex', 'postscr', 'ruby', 'sh', 'spec', 'sql', 'tex', 'vb',
\ 'verilog', 'vhdl', 'vim', 'xhtml', 'xml', 'zimbu', 'zsh'
\]
" To test another filetype, add it to g:matchup_supported_filetypes
if v:false
let g:matchup_supported_filetypes += ['javascript']
endif
" If no support (without Tree-sitter), then:
" - Disable the plugin entirely
" - Remap most used like 'i%' and 'a%'
" - Do not remap '%' since it's still useful in vanilla Vim, see ':h %'
" > % Find the next item in this line after or under the
" cursor and jump to its match. |inclusive| motion.
if v:false
" Opt. A. Define filetype 1 by 1
au FileType python let b:matchup_enabled = 0
au FileType python xmap i% :<C-u>call MatchupSupportPython()<CR>
au FileType python xmap a% :<C-u>call MatchupSupportPython()<CR>
" au FileType python map % :<C-u>call MatchupSupportPython()<CR>
else
" Opt. B. Every filetype not in g:matchup_supported_filetypes
augroup matchup_auto_disable
autocmd!
autocmd FileType * if index(g:matchup_supported_filetypes, &filetype) < 0 |
\ let b:matchup_enabled = 0 |
\ endif
autocmd FileType * call s:MatchupSetupFallback()
augroup END
endif
fun! s:MatchupSetupFallback()
if index(g:matchup_supported_filetypes, &filetype) < 0
xnoremap <buffer> i% <Esc>:<C-u>call MatchupSupportPython()<CR>
xnoremap <buffer> a% <Esc>:<C-u>call MatchupSupportPython()<CR>
" nnoremap <buffer> % :<C-u>call MatchupSupportPython()<CR>
nnoremap <buffer> % :<C-u>execute "normal! %" <bar> echo "vim-matchup plugin not enabled for this filetype"<CR>
else
call s:MatchupCustomMaps()
endif
endf
fun MatchupSupportPython()
echo "As explained in https://github.com/andymass/vim-matchup/issues/68#issuecomment-917635326"
echo "support for Python, Go,... requires Tree-sitter integration, https://github.com/andymass/vim-matchup#tree-sitter-integration"
echo "and Tree-sitter is:"
echo "- Experimental"
echo "- No easy to install: latest NeoVim, branch 'master' only,..."
echo "- Only guaranteed to work with specific versions of language parsers"
echo "- When upgrading the plugin, you must make sure that all installed parsers are updated to the latest version via :TSUpdate"
echo "Reference: https://github.com/nvim-treesitter/nvim-treesitter?tab=readme-ov-file#installation"
echo "\n"
echo "Supported filetypes:"
echo g:matchup_supported_filetypes
endf
" Custom maps
" ':h matchup-custom-mappings' and https://github.com/andymass/vim-matchup/blob/master/autoload/matchup.vim
fun! s:MatchupCustomMaps()
" https://github.com/andymass/vim-matchup#c4-where-am-i
nnoremap %w :<c-u>MatchupWhereAmI??<CR>
" https://github.com/andymass/vim-matchup/issues/389
xmap <c-o> i%
endf
Thanks in advance!
You can get all the installed queries with vim.api.nvim_get_runtime_file('queries/*/matchup.scm', true), and from that you can extract the list of filetypes.