Skip to content

Plugins

Diego Ulloa edited this page May 22, 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,
}
Clone this wiki locally