From 57afc966de5e7ca2d33333bed54de17e2c5350b5 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 8 Mar 2024 22:11:13 +0100 Subject: Adding upstream version 0.20200629. Signed-off-by: Daniel Baumann --- LICENSE | 22 ++++++++++++++++++++++ README.md | 11 +++++++++++ ftdetect/nftables.vim | 11 +++++++++++ ftplugin/nftables.vim | 24 ++++++++++++++++++++++++ indent/nftables.vim | 17 +++++++++++++++++ syntax/nftables.vim | 37 +++++++++++++++++++++++++++++++++++++ 6 files changed, 122 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 ftdetect/nftables.vim create mode 100644 ftplugin/nftables.vim create mode 100644 indent/nftables.vim create mode 100644 syntax/nftables.vim diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0543388 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 nfnty + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..65aaba1 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# vim-nftables + +## Installation + +Recommend [NeoBundle](https://github.com/Shougo/neobundle.vim) for installation. + +Add the following to your vimrc: + +```vim +NeoBundle 'nfnty/vim-nftables' +``` diff --git a/ftdetect/nftables.vim b/ftdetect/nftables.vim new file mode 100644 index 0000000..8936167 --- /dev/null +++ b/ftdetect/nftables.vim @@ -0,0 +1,11 @@ +function! s:DetectFiletype() + if getline(1) =~# '^#!\s*\%\(/\S\+\)\?/\%\(s\)\?bin/\%\(env\s\+\)\?nft\>' + setfiletype nftables + endif +endfunction + +augroup nftables + autocmd! + autocmd BufRead,BufNewFile * call s:DetectFiletype() + autocmd BufRead,BufNewFile *.nft,nftables.conf setfiletype nftables +augroup END diff --git a/ftplugin/nftables.vim b/ftplugin/nftables.vim new file mode 100644 index 0000000..f330cb8 --- /dev/null +++ b/ftplugin/nftables.vim @@ -0,0 +1,24 @@ +if exists('b:did_ftplugin') + finish +endif +let b:did_ftplugin = 1 + +let s:save_cpo = &cpoptions +set cpoptions&vim + +setlocal smartindent nocindent +setlocal commentstring=#%s +setlocal formatoptions-=t formatoptions+=croqnlj + +setlocal comments=b:# + +setlocal tabstop=4 shiftwidth=4 softtabstop=4 expandtab +setlocal textwidth=99 + +let b:undo_ftplugin = ' + \ setlocal formatoptions< comments< commentstring< + \|setlocal tabstop< shiftwidth< softtabstop< expandtab< textwidth< + \' + +let &cpoptions = s:save_cpo +unlet s:save_cpo diff --git a/indent/nftables.vim b/indent/nftables.vim new file mode 100644 index 0000000..02e9c17 --- /dev/null +++ b/indent/nftables.vim @@ -0,0 +1,17 @@ +" Only load this indent file when no other was loaded. +if exists('b:did_indent') + finish +endif +let b:did_indent = 1 + +setlocal cindent +setlocal cinoptions=L0,(0,Ws,J1,j1,+N +setlocal cinkeys=0{,0},!^F,o,O,0[,0] +" Don't think cinwords will actually do anything at all... never mind +setlocal cinwords=table,chain + +" Some preliminary settings +setlocal nolisp " Make sure lisp indenting doesn't supersede us +setlocal autoindent " indentexpr isn't much help otherwise +" Also do indentkeys, otherwise # gets shoved to column 0 :-/ +setlocal indentkeys=0{,0},!^F,o,O,0[,0] diff --git a/syntax/nftables.vim b/syntax/nftables.vim new file mode 100644 index 0000000..f043e2e --- /dev/null +++ b/syntax/nftables.vim @@ -0,0 +1,37 @@ +if exists('b:current_syntax') + finish +endif + +syn match nftablesSet /{.*}/ contains=nftablesSetEntry +syn match nftablesSetEntry /[a-zA-Z0-9]\+/ contained +hi def link nftablesSet Keyword +hi def link nftablesSetEntry Operator + +syn match nftablesNumber "\<[0-9A-Fa-f./:]\+\>" contains=nftablesMask,nftablesDelimiter +syn match nftablesHex "\<0x[0-9A-Fa-f]\+\>" +syn match nftablesDelimiter "[./:]" contained +syn match nftablesMask "/[0-9.]\+" contained contains=nftablesDelimiter +hi def link nftablesNumber Number +hi def link nftablesHex Number +hi def link nftablesDelimiter Operator +hi def link nftablesMask Operator + +syn region Comment start=/#/ end=/$/ +syn region String start=/"/ end=/"/ +syn keyword Function flush +syn keyword Function table chain map +syn keyword Statement type hook +syn keyword Type ip ip6 inet arp bridge +syn keyword Type filter nat route +syn keyword Type ether vlan arp ip icmp igmp ip6 icmpv6 tcp udp udplite sctp dccp ah esp comp icmpx +syn keyword Type ct +syn keyword Type length protocol priority mark iif iifname iiftype oif oifname oiftype skuid skgid rtclassid +syn keyword Constant prerouting input forward output postrouting + +syn keyword Special snat dnat masquerade redirect +syn keyword Special accept drop reject queue +syn keyword Keyword continue return jump goto +syn keyword Keyword counter log limit +syn keyword Keyword define + +let b:current_syntax = 'nftables' -- cgit v1.2.3