helix icon indicating copy to clipboard operation
helix copied to clipboard

nginx config syntax highlight support?

Open sgon00 opened this issue 2 years ago • 8 comments

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

sgon00 avatar Aug 21 '23 17:08 sgon00

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 avatar Aug 23 '23 13:08 mahor1221

@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 avatar Aug 23 '23 15:08 sgon00

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.

sgon00 avatar Aug 23 '23 15:08 sgon00

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 avatar Aug 24 '23 05:08 mahor1221

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 avatar Aug 24 '23 05:08 mahor1221

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

sgon00 avatar Aug 24 '23 15:08 sgon00

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

kirawi avatar Aug 25 '23 23:08 kirawi

Can be closed now that https://github.com/helix-editor/helix/pull/12309#issuecomment-2562888743 is merged

nik-rev avatar Dec 26 '24 16:12 nik-rev