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