Vim: Filetype plugin setlocal options for comments and commentstring not appearing in buffer

198 Views Asked by At

I'm using Vim 9.0 on Windows 10.

I've created a new filetype called 'projects' but setting local options for comments is not working. Here is what I've done:

  1. I added the line :filetype plugin indent on to my vimrc file.

  2. The :filetype command returns: filetype detection:ON plugin:ON indent:ON.

  3. I then created a filetype file called project.vim in a new directory called ftdetect in the first item of runtimepath (~/vimfiles).

  4. In the project.vim file I added the autocommand line to enable filetype detection:

    au BufNewFile,BufRead *project   setf project
    
  5. I then created a filetype plugin file called project.vim in a new directory called ftplugin in the first item of runtimepath (~/vimfiles). In that file I added the following setlocal options for comments:

    setlocal comments=:# commentstring=#\ %s formatoptions-=t formatoptions+=croql
    
  6. As neither the directory ftdetect or ftplugin were appearing in the output of :set runtimepath?, I added this line to my vimrc:

    set rtp+=~/vimfiles/ftdetect,~/vimfiles/ftplugin
    
  7. After I did this the output of :set runtimepath? included those previously missing directories as the last listed items:

    runtimepath=
     ~/vimfiles,
     ~\vimfiles\pack\plugins\start\VOoM,
     ~\vimfiles\pack\plugins\start\vimroom,
     ~\vimfiles\pack\plugins\start\vim-shell-master,
     ~\vimfiles\pack\plugins\start\vim-obsession-master,
     ~\vimfiles\pack\plugins\start\vim-misc-master,
     ~\vimfiles\pack\plugins\start\vim-addon-mw-utils,
     ~\vimfiles\pack\plugins\start\utl,
     ~\vimfiles\pack\plugins\start\tlib_vim,
     ~\vimfiles\pack\plugins\start\taskpaper.vim-master,
     ~\vimfiles\pack\plugins\start\tabular,
     ~\vimfiles\pack\plugins\start\supertab,
     ~\vimfiles\pack\plugins\start\limelight,
     ~\vimfiles\pack\plugins\start\goyo,
     ~\vimfiles\pack\plugins\start\ctrlpcache,
     ~\vimfiles\pack\plugins\start\ctrlp,
     C:\Program Files (x86)\Vim/vimfiles,
     C:\Program Files (x86)\Vim\vim90,
     ~\vimfiles\pack\plugins\start\tabular\after,
     C:\Program Files (x86)\Vim/vimfiles/after,
     ~/vimfiles/after,
     ~/vimfiles/ftdetect,
     ~/vimfiles/ftplugin
    
  8. I then created a test file with the project filetype extension and entered some text, but it was not commented as per the setlocal option (ie: the text in lines prepended with # should be italicized).

  9. I ran the command :set ft? on the test file, which returned filetype=project. When I change the filetype to set ft=conf the comments appear as expected. The filetype file for 'conf' has identical setlocal options for comments.

  10. I added a setlocal option for a statusline to ~/vimfiles/ftplugin/project.vim. The corresponding statusline became present in the test file. Running the :set ft? command indicated returned filetype=project as before.

  11. I am a now a bit stuck and would welcome any help.

1

There are 1 best solutions below

10
Matt On

(6) and (7) are unneeded and useless. Only "vimfiles" must be in runtimepath. "ftdetect" and "ftplugin" are always taken relative to it.

(8) Syntax does not have anything to do with options you set. Instead, you have to create regexes and enable syntax support. How to do it is a topic of its own, so you're adviced to start long reading at :h syntax and all such.