Modularize complex plugin configs. Add folding plugin

This commit is contained in:
juanmagalhaes 2023-08-15 01:18:37 -03:00
parent 1b94c10240
commit aa1b35c68b
4 changed files with 129 additions and 34 deletions

150
lua/plugins/init.lua Normal file
View file

@ -0,0 +1,150 @@
-- Here is where you install your plugins.
-- You can configure plugins using the `config` key.
--
-- You can also configure plugins after the setup call,
-- as they will be available in your neovim runtime.
local plugins = {
-- :Git/:G
'tpope/vim-fugitive',
-- :GBrowse on github
'tpope/vim-rhubarb',
-- Detect tabstop and shiftwidth automatically (Editor Config taken into account)
'tpope/vim-sleuth',
-- This is where plugins related to LSP can be installed.
-- The configuration is done below. Search for lspconfig to find it below.
{
-- LSP Configuration & Plugins
'neovim/nvim-lspconfig',
dependencies = {
-- Automatically install LSPs to stdpath for neovim
{ 'williamboman/mason.nvim', config = true },
'williamboman/mason-lspconfig.nvim',
-- Useful status updates for LSP
-- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})`
{
'j-hui/fidget.nvim',
tag = 'legacy',
opts = {}
},
-- Additional lua configuration, makes nvim stuff amazing!
'folke/neodev.nvim',
},
},
{
-- Autocompletion
'hrsh7th/nvim-cmp',
dependencies = {
-- Snippet Engine & its associated nvim-cmp source
'L3MON4D3/LuaSnip',
'saadparwaiz1/cmp_luasnip',
-- Adds LSP completion capabilities
'hrsh7th/cmp-nvim-lsp',
-- Adds a number of user-friendly snippets
'rafamadriz/friendly-snippets',
},
},
-- Useful plugin to show you pending keybinds.
{
'folke/which-key.nvim',
opts = {}
},
{
-- Theme inspired by Atom
'Mofiqul/dracula.nvim',
priority = 1000,
config = function()
vim.cmd.colorscheme 'dracula'
end,
},
{
-- Set lualine as statusline
'nvim-lualine/lualine.nvim',
-- See `:help lualine.txt`
opts = {
options = {
icons_enabled = true,
theme = 'dracula',
component_separators = '|',
section_separators = { left = '', right = '' },
},
},
},
{
-- Add indentation guides even on blank lines
'lukas-reineke/indent-blankline.nvim',
-- Enable `lukas-reineke/indent-blankline.nvim`
-- See `:help indent_blankline.txt`
opts = {
char = '',
show_trailing_blankline_indent = false,
},
},
-- "gc" to comment visual regions/lines
{
'numToStr/Comment.nvim',
opts = {}
},
-- Fuzzy Finder (files, lsp, etc)
{ 'nvim-telescope/telescope.nvim', branch = '0.1.x', dependencies = { 'nvim-lua/plenary.nvim' } },
-- Fuzzy Finder Algorithm which requires local dependencies to be built.
-- Only load if `make` is available. Make sure you have the system
-- requirements installed.
{
'nvim-telescope/telescope-fzf-native.nvim',
-- NOTE: If you are having trouble with this installation,
-- refer to the README for telescope-fzf-native for more instructions.
build = 'make',
cond = function()
return vim.fn.executable 'make' == 1
end,
},
{
-- Highlight, edit, and navigate code
'nvim-treesitter/nvim-treesitter',
dependencies = {
'nvim-treesitter/nvim-treesitter-textobjects',
},
build = ':TSUpdate',
},
{
"mg979/vim-visual-multi",
branch = "master"
},
-- require plugins with more complex config
require 'plugins.neo-tree',
require 'plugins.nvim-ufo',
require 'kickstart.plugins.autoformat',
-- require 'kickstart.plugins.debug',
-- NOTE: The import below automatically adds your own plugins, configuration, etc from `lua/custom/plugins/*.lua`
-- You can use this folder to prevent any conflicts with this init.lua if you're interested in keeping
-- up-to-date with whatever is in the kickstart repo.
--
-- For additional information see: https://github.com/folke/lazy.nvim#-structuring-your-plugins
{ import = 'custom.plugins' },
}
local pluginOptions = {}
require('lazy').setup(plugins, pluginOptions)

19
lua/plugins/neo-tree.lua Normal file
View file

@ -0,0 +1,19 @@
return {
"nvim-neo-tree/neo-tree.nvim",
branch = "v3.x",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-tree/nvim-web-devicons", -- not strictly required, but recommended
"MunifTanjim/nui.nvim",
},
config = function()
require('neo-tree').setup {
filesystem = {
filtered_items = {
visible = true,
hide_hidden = false
}
},
}
end,
}

92
lua/plugins/nvim-ufo.lua Normal file
View file

@ -0,0 +1,92 @@
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
local function applyFoldsAndThenCloseAllFolds(bufnr, providerName)
require('async')(function()
bufnr = bufnr or vim.api.nvim_get_current_buf()
-- make sure buffer is attached
require('ufo').attach(bufnr)
-- getFolds return Promise if providerName == 'lsp'
local ranges = await(require('ufo').getFolds(bufnr, providerName))
local ok = require('ufo').applyFolds(bufnr, ranges)
if ok then
require('ufo').closeFoldsWith(1)
end
end)
end
return {
"kevinhwang91/nvim-ufo",
dependencies = {
"kevinhwang91/promise-async",
{
"luukvbaal/statuscol.nvim",
config = function()
local builtin = require("statuscol.builtin")
require("statuscol").setup({
relculright = true,
segments = {
{ text = { builtin.foldfunc }, click = "v:lua.ScFa" },
{ text = { "%s" }, click = "v:lua.ScSa" },
{ text = { builtin.lnumfunc, " " }, click = "v:lua.ScLa" },
},
})
end,
},
},
event = "BufReadPost",
opts = {
provider_selector = function()
return { "treesitter", "indent" }
end,
},
init = function()
vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep: ,foldclose:]]
vim.o.foldcolumn = '1'
vim.o.foldnestmax = 1
vim.o.foldlevel = 99
vim.o.foldlevelstart = 1
vim.o.foldenable = true
end,
config = function(_, opts)
local newOpts = {
fold_virt_text_handler = handler
}
for k, v in pairs(newOpts) do opts[k] = v end
require("ufo").setup(newOpts)
vim.api.nvim_create_autocmd('BufRead', {
pattern = '*',
callback = function(e)
applyFoldsAndThenCloseAllFolds(e.buf, 'lsp')
end
})
end,
}