Skip to content

Commit

Permalink
nvim-utf 기본설정
Browse files Browse the repository at this point in the history
  • Loading branch information
deptno committed Oct 22, 2023
1 parent 94f9410 commit 38f6c19
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 3 deletions.
12 changes: 10 additions & 2 deletions lua/custom/configs/lspconfig.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
-- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
-- https://github.com/williamboman/mason-lspconfig.nvim/blob/main/doc/server-mapping.md
local configs = require("plugins.configs.lspconfig")
local configs = require("plugins.configs.lspconfig").capabilities
local on_attach = configs.on_attach
local capabilities = configs.capabilities

--- nvim-ufo
local capabilities = configs.capabilities or {}
local textDocument = capabilities.textDocument or {}
textDocument.foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true
}
configs.capabilities = capabilities

local lspconfig = require("lspconfig")
local servers = {
Expand Down
6 changes: 6 additions & 0 deletions lua/custom/init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
vim.o.timeout = true
vim.o.timeoutlen = 150
vim.g.mapleader = ';'

--- nvim-ufo
vim.o.foldcolumn = '1'
vim.o.foldlevel = 99
vim.o.foldlevelstart = 99
vim.o.foldenable = true
29 changes: 29 additions & 0 deletions lua/custom/mappings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,33 @@ M["nvim-notify"] = {
}
}
}
M["nvim-ufo"] = {
n = {
["zR"] = {
function ()
return require('ufo').openAllFolds()
end,
"Open all folds: ufo",
},
["zM"] = {
function ()
return require('ufo').closeAllFolds()
end,
"Close all folds: ufo",
},
["zr"] = {
function ()
return require('ufo').openFoldsExceptKinds()
end,
"Open folds except kinds: ufo",
},
["zm"] = {
function ()
require('ufo').closeFoldsWith()
end,
"Close folds with: ufo",
},
},
}

return M
42 changes: 41 additions & 1 deletion lua/custom/plugins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,45 @@ return {
'chentoast/marks.nvim',
opts = require('custom/configs/marks'),
event = 'VeryLazy',
}
},
{
'kevinhwang91/nvim-ufo',
dependencies = {
'kevinhwang91/promise-async',
'nvim-treesitter/nvim-treesitter'
},
config = function ()
local fold_virt_text_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
require('ufo').setup({
fold_virt_text_handler = fold_virt_text_handler,
})
end,
event = 'VeryLazy'
},
}

0 comments on commit 38f6c19

Please sign in to comment.