mirror of
https://github.com/jdhao/nvim-config.git
synced 2025-06-08 14:14:33 +02:00
add plugin nvim-ufo
Currently there are display issues that needs to be addressed in nvim core, see https://github.com/kevinhwang91/nvim-ufo/issues/4 .
This commit is contained in:
parent
64a7a23309
commit
20964853a4
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
41
lua/config/nvim-ufo.lua
Normal file
41
lua/config/nvim-ufo.lua
Normal file
@ -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
|
||||
})
|
||||
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user