2
votes

I have:

$ vim --version
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Dec  1 2011 03:25:24)

using Debian testing.

I was playing around with an old manpage I wrote and noticed that vim (I used gedit to write it initially but have switched to vim) is not recognizing it as a nroff/groff filetype upon loading or with a:

:filetype detect

It does syntax highlighting fine, of course, with:

:set filetype=groff

Anyone else have this behaviour and if so find a fix?

BTW, it recognizes html, bash, and python scripts correctly and sets the correct syntax highlighting. Just seems to balk at groff files that are saved without the [FILENAME].1-type suffix.

Cheerio, Narnie

2
Does your ~/.vimrc include any filetype commands? (Look in the autocmd commands too -- it might not be the first word on the line.)sarnold
Yes, filetype plugin on is set. Other filetypes are recognized fine.narnie
My ~/.vimrc also has filetype on, filetype indent on, filetype plugin on and gets the filetype correct when testing with e.g. /usr/share/man/man1/ls.1.gz. (Vim 7.3, but Ubuntu packaged.)sarnold
Ur right, mine recognizes /usr/share/man/man1/ls.1.gz as well, but I'll bet it is based on the filename. I normally don't follow the convention of .sh, .py, or .1 when initially writing my scripts, python code, and manpages, respectively. Perhaps the filetype detection only relies of file suffix rather than content. It does so with bash and python scripts by content, not relying on file suffix.narnie

2 Answers

2
votes

Vim can detect the filetype based on both the name of the file and the context. It appears that in this case vim only looks at the file name. You can write your own filetype detection script to figure out files of this type based on the context. The vim's help has some basic instructions on how to do this. Basically you can just write a vim script that detects the file type and put it in $VIMRUNTIME/scripts.vim.

2
votes

Add in your ~/.vimrc file:

au BufNewFile,BufRead *.groff set filetype=groff

Or whatever extension you're using to define your groff files.