vim when editing rc.conf lost color

After several editing of rc.conf vim, I found the colorful syntax has been lost and I don't the cause.

:set filetype?

returns a blank filetype so I manually set the file type to rc. I wish it will persist to work after I save and close. However, the next time I opened the rc.conf via vim it is colorless again. Any idea? Thanks
 
Thank you for your reply. However, my FreeBSD has only a root user and at the ~ directory there is not .vimrc file. Should I create one and add the syntax on line to it?

One important thing: /etc/pf.conf file is completely normally opened in vim. Therefore, this issue seems to be file specific.
 
Should I create one and add the syntax on line to it?
Yes, that's the idea, ~/.vimrc contains your personal settings. You typically also set things like your preferred tab size.

Here's an example:
Code:
set background=dark
set autoindent
set smartindent
set backspace=indent,eol,start
set softtabstop=2
set shiftwidth=2
set noexpandtab
set ruler
syntax on

set nobackup
set noundofile
 
Unfortunately, this method did not work. I have tried the line now. The issue probably is that the vim does not recognize the file type of /etc/rc.conf which should be rc.
 
Odd, I just tested this on a fresh install and it works fine there. Make sure you're actually starting vim(1) not vi(1).

Without syntax on the filetype is indeed empty. But after turning syntax highlighting on the filetype is conf (which would be correct).

What version of FreeBSD are you using and what version is the editors/vim package?
 
Try this in your ~/.vimrc:
Code:
if has("syntax")
        syntax on
        au BufNewFile,BufRead rc.conf set filetype=sh
endif

This sets the filetype for rc.conf specifically to sh (rc.conf is actually a shell script).
 
Thank you. But, the behavior of vim for /etc/rc.conf was fine and the text was colorful. However, I probably did something that I had not recognized to change the behavior of vim for this file. Other file, for example, /etc/pf.conf does not meet this issue. I just want to figure out how to restore the default status.
 
The screenshot below is my rc.conf file. Is there any line that fails the vim filetype detection? I did not take care when this issue happen so I don't know which line causes the vim filetype detection to fail. But I am very certain that the original rc.conf file indeed was recognized by the vim editor.

Screenshot 2023-10-22 at 4.12.24 PM.png
 
my vim config file
Code:
syntax on
set autoindent
set backspace=indent,eol,start
set background=dark
set clipboard+=unnamedplus
set encoding=utf-8
set fileencoding=utf-8
set guioptions+=m
set noexpandtab
set nobackup
set noundofile
set nornu
set norelativenumber
set number
set omnifunc=syntaxcomplete#Complete
set omnifunc=ale#completion#OmniFunc
set ruler
set smartindent
set softtabstop=4
set shiftwidth=4
set signcolumn=yes
set tabstop=4
set termguicolors
 
I added a line at the end of /etc/rc.conf, as shown in the screenshot below, and the syntax highlights got back to work. Therefore, my theory is that the content of the /etc/rc.conf will affect the filetype recognition by vim editor. In other words, the vim editor failed to detect the filetype before because it was not able to tell what the filetype is due to the content.

Screenshot 2023-10-23 at 1.22.24 PM.png
 
And, I think there might have been another possibility to explain the original issue I encountered - The version of the terminal app of the MacOS from which I connected the FreeBSD remotely was likely to play a role in this issue. So, after I upgraded the macOS, the issue resolved.
 
Back
Top