From ee38046ebc83b5dc91739a9c2a8d60cd9725e206 Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 13 Jun 2023 22:24:31 +0200 Subject: [PATCH] Add folding support for JSON files --- after/ftplugin/json.vim | 6 ++++++ lua/config/treesitter.lua | 2 +- plugin/command.vim | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) 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..90db3ec --- /dev/null +++ b/after/ftplugin/json.vim @@ -0,0 +1,6 @@ +" let the initial folding state be that all folds are closed. +set foldlevel=0 + +" Use nvim-treesitter for folding +set foldmethod=expr +set foldexpr=nvim_treesitter#foldexpr() diff --git a/lua/config/treesitter.lua b/lua/config/treesitter.lua index 92759d3..ee07b83 100644 --- a/lua/config/treesitter.lua +++ b/lua/config/treesitter.lua @@ -1,5 +1,5 @@ require("nvim-treesitter.configs").setup { - ensure_installed = { "python", "cpp", "lua", "vim" }, + ensure_installed = { "python", "cpp", "lua", "vim", "json" }, ignore_install = {}, -- List of parsers to ignore installing highlight = { enable = true, -- false will disable the whole extension diff --git a/plugin/command.vim b/plugin/command.vim index 5ed7b73..68b11f4 100644 --- a/plugin/command.vim +++ b/plugin/command.vim @@ -45,3 +45,6 @@ function! s:md_to_pdf() abort echoerr "Error running command" endif endfunction + +" json format +command! -range JSONFormat ,!python -m json.tool