Skip to content

Plugins

Diego Ulloa edited this page May 23, 2024 · 16 revisions

1. lualine

plugins/lualine.lua

-- require custom extensions
local extensions = require("root.extensions.lualine") -- replace root

return {
  "nvim-lualine/lualine.nvim",
  dependencies = {
    "folke/noice.nvim",
    "nvim-tree/nvim-web-devicons",
  },
  config = function()
    -- require noice
    local noice = require("noice")

    -- require lazy extensions
    local lazy_status = require("lazy.status")

    -- custom setup
    require("lualine").setup({
      options = {
        theme = require("neofusion.lualine"),
        globalstatus = true,
        component_separators = { left = "", right = "" },
        section_separators = { left = "", right = "" },
        disabled_filetypes = { "dashboard", "packer", "help" },
        ignore_focus = {}, -- add filetypes inside
      },
      -- man:124 for sections doc
      sections = {
        lualine_a = { "progress" }, -- disable vim mode viewer
        lualine_b = {
          {
            "branch",
            icon = "", -- disable icon
            padding = { left = 1, right = 1 },
          },
        },
        lualine_c = {
          -- filetype icon
          {
            "filetype",
            icon_only = true,
            padding = { left = 2, right = 0 },
            color = "_lualine_c_filetype",
          },
          -- filename
          {
            "filename",
            file_status = true, -- display file status (read only, modified)
            path = 1, -- 0: just name, 1: relative path, 2: absolute path, 3: absolute path with ~ as home directory
            symbols = {
              unnamed = "",
              readonly = "",
              modified = "",
            },
            padding = { left = 1 },
            color = { gui = "bold" },
          },
        },
        lualine_x = {
          {
            lazy_status.updates,
            cond = lazy_status.has_updates,
          },
          -- number of changes in file
          {
            "diff",
            colored = true,
            padding = { right = 2 },
            symbols = {
              added = "+",
              modified = "|",
              removed = "-",
            },
          },
          -- status like @recording
          {
            noice.api.statusline.mode.get,
            cond = noice.api.statusline.mode.has,
          },
        },
        lualine_y = {},
        lualine_z = { "location" },
      },
      extensions = {
        "nvim-tree",
        "toggleterm",
        "mason",
        "fzf",
        "quickfix",
        "man",
        "lazy",
        -- custom extensions
        extensions.telescope,
        extensions.lspinfo,
        extensions.saga,
        extensions.btw,
      },
    })
  end,
}

a. extensions

extensions/lualine/telescope.lua

-- extension: telescope
local function get_display_name()
  return "Telescope"
end

-- custom extension
local telescope = {
  sections = {
    lualine_a = {
      { get_display_name },
    },
  },
  filetypes = { "TelescopePrompt" },
}

-- export
return telescope

extensions/lualine/lspinfo.lua

-- extension: lsp info
local function get_display_name()
  return "LspInfo"
end

-- custom extension
local lsp_info = {
  sections = {
    lualine_a = {
      { get_display_name },
    },
  },
  filetypes = { "lspinfo" },
}

-- export
return lsp_info

extensions/lualine/saga.lua

-- extension: saga
local function get_display_name()
  local filetype = vim.bo.filetype
  local action = filetype:match("saga(%a+)")

  return "Saga" .. action:gsub("^%l", string.upper)
end

-- custom extension
local saga = {
  sections = {
    lualine_a = {
      { get_display_name },
    },
  },
  filetypes = { "sagaoutline", "sagafinder" },
}

-- export
return saga

extensions/lualine/btw.lua

-- extension: telescope
local function get_display_name()
  return "BTW bitch."
end

-- custom extension
local telescope = {
  sections = {
    lualine_a = {
      { get_display_name },
    },
  },
  filetypes = { "starter" },
}

-- export
return telescope

2. nvim-tree

plugins/nvim-tree.lua

-- recommended settings from nvim-tree documentation
vim.g.loaded = 1
vim.g.loaded_netrwPlugin = 1

-- custom setup
return {
  "nvim-tree/nvim-tree.lua",
  version = "*",
  dependencies = {
    "nvim-tree/nvim-web-devicons",
  },
  opts = {
    view = {
      width = 38,
    },
    renderer = {
      root_folder_label = false, -- hide root directory at the top
      indent_markers = {
        enable = enable, -- folder level guide
        icons = {
          corner = "",
          edge = "",
          item = "",
          bottom = "",
          none = " ",
        },
      },
      icons = {
        glyphs = {
          folder = {
            default = "",
            open = "",
            empty = "",
            empty_open = "",
          },
          git = {
            unstaged = "",
            staged = "",
            unmerged = "",
            renamed = "",
            untracked = "",
            deleted = "",
            ignored = "",
          },
        },
      },
    },
    actions = {
      open_file = {
        quit_on_open = true,
        window_picker = {
          enable = false,
        },
      },
    },
    update_focused_file = {
      enable = true,
      update_root = true,
    },
    filters = {
      dotfiles = true,
    },
    sync_root_with_cwd = true,
    respect_buf_cwd = true,
  },
}

3. bufferline

plugins/bufferline.lua

return {
  "akinsho/bufferline.nvim",
  version = "*",
  dependencies = { "nvim-tree/nvim-web-devicons" },
  config = function()
    -- require bufferline
    local bufferline = require("bufferline")

    -- custom setup
    bufferline.setup({
      options = {
        mode = "tabs", -- only show tabs and not all buffers
        numbers = "ordinal", -- add tabs ordinal numbers
        style_preset = bufferline.style_preset.default, -- default|minimal
        color_icons = true,
        tab_size = 22,
        close_icon = "",
        show_buffer_icons = true,
        show_duplicate_prefix = true, -- show base path if tabs have the same name
        separator_style = "thick", -- slant|slope|thick|thin|{"|", "|"}
        diagnostics = "nvim_lsp", -- nvim lsp diagnostics integration in tabs or false
        indicator = {
          style = "icon", -- icon|underline|none
        },
        offsets = {
          -- avoid to show bufferline on top nvim-tree
          {
            filetype = "NvimTree",
            text = "File Explorer", -- title on top
            highlight = "Directory",
            separator = true, -- true is the default, or set custom
          },
          -- avoid to show bufferline on top saga outline symbols
          {
            filetype = "sagaoutline",
            text = "Symbols", -- title on top
            highlight = "Directory",
            separator = true, -- true is the default, or set custom
          },
        },
        diagnostics_indicator = function(count, level) -- diagnostics format
          return " " .. count
        end,
        -- exclude some buffer and file types
        custom_filter = function(buf_number)
          local buftype = vim.api.nvim_buf_get_option(buf_number, "buftype")
          local filetype = vim.api.nvim_buf_get_option(buf_number, "filetype")

          -- exclude list
          local excluded_filetypes = {
            ["terminal"] = true,
            ["TelescopePrompt"] = true,
            ["NvimTree"] = true,
            ["sagaoutline"] = true,
            ["sagafinder"] = true,
            ["starter"] = true,
          }

          local excluded_buftypes = {
            ["nofile"] = true,
            ["terminal"] = true,
          }

          return not excluded_buftypes[buftype] and not excluded_filetypes[filetype]
        end,
      },
    })
  end,
}

4. telescope

plugins/telescope.lua

return {
  "nvim-telescope/telescope.nvim",
  branch = "0.1.x",
  dependencies = {
    "nvim-lua/plenary.nvim",
    "nvim-telescope/telescope-fzf-native.nvim",
    -- addons
    "ahmedkhalf/project.nvim",
    "olimorris/persisted.nvim",
  },
  cmd = "Telescope",
  config = function()
    -- require telescope
    local telescope = require("telescope")

    -- require telescope actions
    local actions = require("telescope.actions")

    -- load fzf
    telescope.load_extension("fzf")

    -- projects extension integration for telescope
    telescope.load_extension("projects")

    -- persisted extension for session management
    telescope.load_extension("persisted")

    -- custom setup
    telescope.setup({
      defaults = {
        layout_strategy = "vertical", -- vertical layout
        sorting_strategy = "ascending",
        results_title = "",
        prompt_prefix = "", --  ›
        selection_caret = "",
        entry_prefix = "   ", -- each entry result prefix
        layout_config = {
          prompt_position = "top",
          width = 0.7,
          height = 0.6,
        },
        mappings = {
          i = {
            ["<C-k>"] = actions.move_selection_previous,
            ["<C-j>"] = actions.move_selection_next,
            ["<C-q>"] = actions.send_selected_to_qflist + actions.open_qflist,
          },
        },
        -- result numbers at the right: matches|total
        get_status_text = function(picker)
          local total = picker.stats.processed or 0
          local matches = total - (picker.stats.filtered or 0)

          if matches == 0 and total == 0 then
            return ""
          end

          return string.format("%s|%s ", matches, total)
        end,
      },
      pickers = {
        find_files = {
          previewer = false,
          layout_config = {
            prompt_position = "top",
            width = 0.6,
            height = 0.5,
          },
        },
        live_grep = {
          previewer = false,
          prompt_title = "Global Search",
          results_title = "", -- results
          layout_config = {
            prompt_position = "top",
            width = 0.7,
            height = 0.6,
          },
        },
        current_buffer_fuzzy_find = {
          previewer = false,
          prompt_title = "Search",
          results_title = "", -- results
          layout_config = {
            prompt_position = "top",
            width = 0.7,
            height = 0.6,
          },
        },
        buffers = {
          previewer = false,
          layout_config = {
            prompt_position = "top",
            width = 0.6,
            height = 0.5,
          },
        },
        git_bcommits = {
          previewer = false,
          layout_config = {
            prompt_position = "top",
            width = 0.7,
            height = 0.6,
          },
        },
        git_commits = {
          previewer = false,
          layout_config = {
            prompt_position = "top",
            width = 0.7,
            height = 0.6,
          },
        },
        git_status = {
          previewer = false,
          layout_config = {
            prompt_position = "top",
            width = 0.6,
            height = 0.5,
          },
        },
        git_branches = {
          previewer = false,
          layout_config = {
            prompt_position = "top",
            width = 0.6,
            height = 0.5,
          },
          -- overwrite default behavior of checking out to dettached HEAD
          mappings = {
            i = { ["<cr>"] = actions.git_switch_branch },
          },
        },
        diagnostics = {
          previewer = false,
          prompt_title = "Diagnostics",
          layout_config = {
            prompt_position = "top",
            width = 0.6,
            height = 0.5,
          },
        },
      },
      extensions = {
        persisted = {
          layout_config = {
            prompt_position = "top",
            width = 0.6,
            height = 0.5,
          },
        },
      },
    })
  end,
}

5. nvim-cmp

plugins/nvim-cmp.lua

-- configuration instructions
-- source: https://github.com/hrsh7th/nvim-cmp/wiki/Menu-Appearance#how-to-get-types-on-the-left-and-offset-the-menu

-- for conciseness
local opt = vim.opt -- vim options

-- set options
opt.completeopt = "menu,menuone,noselect"

-- vscode like icons
local cmp_kinds = {
  Text = "",
  Method = "",
  Function = "",
  Constructor = "",
  Field = "",
  Variable = "",
  Class = "",
  Interface = "",
  Module = "",
  Property = "",
  Unit = "",
  Value = "",
  Enum = "",
  Keyword = "",
  Snippet = "",
  Color = "",
  File = "",
  Reference = "",
  Folder = "",
  EnumMember = "",
  Constant = "",
  Struct = "",
  Event = "",
  Operator = "",
  TypeParameter = "",
}

return {
  "hrsh7th/nvim-cmp",
  dependencies = {
    "hrsh7th/cmp-buffer",
    "hrsh7th/cmp-path",
    "onsails/lspkind.nvim",
    "L3MON4D3/LuaSnip",
    "saadparwaiz1/cmp_luasnip",
    "rafamadriz/friendly-snippets",
    "roobert/tailwindcss-colorizer-cmp.nvim",
  },
  event = "InsertEnter",
  config = function()
    -- load friendly-snippets
    require("luasnip.loaders.from_vscode").lazy_load()

    -- require cmp
    local cmp = require("cmp")

    -- require luasnip
    local luasnip = require("luasnip")

    -- require lspkind
    local lspkind = require("lspkind")

    -- require tailwind colorizer for cmp
    local tailwindcss_colorizer_cmp = require("tailwindcss-colorizer-cmp")

    -- custom setup
    cmp.setup({
      window = {
        completion = {
          border = "rounded", -- single|rounded|none
          -- custom colors
          winhighlight = "Normal:Normal,FloatBorder:FloatBorder,CursorLine:CursorLineBG,Search:None", -- BorderBG|FloatBorder
          side_padding = 0, -- padding at sides
          col_offset = -4, -- move floating box left or right
        },
        documentation = {
          border = "rounded", -- single|rounded|none
          -- custom colors
          winhighlight = "Normal:Normal,FloatBorder:FloatBorder,CursorLine:CursorLineBG,Search:None", -- BorderBG|FloatBorder
        },
      },
      snippet = {
        expand = function(args)
          luasnip.lsp_expand(args.body)
        end,
      },
      mapping = cmp.mapping.preset.insert({
        ["<C-k>"] = cmp.mapping.select_prev_item(), -- select previous suggestion
        ["<S-tab>"] = cmp.mapping.select_prev_item(), -- select previous suggestion (2)
        ["<C-j>"] = cmp.mapping.select_next_item(), -- select next suggestion
        ["<tab>"] = cmp.mapping.select_next_item(), -- select next suggestion (2)
        ["<C-l>"] = cmp.mapping.scroll_docs(-4), -- scroll docs down
        ["<C-h>"] = cmp.mapping.scroll_docs(4), -- scroll docs up
        ["<C-e>"] = cmp.mapping.abort(), -- close completion window
        ["<C-Space>"] = cmp.mapping.complete(), -- show completion suggestions
        ["<CR>"] = cmp.mapping.confirm({ select = false }), -- confirm suggestion
      }),
      sources = cmp.config.sources({
        { name = "nvim_lsp" }, -- lsp
        { name = "luasnip" }, -- luasnips
        { name = "buffer" }, -- text within the current buffer
        { name = "path" }, -- file system paths
      }),
      formatting = {
        fields = { "kind", "abbr", "menu" },
        format = function(entry, item)
          -- vscode like icons for cmp autocompletion
          local fmt = lspkind.cmp_format({
            mode = "symbol_text",
            maxwidth = 50,
            ellipsis_char = "...",
            before = tailwindcss_colorizer_cmp.formatter, -- prepend tailwindcss-colorizer
          })(entry, item)

          -- customize lspkind format
          local strings = vim.split(fmt.kind, "%s", { trimempty = true })

          -- strings[1] -> default icon
          -- strings[2] -> kind

          -- set different icon styles
          fmt.kind = " " .. (cmp_kinds[strings[2]] or "") -- concatenate icon based on kind

          -- append customized kind text
          fmt.kind = fmt.kind .. " " -- just an extra space at the end
          fmt.menu = strings[2] ~= nil and ("  " .. (strings[2] or "")) or ""
          
          return fmt
        end,
      },
    })
  end,
}

6. toggleterm

plugins/toggleterm.lua

return {
  "akinsho/toggleterm.nvim",
  version = "*",
  event = "VeryLazy",
  config = function()
    -- custom setup
    require("toggleterm").setup({
      direction = "float", -- float|horizontal|vertical|tab
      float_opts = {
        border = "curved", -- single|double|curved|shadow
      },
      persist_mode = true,
      highlights = {
        Normal = { link = "ToogleTermNormal" },
        NormalFloat = { link = "ToogleTermNormalFloat" },
        FloatBorder = { link = "ToggleTermFloatBorder" },
      },
      on_create = function()
        -- disable sign column (annoying black space at the left)
        vim.cmd([[ setlocal signcolumn=no ]])
      end,
    })

    -- require toggleterm:terminal instance
    local toggleterm_terminal = require("toggleterm.terminal")

    -- general toggleterm terminal instance
    local Terminal = toggleterm_terminal.Terminal

    -- main terminal
    local main_term = Terminal:new({
      display_name = " TERMINAL ",
      on_open = function()
        vim.cmd([[ startinsert! ]])
      end,
    })

    -- global: main term toggle
    function _G.main_term_toggle()
      main_term:toggle()
    end

    -- global: attach general key shortcuts
    function _G.set_terminal_keymaps()
      local opts = { buffer = 0 }
      vim.keymap.set("t", "<esc>", [[<C-\><C-n>]], opts)
    end

    -- set global toggleterm keymaps
    vim.cmd([[ autocmd! TermOpen term://* lua set_terminal_keymaps() ]])
  end,
}

7. lspsaga

plugins/lspsaga.lua

return {
  "nvimdev/lspsaga.nvim",
  event = { "BufReadPre", "BufNewFile" },
  dependencies = {
    "nvim-treesitter/nvim-treesitter",
    "nvim-tree/nvim-web-devicons",
  },
  opts = {
    scroll_preview = {
      scroll_down = "<C-h>",
      scroll_up = "<C-l>",
    },
    finder = {
      keys = {
        edit = "<CR>",
      },
    },
    definition = {
      keys = {
        edit = "<CR>",
      },
    },
    symbol_in_winbar = {
      enable = true,
      separator = "",
      show_file = false,
      folder_level = 0, -- 0: display folder | 1: only file
    },
    lightbulb = {
      enable = false, -- enable by default
      sign = false, -- display sign at the column when code actions are available
    },
    ui = {
      theme = "round",
      border = "rounded",
      expand = "", -- shown in sagaoutline
      collapse = "", -- shown in sagaoutline
      code_action = "👾",
      lines = { "", "", "", "", "" },
    },
    outline = {
      win_width = 35,
    },
  },
}

👾 For more plugins configuration check my personal nvim config:

https://github.com/diegoulloao/nvim-diegoulloao

(some things may change along the time)

Clone this wiki locally