add code folding
This commit is contained in:
parent
c091b7b5fe
commit
791068797c
6 changed files with 56 additions and 0 deletions
1
init.lua
1
init.lua
|
@ -31,3 +31,4 @@ require("user.dressing")
|
|||
require("user.cybu")
|
||||
require("user.autocommands")
|
||||
require("user.gps")
|
||||
require("user.ufo")
|
||||
|
|
|
@ -98,6 +98,10 @@ keymap("n", "<leader>u", ":UndotreeToggle<CR>", opts)
|
|||
-- Legendary
|
||||
keymap("n", "<C-p>", ":lua require('legendary').find()<CR>", opts)
|
||||
|
||||
-- UFO
|
||||
keymap("n", "zR", ":lua require('ufo').openAllFolds", opts)
|
||||
keymap("n", "zM", ":lua require('ufo').closeAllFolds", opts)
|
||||
|
||||
-- Insert --
|
||||
|
||||
-- Visual --
|
||||
|
|
|
@ -80,8 +80,13 @@ M.on_attach = function(client, bufnr)
|
|||
attach_navic(client, bufnr)
|
||||
end
|
||||
|
||||
-- Define Capabilities
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
capabilities.textDocument.completion.completionItem.snippetSupport = true
|
||||
capabilities.textDocument.foldingRange = {
|
||||
dynamicRegistration = false,
|
||||
lineFoldingOnly = true
|
||||
}
|
||||
|
||||
local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
|
||||
|
||||
|
|
|
@ -37,6 +37,11 @@ vim.opt.colorcolumn = "120"
|
|||
vim.opt.list = true
|
||||
vim.opt.listchars:append("lead:.")
|
||||
vim.opt.winbar = "%{%v:lua.require'user.winbar'.get_winbar()%}"
|
||||
vim.opt.foldcolumn = "2"
|
||||
vim.opt.foldlevel = 99
|
||||
vim.opt.foldlevelstart = -1
|
||||
vim.opt.foldenable = true
|
||||
vim.opt.fillchars = [[eob: ,fold: ,foldopen:,foldsep: ,foldclose:]]
|
||||
|
||||
vim.cmd("set whichwrap+=<,>,[,],h,l")
|
||||
vim.cmd([[set iskeyword+=-]])
|
||||
|
|
|
@ -46,6 +46,7 @@ return packer.startup(function(use)
|
|||
use("nvim-lua/plenary.nvim")
|
||||
use("kyazdani42/nvim-web-devicons")
|
||||
use("antoinemadec/FixCursorHold.nvim")
|
||||
use("kevinhwang91/promise-async")
|
||||
|
||||
-- Themes
|
||||
use("shaunsingh/nord.nvim")
|
||||
|
@ -79,6 +80,7 @@ return packer.startup(function(use)
|
|||
use("glepnir/lspsaga.nvim")
|
||||
use("Maan2003/lsp_lines.nvim")
|
||||
use("SmiteshP/nvim-navic")
|
||||
use("kevinhwang91/nvim-ufo")
|
||||
|
||||
-- Telescope
|
||||
use("nvim-telescope/telescope.nvim")
|
||||
|
|
39
lua/user/ufo.lua
Normal file
39
lua/user/ufo.lua
Normal file
|
@ -0,0 +1,39 @@
|
|||
local status_ok, ufo = pcall(require, "ufo")
|
||||
if not status_ok then
|
||||
return
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
ufo.setup({
|
||||
provider_selector = function()
|
||||
return { "lsp", "indent" }
|
||||
end,
|
||||
fold_virt_text_handler = handler,
|
||||
})
|
Reference in a new issue