Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nginx config syntax highlight support? #8029

Open
sgon00 opened this issue Aug 21, 2023 · 8 comments
Open

nginx config syntax highlight support? #8029

sgon00 opened this issue Aug 21, 2023 · 8 comments
Labels
C-enhancement Category: Improvements

Comments

@sgon00
Copy link

sgon00 commented Aug 21, 2023

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 sgon00 added the C-enhancement Category: Improvements label Aug 21, 2023
@mahor1221
Copy link

mahor1221 commented Aug 23, 2023

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
Copy link
Author

sgon00 commented Aug 23, 2023

@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
Copy link
Author

sgon00 commented Aug 23, 2023

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
Copy link

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.

pub enum FileType {
/// The extension of the file, either the `Path::extension` or the full
/// filename if the file does not have an extension.
Extension(String),
/// The suffix of a file. This is compared to a given file's absolute
/// path, so it can be used to detect files based on their directories.
Suffix(String),
}

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
Copy link

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
Copy link
Author

sgon00 commented Aug 24, 2023

@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
Copy link
Member

kirawi commented Aug 25, 2023

#8006 might address this.

@anoduck
Copy link

anoduck commented Jun 5, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Improvements
Projects
None yet
Development

No branches or pull requests

4 participants