0

I want to write a custom fold-method file for .paul files (based on the example at Learn Vimscript the Hard Way). However, it appears that my folding.vim file is being ignored.

I'm running VIM version 8.2.1972 (on mac os 11.2.3)

  • ~/.vimrc contains nothing but syntax on

  • ~/.vim/filetype.vim contains

" my filetype file
        if exists("did_load_filetypes")
          finish
        endif
        augroup filetypedetect
          au! BufRead,BufNewFile *.txt         setfiletype txt
          au! BufRead,BufNewFile *.paul        setfiletype paul
        augroup END
  • ~/.vim/ftplugin/paul/folding.vim contains
    set foldmethod=expr

If I do vim sadf.paul then :set ft? returns filetype=paul so the filetype detection is working.

However, :set foldmethod? returns foldmethod=manual, whereas I had expected to see foldmethod=expr.

As a test, I then changed folding.vim to contain set foldmethod=bogus to see if I would get an error when the file was processed.

However, I see no error from the =bogus statement in .vim/ftplugin/paul/folding.vim, which makes me think that the file is never being sourced/run. And, per the suggestion from Christian Brabandt, running :scriptnames confirms that ~/.vim/ftplugin/paul/folding.vim was not sourced.

Any ideas what I'm doing wrong?

6
  • check with :scriptnames if your file is actually being sourced Commented Apr 20, 2021 at 5:51
  • 3
    1. You should not create filetype.vim. Use ftdetect instead. 2. Must have at least filetype plugin on.
    – Matt
    Commented Apr 20, 2021 at 7:12
  • 1
    Welcome to Vi and Vim! You should not post answers in the question—instead, post them in an answer which can be separately voted on/accepted. Consider taking the tour and checking out How to Ask and How to Answer. I’ve edited your question for clarity and removed the answer; you can find it if you wish to post it as an answer in the history. (Our long-time members should know to avoid answering in the comments, which are for clarification.)
    – D. Ben Knoble
    Commented Apr 20, 2021 at 13:28
  • Also, you should consider using setlocal for filetype plugins.
    – D. Ben Knoble
    Commented Apr 20, 2021 at 13:32
  • Check output of the :filetype command, I bet you have plugin:OFF and that's what's causing the problem. You can fix that by adding filetype plugin indent on to your vimrc file. Or you can delete your vimrc file, which will make Vim load the defaults.vim file which enables that setting. (See :help defaults.vim for more details. You can also explicitly load defaults.vim from your vimrc, if you want more customizations.) Let me know if that solves the problem, in that case I'll post it as an answer. Cheers!
    – filbranden
    Commented Apr 21, 2021 at 5:44

1 Answer 1

0

This answer is from Matt. Copied here from his comment.

  1. You should not create filetype.vim. Use ftdetect instead.
  2. Must have at least filetype plugin on
1
  • 1
    This was the answer I needed, specifically #2. I added filetype plugin on in my .vimrc and now I see the correct response from :set foldmethod?. Also, :scriptnames now shows that ~/.vim/ftplugin/paul/folding.vim has been sourced. Per Matt's advice (in #1) I also got rid of .vim/filetime.vim and instead created .vim/ftdetect/paul.vim Thanks, everyone, for the prompt and helpful responses!
    – paulSFO
    Commented Apr 21, 2021 at 21:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.