StevieD
StevieD

Reputation: 7433

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.

Upvotes: 0

Views: 153

Answers (1)

D. Ben Knoble
D. Ben Knoble

Reputation: 4663

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 (e.g., setlocal, map-<buffer>, autocmd pattern <buffer>).

Upvotes: 1

Related Questions