Почему форматирование в моем ftplugin применяется ко всем файлам в каждом формате?

Я создал собственный формат файла, .cheat, для моих шпаргалок, и только в этом формате я выделяю чередующиеся строки, чтобы было легче увидеть, какое сочетание клавиш запускает каждую команду. Почему форматирование в моем ftplugin применяется ко всем файлам в каждом формате?

Ключевые строки из ~/.vim/vimrc:

set nocompatible                                                                                                        
au BufNewFile,BufRead *.cheat set filetype=cheat
filetype off 
" vundle stuff
filetype on
nmap <leader>? :75vsp ~/.vim/my.cheat

(Полный vimrc ниже для справки.)

Полный ~/.vim/ftdetect/cheat.vim:

if exists("b:did_load_filetypes") | finish | endif                                                                      
let b:did_ftplugin = 1                                       
au BufNewFile,BufRead *.cheat set filetype=cheat

syn match Oddlines "^.*$" contains=ALL nextgroup=Evenlines skipnl  
syn match Evenlines "^.*$" contains=ALL nextgroup=Oddlines skipnl
hi Oddlines ctermbg=DarkGray ctermfg=White
hi Evenlines ctermbg=LightGray ctermfg=White

Полный ~/.vim/vimrc:

set nocompatible
au BufNewFile,BufRead *.cheat set filetype=cheat                                                                                                
filetype off 
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
  Plugin 'VundleVim/Vundle.vim'
  Plugin 'dracula/vim'
  Plugin 'vim-airline/vim-airline'
  Plugin 'tpope/vim-commentary'
  Plugin 'neilagabriel/vim-geeknote'
  Plugin 'tpope/vim-fugitive'
  Plugin 'moll/vim-node'
  Plugin 'danro/rename.vim'
  Plugin 'vim-syntastic/syntastic'
  set statusline+=%#warningmsg#
  set statusline+=%{SyntasticStatuslineFlag()}
  set statusline+=%*
  let g:syntastic_always_populate_loc_list=1
  let g:syntastic_auto_loc_list=1
  let g:syntastic_check_on_open=1
  let g:syntastic_check_on_wq=0
call vundle#end() 
filetype plugin indent on 
set number
set wrap
set breakindent
set autoindent
set shiftwidth=2
set linebreak
set nolist
set cursorline
set cursorcolumn
set ruler
set laststatus=2
set timeoutlen=1000 ttimeoutlen=0
set splitright
hi CursorLine  cterm=NONE ctermbg=Black ctermfg=None
hi CursorColumn cterm=NONE ctermbg=Black ctermfg=None
set updatetime=200
au CursorHold * silent! update
nmap <CR> o<Esc>
nmap <leader>? :75vsp ~/.vim/my.cheat

1 ответ

Решение

Ваш ftdetect/cheat.vim должен содержать только следующее:

au BufNewFile,BufRead *.cheat set filetype=cheat

В то время как остальные конфигурации вы должны поместить в ftplugin/cheat.vim:

if exists("b:did_ftplugin") | finish | endif
let b:did_ftplugin = 1

syn match Oddlines "^.$" contains=ALL nextgroup=Evenlines skipnl
syn match Evenlines "^.$" contains=ALL nextgroup=Oddlines skipnl
hi Oddlines ctermbg=DarkGray ctermfg=White
hi Evenlines ctermbg=LightGray ctermfg=White
Другие вопросы по тегам