irongit

A readme explaining how to make neovim work fast

fixed the comment folding finally

huncholanehuncholaneauthored
parent 7d29516commit 830210844604721b5a17d6be402fed0b1a751fc7Browse files

2 files changed, +33 -6

+31-0lua/config/autocmds/init.lua
@@ -90,3 +90,34 @@ vim.api.nvim_create_user_command("SetTabs", function(opts)
9090 vim.notify("Invalid number", vim.log.levels.ERROR)
9191 end
9292 end, { desc = "Set tab width for current buffer.", nargs = 1 })
93+
94+-- use comments for fold expression
95+-- use comments for fold expression
96+-- use comments for fold expression
97+-- use comments for fold expression
98+_G.CommentFoldExpr = function()
99+ local line = vim.fn.getline(vim.v.lnum)
100+ local cs = vim.bo.commentstring:gsub("%%s", ""):gsub(" ", ""):gsub("([^%w])", "%%%1")
101+ if line:match("^%s*" .. cs) then
102+ return 1
103+ else
104+ return 0
105+ end
106+end
107+local foldexpr = "v:lua.CommentFoldExpr()"
108+vim.api.nvim_create_user_command("UseFoldTreesitter", function()
109+ foldexpr = "v:lua.vim.treesitter.foldexpr()"
110+ vim.opt_local.foldexpr = foldexpr
111+end, { desc = "Set fold expression to treesitter" })
112+vim.api.nvim_create_user_command("UseFoldComment", function()
113+ foldexpr = "v:lua.CommentFoldExpr()"
114+ vim.opt_local.foldexpr = foldexpr
115+end, { desc = "Set foldexpr to comments" })
116+vim.api.nvim_create_autocmd("FileType", {
117+ group = general,
118+ pattern = "*",
119+ callback = function()
120+ vim.opt_local.foldmethod = "expr"
121+ vim.opt_local.foldexpr = foldexpr
122+ end,
123+})
+2-6lua/config/options.lua
@@ -42,11 +42,7 @@ vim.g.snacks_animate = false
4242 -- set normal numbers
4343 vim.cmd("set norelativenumber")
4444
45--- fold settings
46--- fold settings
47--- fold settings
48--- fold settings
49--- fold settings
45+-- fold basic comments
5046 vim.opt.foldmethod = "expr"
5147 vim.opt.foldopen = ""
52-vim.foldexpr = [[getline(v:lnum)=~'^\s*[--|#|//]']]
48+vim.opt.foldexpr = [[getline(v:lnum)=~'^\s*[--|#|//]']]