nginx config syntax highlight support?
Hi, I need to edit nginx config file a lot. Is that possible to enable nginx config syntax highlight? Thanks a lot.
Edited:
I try to replace vim with helix, but I find out helix is missing many file type support. It does not support many linux config file types, such as nginx, systemd etc..
I have the same problem. For a temporary fix, you can try adding this config to ~/.config/helix/languages.toml:
# https://docs.helix-editor.com/languages.html
[[language]]
name = "ini"
file-types = [
"conf",
# from https://github.com/helix-editor/helix/blob/master/languages.toml
"ini", "service", "automount", "device", "mount", "path", "service", "slice", "socket", "swap", "target", "timer", "container", "volume", "kube", "network",
]
[[language]]
name = "bash"
file-types = [
"nginx.conf",
# from https://github.com/helix-editor/helix/blob/master/languages.toml
"sh", "bash", "zsh", ".bash_login", ".bash_logout", ".bash_profile", ".bashrc", ".profile", ".zshenv", "zshenv", ".zlogin", "zlogin", ".zlogout", "zlogout", ".zprofile", "zprofile", ".zshrc", "zshrc", ".zimrc", "APKBUILD", "PKGBUILD", "eclass", "ebuild", "bazelrc", ".bash_aliases", "Renviron", ".Renviron",
]
(The file types can't be extended, related issue: #6896)
The first section will use ini syntax highlighting for files with .conf extension,
and the next one will use bash for nginx.conf.
You can also use toml or ini for Systemd services.
This is not ideal but it does the job for me.
@mahor1221 thanks a lot for the tip. It does the job. I am about to give up helix because of this issue. I am getting headache to switch between vim and helix. Now, let me try to see if I can stay with helix only.
One more question about file-types in languages.toml: is that possible to define a path and everything inside the path will use the configued language? For example, /etc/nginx/sites-enabled/* will be bash language. Thanks a lot.
Unfortunately it seems that that's not possible currently. There is a suffix option to set the filetype for certain paths but it only accepts files not directories.
https://github.com/helix-editor/helix/blob/c9694f680f97823ac9b893239a78bf45bfee0403/helix-core/src/syntax.rs#L160-L167
Personally, I'm using keybindings for commands like :set-language bash, :set-language ini and so on, until this issue is fixed. I don't wanna mess with vim or neovim configs in my lifetime again.
I know a little Rust, so if nobody fixed this issue, I would be happy to work on it myself but I probably can't do it in the upcoming weeks or months.
@mahor1221 thanks a lot for your help. Hopefully, helix team can put more attention on these kind of issues. I think they are very easy to be fixed and improved. It shouldn't take too much time. I don't want to switch between editors all the time. :)
https://github.com/helix-editor/helix/pull/8006 might address this.
Can be closed now that https://github.com/helix-editor/helix/pull/12309#issuecomment-2562888743 is merged