Skip to content

Instantly share code, notes, and snippets.

@ralavay
Last active November 5, 2024 02:16
Show Gist options
  • Save ralavay/c4c7750795ccfd72c2db to your computer and use it in GitHub Desktop.
Save ralavay/c4c7750795ccfd72c2db to your computer and use it in GitHub Desktop.
Enable syntax highlight for Nginx conf file in Vim
#!/bin/bash
#
# Highligh Nginx config file in Vim
# Download syntax highlight
mkdir -p ~/.vim/syntax/
wget http://www.vim.org/scripts/download_script.php?src_id=19394 -O ~/.vim/syntax/nginx.vim
# Set location of Nginx config file
cat > ~/.vim/filetype.vim <<EOF
au BufRead,BufNewFile /etc/nginx/*,/etc/nginx/conf.d/*,/usr/local/nginx/conf/* if &ft == '' | setfiletype nginx | endif
EOF
@fessacchiotto
Copy link

🎉👍🏻

an alternative to filetype.vim file would be having sth like that at the end of nginx config file:

# vi: filetype=nginx

pros: you are not limited to have nginx config in /etc/nginx directory cons: you need to add this modeline to the file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment