Code Monkey home page Code Monkey logo

nginx.vim's Introduction

nginx.vim

Description

Vim plugin for Nginx

Features

The plugin is based on the recent vim-plugin distributed with nginx-1.12.0 and additionally features the following syntax improvements:

  • Highlight IPv4 and IPv6 addresses
  • Mark insecure ssl_protocols as errors
  • Inline template syntax highlight for ERB and Jinja
  • Inline syntax highlight for LUA
  • Improve integer matching
  • Syntax highlighting for proxy_next_upstream options
  • Syntax highlighting for sticky options
  • Syntax highlighting for upstream server options
  • More to come!

Furthermore:

  • Remove annoying delimiters, resulting in strange word-boundaries

Note: Also check out sslsecure.vim: it supports highlighting insecure SSL/TLS cipher suites and protocols in all your files!

Screenshots

A server block with highlighting of insecure ssl_protocol options: nginx server block with SSL configuration

An upstream block with highlighted options: nginx upstream configuration

Embedded highlighting for ERB and Jinja templates: Embedded highlighting for ERB and Jinja templates

Embedded LUA syntax highlighting: Embedded LUA syntax highlighting

References

  • Based on the original nginx-1.12.0/contrib/vim
  • IPv4 and IPv6 address highlighting, based on expressions found in this forum post
  • Blog post introducing this plugin including some more examples

For help with secure cipher selection, visit Mozillas SSL Configuration Generator

Installation

If your Vim is at version 8 or later, the first method below is the quickest. Otherwise, install this plugin with any Vim plugin manager (vim-plug is recommended).

Native plugin management (Vim 8+)

Clone or submodule this repo into your Vim packages location. Example:

mkdir -p ~/.vim/pack/plugins/start
cd ~/.vim/pack/plugins/start
git clone https://github.com/chr4/nginx.vim.git

Plug

Plug 'chr4/nginx.vim'

Dein.vim

call dein#add('chr4/nginx.vim')

Vundle

Plugin 'chr4/nginx.vim'

Pathogen

git clone https://github.com/chr4/nginx.vim ~/.vim/bundle/nginx.vim

Optionally, if you like Jinja template syntax highlighting, install lepture/vim-jinja, too.

License

Copyright (c) Chris Aumann. Distributed under the same terms as Vim itself. See :help license.

nginx.vim's People

Contributors

chr4 avatar dkearns avatar flosacca avatar hongquan avatar nicklinnell avatar nrobinaubertin avatar observeroftime avatar pappasam avatar rjanata avatar sollie avatar tkaden4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nginx.vim's Issues

`/*` breaks indenting

First off, thank you for publishing this plugin—syntax highlighting is super nice to have.

However, I've had to turn off indenting because of how the plugin deals with /*. I often use patterns like include /etc/nginx/conf.d/*.nginx but it seems that cindent treats this as the start of a multi-line comment and ruins the formatting for the entire file.

Not being much of a vim wizard, I can't find a solution to fix it myself and create a PR so I'm hoping someone else can fix it.

image

Comment and TODO

I noticed that you haven't exactly supported comment (much less TODO/FIXME) yet.

I know for a fact that nginx.conf shares a very strong resemblance to ISC Bind9 named.conf configuration file's syntax.

I've been working on the vim-syntax-bind-named highlighter for this named.conf file. And it's pretty ALPHA at that point.

Maybe this snippet for your Vim syntax/nginx.vim will jumpstart you:

hi link namedError  Error
syn match namedError /[^;{#]$/

hi link namedToDo Todo
syn keyword namedToDo xxx contained XXX FIXME TODO TODO: FIXME:

syn region namedQuotedString start=/"/ skip=/\\"/ end=/"/ contained
syn region namedQuotedString start=/'/ skip=/\\'/ end=/'/ contained

" --- Other variants of strings
"  filespec = '_-.+~@$%^&*()=[]\\|:<>`?'  " no curly braces nor semicolon
"  filespec = can be unquoted but no space char allowed
hi link namedFilespec   String
syn match namedFilespec contained /[{}<>\|:;"'a-zA-Z0-9_\.\-\/\\]\+[^;]/ contains=namedQuotedString skipwhite skipempty skipnl 

hi link namedComment    Comment
syn match namedComment "//.*" contains=namedToDo
syn match namedComment "#.*" contains=namedToDo
syn region namedComment start="/\*" end="\*/" contains=namedToDo
syn match namedInclude /\_s*include/
\ nextgroup=namedFilespec,namedError
\ skipwhite

"gzip on" is marked as an error

I’m not sure if this is an oversight or an intentional feature 😄 I tried adding the following directive to a location block:

gzip on;

and the on was highlighted as an error. I notice that the syntax file includes

hi link ngxGzipOff ngxBoolean
hi link ngxGzipOn Error

I’m curious: why do you consider enabling gzip to be an error?

Some config files not highlighting correctly

This is cool, I've been looking for something like this for awhile. I noticed that some of my configuration files are not getting picked up by the syntax highlighter.

For example, I created a config file called test.conf and tried to apply some of the same configuration that is working in another file that is named nginx.conf.

Here is a sample snippet of the code that isn't working for me in the test.conf file.

worker_processes 1;

events {
    worker_connections 20000;
    multi_accept on;
}

http {
    # Dummy setting
    keepalive_timeout 0;

    server {
        listen 80;
    }
}

Embedding LUA breaks the syntax highlighting

When I am embedding LUA code in nginx.conf highlights breaks.

pid /tmp/nginx.pid;

daemon off;

worker_processes 48;

worker_rlimit_nofile 20821;

worker_shutdown_timeout 240s ;

events {
	multi_accept        on;
	worker_connections  16384;
	use                 epoll;
}

http {
	lua_package_path "/etc/nginx/lua/?.lua;;";
	
	lua_shared_dict balancer_ewma 10M;
	lua_shared_dict balancer_ewma_last_touched_at 10M;
	lua_shared_dict balancer_ewma_locks 1M;
	lua_shared_dict certificate_data 20M;
	lua_shared_dict certificate_servers 5M;
	lua_shared_dict configuration_data 20M;
	lua_shared_dict ocsp_response_cache 5M;
	
	server {
		listen 127.0.0.1:10247;
		
		access_log off;
		
        content_by_lua_block {
            ngx.say('Hey!')
	}
    }
	
	# TCP services
	
	# UDP services
	
}

using VimR Version 0.43.0 (20221115.195322), which itself is using NeoVim 0.8.1
is rendered as follow:

immagine

there are different problems and I don't know if they are related or not:

  • closed parenthesis is always grouped as luaParenError.

  • It looks like the ngxLua region starts but doesn't end with the matching } (i.e. the lines starting with # in the NGINX part, later on, are not marked as comments).

Reindentation adds extra tab on `# comments` for the next line

This has been bugging me for a while now, let's say you have the following config:

http {
  server {
    listen 80; # moo
    listen 443 ssl;

    server_name test;
  }
}

And you want to reindent the file with vim, by doing gg=G, this syntax will move every next line after the comment by a tab, for some reasons, and it will turn into:

http {
  server {
    listen 80; # moo
      listen 443 ssl;

    server_name test;
  }
}

Add support for http2 directive

Changes with nginx 1.25.1                                        13 Jun 2023

    *) Feature: the "http2" directive, which enables HTTP/2 on a per-server
       basis; the "http2" parameter of the "listen" directive is now
       deprecated.

    *) Change: HTTP/2 server push support has been removed.

    *) Change: the deprecated "ssl" directive is not supported anymore.

    *) Bugfix: in HTTP/3 when using OpenSSL.


Changes with nginx 1.25.0                                        23 May 2023

    *) Feature: experimental HTTP/3 support.

Would be great to do syntax highlighting for the http2 directive.

Installation should mention ~/.vim/plugin

https://github.com/chr4/nginx.vim#installation
Anyone with a package manager for vim should know how to use their package manager. Those not using one may never have installed a vim plugin before so the first entry listed in installation should be vim's own default location: ~/.vim/plugins

Thanks for making the file btw, made it really convenient to see syntax highlighting on a remote server with a minimal install.

Submodule referencing your plugin not finding commit

This is more of a question than it is an issue. I'm wondering if you might be able to help.
I'm attempting to use this .vim dotfiles repo: https://github.com/jessfraz/.vim
It references your plugin and the following commit:
https://github.com/chr4/nginx.vim/tree/a3def0ecd201de5ea7294cf92e4aba62775c9f5c
Yet, when I attempt to do:
git submodule update --init I get a failure of the following:
error: Server does not allow request for unadvertised object a3def0e
Fetched in submodule path 'bundle/nginx.vim', but it did not contain a3def0e. Direct fetching of that commit failed.
Any ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.