Просте рішення
Введіть :setfiletype
(з пробілом після цього) , а потім натисніть Ctrl-d
.
Докладніше :help cmdline-completion
про автоматичне завершення див. У командному рядку vim.
Складне рішення
Це рішення використовує 'runtimepath'
опцію для отримання всіх доступних каталогів синтаксису, а потім отримує список файлів vimscript у цих каталогах із видаленими розширеннями. Це може бути не найбезпечнішим способом цього, тому покращення вітаються:
function! GetFiletypes()
" Get a list of all the runtime directories by taking the value of that
" option and splitting it using a comma as the separator.
let rtps = split(&runtimepath, ",")
" This will be the list of filetypes that the function returns
let filetypes = []
" Loop through each individual item in the list of runtime paths
for rtp in rtps
let syntax_dir = rtp . "/syntax"
" Check to see if there is a syntax directory in this runtimepath.
if (isdirectory(syntax_dir))
" Loop through each vimscript file in the syntax directory
for syntax_file in split(glob(syntax_dir . "/*.vim"), "\n")
" Add this file to the filetypes list with its everything
" except its name removed.
call add(filetypes, fnamemodify(syntax_file, ":t:r"))
endfor
endif
endfor
" This removes any duplicates and returns the resulting list.
" NOTE: This might not be the best way to do this, suggestions are welcome.
return uniq(sort(filetypes))
endfunction
Потім ви можете використовувати цю функцію будь-яким способом, наприклад, друкуючи всі значення у списку. Ви можете це зробити так:
for f in GetFiletypes() | echo f | endfor
Зауважте, що це, ймовірно, може бути досить ущільнено, це просто так для читабельності. Я не буду пояснювати будь-яку функцію та команду, що використовується тут, але ось усі довідкові сторінки для них:
:help 'runtimepath'
:help :let
:help :let-&
:help split()
:help :for
:help expr-.
:help :if
:help isdirectory()
:help glob()
:help fnamemodify()
:help add()
:help uniq()
:help sort()
:setfiletype
(тобтоTab
після пробілу). Не впевнений, чи це повний список, чи як зафіксувати його до якогось буфера / файлу.