From 7bfa6da6033508b45b84b882eca61daa0a150a86 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Sun, 11 Sep 2016 13:00:08 +0100 Subject: [PATCH] Add custom fold functions for json --- after/ftplugin/json.vim | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 after/ftplugin/json.vim diff --git a/after/ftplugin/json.vim b/after/ftplugin/json.vim new file mode 100644 index 0000000..3f08013 --- /dev/null +++ b/after/ftplugin/json.vim @@ -0,0 +1,24 @@ +" Set custom fold expression +setlocal foldmethod=expr +setlocal foldexpr=JsonFold(v:lnum) + +" Custom fold function +function! JsonFold(lnum) + let l:line = getline(a:lnum) + + if l:line =~ '{' && l:line !~ '}' && l:line !~ '".*{.*"' + return 'a1' + elseif l:line =~ '[' && l:line !~ ']' && l:line !~ '".*].*"' + return 'a1' + elseif l:line =~ '}' && l:line !~ '{' && l:line !~ '".*}.*"' + return 's1' + elseif l:line =~ ']' && l:line !~ '[' && l:line !~ '".*[.*"' + return 's1' + endif + + return '=' +endfunction + +" Override default group names +hi link jsonQuote Operator +hi link jsonKeyword Keyword