Vim Tips Wiki
Register
(add some context and backlink)
(note about small bug)
 
(6 intermediate revisions by 5 users not shown)
Line 1: Line 1:
  +
{{ScriptComments|nginx: highlight configuration files for nginx web server}}
== Comments, bugs, improvements to syntax script [http://www.vim.org/scripts/script.php?script_id=1886 nginx.vim] ==
 
   
  +
==Debian/Ubuntu installation==
=== Patch to 0.3.1 fixes comment detection ===
 
  +
For installation on Debian/Ubuntu, copy '''nginx.vim''' to '''/etc/vim/syntax''' and add this line to '''/etc/vim/vimrc.local'''
  +
<pre>
  +
au BufRead,BufNewFile /etc/nginx/* set ft=nginx
  +
</pre>
   
 
==Patch to 0.3.1 fixes comment detection==
 
This patch fixes comment detection. Instead of just looking at space characters, it considers all whitespace before a # character. (You can probably edit the one-character change easier than you could apply the patch file.)
 
This patch fixes comment detection. Instead of just looking at space characters, it considers all whitespace before a # character. (You can probably edit the one-character change easier than you could apply the patch file.)
  +
<pre>
 
--- nginx.vim
 
+++ nginx.vim
 
@@ -15,7 +15,7 @@
 
syn region ngxBlock start=+^+ end=+{+ contains=ngxDirectiveBlock,ngxVariableBlock,ngxString oneline
 
syn region ngxString start=+"+ end=+"+ skip=+\\\\\|\\"+ contains=ngxVariableString oneline
 
syn region ngxString start=+'+ end=+'+ skip=+\\\\\|\\'+ contains=ngxVariableString oneline
 
-syn match ngxComment ' *#.*$'
 
+syn match ngxComment '\W*#.*$'
   
 
syn keyword ngxBoolean on
--- nginx.vim
 
 
syn keyword ngxBoolean off
+++ nginx.vim
 
  +
</pre>
@@ -15,7 +15,7 @@
 
  +
syn region ngxBlock start=+^+ end=+{+ contains=ngxDirectiveBlock,ngxVariableBlock,ngxString oneline
 
  +
==Comments==
syn region ngxString start=+"+ end=+"+ skip=+\\\\\|\\"+ contains=ngxVariableString oneline
 
  +
Can't figure out why but comments won't indent correctly. Any ideas? <small>--Preceding [[Vim Tips Wiki:Quick reference|unsigned]] comment added by [[User:92.41.49.48|92.41.49.48]] 19:17, July 9, 2011</small>
syn region ngxString start=+'+ end=+'+ skip=+\\\\\|\\'+ contains=ngxVariableString oneline
 
  +
:Sorry I have not used this script. However, you should say what version you are using and give more information on what you expect and what you saw. [[User:JohnBeckett|JohnBeckett]] 11:41, July 10, 2011 (UTC)
-syn match ngxComment ' *#.*$'
 
  +
+syn match ngxComment '\W*#.*$'
 
  +
There seems to be a small bug in this script where I can't use b and w to skip forward between parts of a file/directory path. I.e., in /dir1/dir2/dir3/filename, b or w doesn't skip backward or forward over each word (noticing slashes) but instead the entire section. Even worse, dw deletes the entire rest of the path instead of just to the next slash. Other than that, this is a great script and I think I might keep using it even with this bug since you just have to delete character by character instead. (Note that this only manifests when editing nginx files, so it won't affect other regular editing.)
 
  +
syn keyword ngxBoolean on
 
  +
I created a git repo from this file to enable me to use it as a pathogen module.
syn keyword ngxBoolean off
 
  +
https://github.com/andersjanmyr/nginx-vim-syntax

Latest revision as of 23:17, 4 July 2012

Use this page to discuss script 1886 nginx: highlight configuration files for nginx web server

  • Add constructive comments, bug reports, or discuss improvements (see the guideline).
  • Do not document the script here (the author should do that on vim.org).
  • This page may be out of date: check the script's vim.org page above, and its release notes.

Debian/Ubuntu installation[]

For installation on Debian/Ubuntu, copy nginx.vim to /etc/vim/syntax and add this line to /etc/vim/vimrc.local

au BufRead,BufNewFile /etc/nginx/* set ft=nginx

Patch to 0.3.1 fixes comment detection[]

This patch fixes comment detection. Instead of just looking at space characters, it considers all whitespace before a # character. (You can probably edit the one-character change easier than you could apply the patch file.)

--- nginx.vim
+++ nginx.vim
@@ -15,7 +15,7 @@
 syn region ngxBlock start=+^+ end=+{+ contains=ngxDirectiveBlock,ngxVariableBlock,ngxString oneline
 syn region ngxString start=+"+ end=+"+ skip=+\\\\\|\\"+ contains=ngxVariableString oneline
 syn region ngxString start=+'+ end=+'+ skip=+\\\\\|\\'+ contains=ngxVariableString oneline
 -syn match ngxComment ' *#.*$'
 +syn match ngxComment '\W*#.*$'

 syn keyword ngxBoolean on
 syn keyword ngxBoolean off

Comments[]

Can't figure out why but comments won't indent correctly. Any ideas? --Preceding unsigned comment added by 92.41.49.48 19:17, July 9, 2011

Sorry I have not used this script. However, you should say what version you are using and give more information on what you expect and what you saw. JohnBeckett 11:41, July 10, 2011 (UTC)

There seems to be a small bug in this script where I can't use b and w to skip forward between parts of a file/directory path. I.e., in /dir1/dir2/dir3/filename, b or w doesn't skip backward or forward over each word (noticing slashes) but instead the entire section. Even worse, dw deletes the entire rest of the path instead of just to the next slash. Other than that, this is a great script and I think I might keep using it even with this bug since you just have to delete character by character instead. (Note that this only manifests when editing nginx files, so it won't affect other regular editing.)

I created a git repo from this file to enable me to use it as a pathogen module. https://github.com/andersjanmyr/nginx-vim-syntax