helix-editor / helix

A post-modern modal text editor.
https://helix-editor.com
Mozilla Public License 2.0
31.84k stars 2.35k forks source link

nginx config syntax highlight support? #8029

Open sgon00 opened 11 months ago

sgon00 commented 11 months ago

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

mahor1221 commented 11 months ago

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.

sgon00 commented 11 months ago

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

sgon00 commented 11 months ago

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.

mahor1221 commented 11 months ago

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.

mahor1221 commented 11 months ago

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.

sgon00 commented 11 months ago

@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. :)

kirawi commented 11 months ago

https://github.com/helix-editor/helix/pull/8006 might address this.

anoduck commented 1 month ago

IMHO, this should be the #1/most important issue that needs to be addressed by the helix development team. Admittedly, writing a syntax file for .conf is not an easy task, due to the amount of variation that occurs in configuration files with that file extension. Every other editor I know of has managed to address it, though.