-1

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.

Rocco
  • 471
  • 1
  • 3
  • 7
user2962912
  • 69
  • 1
  • 6

1 Answers1

1

(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.

Matt
  • 13,674
  • 1
  • 18
  • 27
  • So if (6) is unnecessary then it can be omitted, and files in both the `ftplugin` and `ftdetect` folder will still be read in the `runtimepath`? If so then why does neither folder appear in the `set rtp?` command unless I include step (6)? Regarding (8) - the comments and commentstring are `set local options`. `:h syntax` does appear to cover those. Also, the set options I used are identical to those that appear in the `conf.vim` filetype, and they work in the latter case - why is that? – user2962912 May 30 '23 at 10:25
  • @user2962912 The files will be found anyway; the options don't have anything to do with syntax. – Matt May 30 '23 at 10:49
  • Yes. So it should be possible to define a `set local` option for `comments` and `comment` string. If the `ftplugin` and `ftdetect` folder can be detected in the `runtimepath` without having to do step (6) that helps. I've yet to test it but will do later. In any case it seems prima facie quite reasonable expect the output of `set rtp?` to include those folders? It would be interesting to know why. – user2962912 May 30 '23 at 11:09
  • @user2962912 The files are found relative to "vimfiles". This is why "ftdetect" _must_ be named "ftdetect", and "ftplugin" _must_ be named "ftplugin". – Matt May 30 '23 at 11:21
  • Yes those are the names that I gave the folders. The fact that the directories are found relative to `vimfiles` does not self-evidently explain why they would not appear in the output of `set rtp?` if they have been found on the `runtimepath`. But this feels like a digression at this point, given that the files should be found regardless. The question regarding `set local` options for `comment` and `commentstring` remains. – user2962912 May 30 '23 at 11:30
  • @user2962912 1) It is nowhere implied that they should. 2) I've already said that three times in a row: you can set or reset these options but they never affect syntax highlighting in any way. RTFM. – Matt May 30 '23 at 11:56
  • 1) Whether or not that is the case ( and I see no indication of that beyond your assertion) does not really answer the question. 2) To clarify my question is not about syntax highlighting. I want to set local option` for `comment` and `commentstring`. Can anyone else help? – user2962912 May 30 '23 at 12:12
  • @user2962912 1) That's not a question, actually. For some obscure reason you assert that they must be there but they don't/shouldn't. 2) The options should be set okay, and you can go and simply check that. – Matt May 30 '23 at 12:35
  • Thanks Matt. I'd welcome support from anyone else specifically on the `setlocal` `comment` `commentstring` issue for a custom `filetype` as set out so far. I can provide further detail if that helps or raise a new question that links back to this one. Thanks again Matt - I'd really appreciate hearing other voices on this one. – user2962912 May 30 '23 at 12:56
  • @user2962912 A mutual feeling. Never met a person so smart in my life before. Hope you'll find someone more patient to repeat the same stuff to you a hudred times more until you finally get it. – Matt May 30 '23 at 13:36