diff --git a/core/options.vim b/core/options.vim index 64664280..e06534c9 100644 --- a/core/options.vim +++ b/core/options.vim @@ -1,7 +1,7 @@ scriptencoding utf-8 " change fillchars for folding, vertical split, end of buffer, and message separator -set fillchars=fold:\ ,vert:\│,eob:\ ,msgsep:‾ +set fillchars=fold:\ ,foldopen:,foldsep:\ ,foldclose:,vert:\│,eob:\ ,msgsep:‾ " Paste mode toggle, it seems that Nvim's bracketed paste mode " does not work very well for nvim-qt, so we use good-old paste mode diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index 7736ae63..2e825335 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -79,6 +79,11 @@ local capabilities = lsp.protocol.make_client_capabilities() capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities) capabilities.textDocument.completion.completionItem.snippetSupport = true +capabilities.textDocument.foldingRange = { + dynamicRegistration = false, + lineFoldingOnly = true +} + local lspconfig = require("lspconfig") if utils.executable('pylsp') then diff --git a/lua/config/nvim-ufo.lua b/lua/config/nvim-ufo.lua new file mode 100644 index 00000000..9e42547d --- /dev/null +++ b/lua/config/nvim-ufo.lua @@ -0,0 +1,41 @@ +vim.o.foldcolumn = '1' +vim.o.foldlevel = 99 -- Using ufo provider need a large value, feel free to decrease the value +vim.o.foldlevelstart = 99 +vim.o.foldenable = true + +-- Using ufo provider need remap `zR` and `zM`. If Neovim is 0.6.1, remap yourself +vim.keymap.set('n', 'zR', require('ufo').openAllFolds) +vim.keymap.set('n', 'zM', require('ufo').closeAllFolds) + +local handler = function(virtText, lnum, endLnum, width, truncate) + local newVirtText = {} + local suffix = ('  %d '):format(endLnum - lnum) + local sufWidth = vim.fn.strdisplaywidth(suffix) + local targetWidth = width - sufWidth + local curWidth = 0 + for _, chunk in ipairs(virtText) do + local chunkText = chunk[1] + local chunkWidth = vim.fn.strdisplaywidth(chunkText) + if targetWidth > curWidth + chunkWidth then + table.insert(newVirtText, chunk) + else + chunkText = truncate(chunkText, targetWidth - curWidth) + local hlGroup = chunk[2] + table.insert(newVirtText, {chunkText, hlGroup}) + chunkWidth = vim.fn.strdisplaywidth(chunkText) + -- str width returned from truncate() may less than 2nd argument, need padding + if curWidth + chunkWidth < targetWidth then + suffix = suffix .. (' '):rep(targetWidth - curWidth - chunkWidth) + end + break + end + curWidth = curWidth + chunkWidth + end + table.insert(newVirtText, {suffix, 'MoreMsg'}) + return newVirtText +end + +-- global handler +require('ufo').setup({ + fold_virt_text_handler = handler +}) diff --git a/lua/plugins.lua b/lua/plugins.lua index 6cc47ef6..65d78599 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -357,6 +357,11 @@ packer.startup({ use { 'ii14/emmylua-nvim', ft = 'lua' } use { 'j-hui/fidget.nvim', after = 'nvim-lspconfig', config = [[require('config.fidget-nvim')]]} + + -- quick fold + use {'kevinhwang91/nvim-ufo', after = 'nvim-lspconfig', config = [[require('config.nvim-ufo')]], + requires = 'kevinhwang91/promise-async' + } end, config = { max_jobs = 16,