简体   繁体   中英

vim filetype settings lost when resourcing vimrc

Following the instructions here I have an ftdetect file, ~/.vim/ftdetect/cheat.vim with this line:

au BufNewFile,BufRead *.cheat/* set filetype=cheat

This loads a simple config file at ~/.vim/ftplugin/cheat.vim :

set statusline=%t
set statusline+=\ %P
set statusline+=%#todo#
set nonumber

It loads fine, but when I source ~/.vimrc the settings for cheat.vim are lost.

The best long-term solution is to avoid having your vimrc overwrite filetype settings if executed directly by using local options and similar, but the simplest fix is often to re-edit the file. Type

:edit

And hit Enter.

This can be shortened to just :e in interactive use, and a mapping is easily created:

nnoremap <silent> <leader>e :edit<CR>

I suggest reading the help pages on vim's startup, init files, source command, edit command, and the various ways to tune things local to a single buffer (eg, setlocal , map-<buffer> , autocmd pattern <buffer> ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM