Files
dotfiles/common/.config/nvim/lua/plugins/editor.lua
Pratik Tripathy 445ba576ca Template files created
- Gitignore and Prettierrc
- Created 2 env variables pointing to them

Shellcheck & Shellharden suggestions Implemented

NeoVim
- Replaced tpope/vim-surround with kylechui/nvim-surround
- LuaSnip typo fix
- [Ctrl+p] to open file fzf
- Formatting
2024-03-06 16:01:37 +05:30

438 lines
16 KiB
Lua

return {
-- Changes the Nvim root to git root
{
"airblade/vim-rooter",
config = function()
vim.g.rooter_cd_cmd = "tcd" -- Use tcd command to change the root
end,
},
-- File Explorer
{
"nvim-neo-tree/neo-tree.nvim",
branch = "v3.x",
keys = {
{ "<leader>e", ":Neotree filesystem toggle<CR>", desc = "Open NeoTree [E]plorer at Git root", remap = true },
{
"<leader>be",
function()
require("neo-tree.command").execute({ source = "buffers", toggle = true })
end,
desc = "NeoTree: Open [B]buffer [E]xplorer",
},
},
deactivate = function()
vim.cmd([[Neotree close]])
end,
init = function()
if vim.fn.argc(-1) == 1 then
local stat = vim.loop.fs_stat(vim.fn.argv(0))
if stat and stat.type == "directory" then
require("neo-tree")
end
end
end,
opts = {
enable_git_status = true,
filesystem = {
bind_to_cwd = true,
follow_current_file = {
enabled = true, -- Highlight the current buffer
leave_dirs_open = false,
},
use_libuv_file_watcher = true, -- Sync file system changes
filtered_items = {
visible = true,
show_hidden_count = true,
hide_dotfile = false,
hide_gitignore = false,
},
},
window = {
position = "left",
width = 30, -- Saner window size
mappings = {
["s"] = "open_split", -- horizontal split
["v"] = "open_vsplit", -- vertical split
["Y"] = function(state)
local node = state.tree:get_node()
local path = node:get_id()
vim.fn.setreg("+", path, "c")
end,
},
},
default_component_configs = {
indent = {
indent_size = 2, -- Compact tree display
with_expanders = true, -- if nil and file nesting is enabled, will enable expanders
expander_collapsed = "",
expander_expanded = "",
expander_highlight = "NeoTreeExpander",
},
},
sources = { "filesystem", "buffers", "git_status", "document_symbols" },
open_files_do_not_replace_types = { "terminal", "Trouble", "trouble", "qf", "Outline" },
},
config = function(_, opts)
local config = require("config.util")
local function on_move(data)
config.on_rename(data.source, data.destination)
end
local events = require("neo-tree.events")
opts.event_handlers = opts.event_handlers or {}
vim.list_extend(opts.event_handlers, {
{ event = events.FILE_MOVED, handler = on_move },
{ event = events.FILE_RENAMED, handler = on_move },
})
require("neo-tree").setup(opts)
vim.api.nvim_create_autocmd("TermClose", {
pattern = "*lazygit",
callback = function()
if package.loaded["neo-tree.sources.git_status"] then
require("neo-tree.sources.git_status").refresh()
end
end,
})
end,
},
-- Automatically highlights other instances of the word under cursor
{
"RRethy/vim-illuminate",
lazy = false,
opts = {
delay = 200,
large_file_cutoff = 2000,
large_file_override = {
providers = { "lsp" },
},
},
config = function(_, opts)
-- Copied from LazyNvim
require("illuminate").configure(opts)
local function map(key, dir, buffer)
vim.keymap.set("n", key, function()
require("illuminate")["goto_" .. dir .. "_reference"](false)
end, { desc = dir:sub(1, 1):upper() .. dir:sub(2) .. " Reference", buffer = buffer })
end
map("]]", "next")
map("[[", "prev")
-- also set it after loading ftplugins, since a lot overwrite [[ and ]]
vim.api.nvim_create_autocmd("FileType", {
callback = function()
local buffer = vim.api.nvim_get_current_buf()
map("]]", "next", buffer)
map("[[", "prev", buffer)
end,
})
end,
keys = {
{ "]]", desc = "Next Reference" },
{ "[[", desc = "Prev Reference" },
},
},
-- Display undotree
{
"mbbill/undotree",
config = function()
vim.keymap.set("n", "<leader>u", vim.cmd.UndotreeToggle)
end,
},
-- Show buffers like VS Code tabs
{
"akinsho/bufferline.nvim",
dependencies = {
{ "echasnovski/mini.bufremove", version = "*" },
},
event = "VeryLazy",
keys = {
{ "<leader>bp", "<Cmd>BufferLineTogglePin<CR>", desc = "Toggle buffer-pin" },
{ "<leader>xo", "<Cmd>BufferLineCloseOthers<CR>", desc = "Delete other buffers" },
},
opts = {
options = {
close_command = function(n)
require("mini.bufremove").delete(n, false)
end,
right_mouse_command = function(n)
require("mini.bufremove").delete(n, false)
end,
diagnostics = "nvim_lsp",
always_show_bufferline = false,
offsets = {
{
filetype = "neo-tree",
text = "Neo-tree",
highlight = "Directory",
text_align = "left",
},
},
numbers = function(opts)
return string.format("%s", opts.raise(opts.id))
end,
},
},
config = function(_, opts)
require("bufferline").setup(opts)
-- Fix bufferline when restoring a session
vim.api.nvim_create_autocmd("BufAdd", {
callback = function()
vim.schedule(function()
pcall(nvim_bufferline)
end)
end,
})
end,
},
-- UI Stuff ------------------------------------------------------------------------
-- icons
{ "nvim-tree/nvim-web-devicons" },
-- ui components
{ "MunifTanjim/nui.nvim" },
-- Better vim.ui
{ "stevearc/dressing.nvim" },
-- Better `vim.notify()`
{
"rcarriga/nvim-notify",
keys = {
{
"<leader>xn",
function()
require("notify").dismiss({ silent = true, pending = true })
end,
desc = "Dismiss all Notifications",
},
{
"<leader>xx",
function()
require("notify").dismiss({ silent = true, pending = true })
end,
desc = "Dismiss all Notifications",
},
},
opts = {
render = "wrapped-compact", -- Smaller popups
timeout = 2500,
max_height = function()
return math.floor(vim.o.lines * 0.25)
end,
max_width = function()
return math.floor(vim.o.columns * 0.5)
end,
on_open = function(win)
vim.api.nvim_win_set_config(win, { zindex = 100 })
end,
},
},
-- Completely replaces the UI for messages, cmdline and the popupmenu.
{
"folke/noice.nvim",
event = "VeryLazy",
dependencies = {
"MunifTanjim/nui.nvim",
"rcarriga/nvim-notify",
},
opts = {
lsp = {
progress = {
throttle = 1000 / 100,
},
override = {
["vim.lsp.util.convert_input_to_markdown_lines"] = true,
["vim.lsp.util.stylize_markdown"] = true,
["cmp.entry.get_documentation"] = true,
},
hover = {
silent = true,
},
},
routes = {
{
-- Show popup message when @recording macros
view = "notify",
filter = { event = "msg_showmode" },
},
{
filter = { event = "notify", find = "No information available" },
opts = { skin = true },
},
{
-- Direct some messages to bottom - obove lualine
view = "mini",
filter = {
event = "msg_show",
any = {
{ find = "%d+L, %d+B" },
{ find = "; after #%d+" },
{ find = "; before #%d+" },
-- Display delete, yank, jump notifications at bottom
{ find = "yanked" },
{ find = "fewer lines" },
{ find = "more lines" },
{ find = "EasyMotion" },
{ find = "Target key" },
{ find = "search hit BOTTOM" },
{ find = "lines to indent" },
{ find = "lines indented" },
{ find = "lines changed" },
{ find = ">ed" },
{ find = "<ed" },
{ find = "The only match" },
},
},
},
},
presets = {
lsp_doc_border = true,
bottom_search = true,
command_palette = true,
long_message_to_split = true,
inc_rename = true,
},
},
keys = {
{ "<leader>nx", "<cmd>NoiceDismiss<CR>", desc = "Dismiss all [N]oice notifications" },
},
},
-- Set lualine as statusline
{
"nvim-lualine/lualine.nvim",
-- See `:help lualine.txt`
--
init = function()
vim.g.lualine_laststatus = vim.o.laststatus
if vim.fn.argc(-1) > 0 then
-- set an empty statusline till lualine loads
vim.o.statusline = " "
else
-- hide the statusline on the starter page
vim.o.laststatus = 0
end
end,
opts = function()
local lualine_require = require("lualine_require")
lualine_require.require = require
vim.o.laststatus = vim.g.lualine_laststatus
local config = require("config.util")
return {
options = {
theme = "auto",
icons_enabled = true,
globalstatus = true,
component_separators = "|",
section_separators = "",
},
extensions = { "neo-tree", "lazy" },
sections = {
lualine_a = { "mode" },
lualine_b = { "branch" },
lualine_c = {
{
"diagnostics",
symbols = {
error = config.icons.diagnostics.Error,
warn = config.icons.diagnostics.Warn,
info = config.icons.diagnostics.Info,
hint = config.icons.diagnostics.Hint,
},
},
{ "filetype", icon_only = true, separator = "", padding = { left = 1, right = 0 } },
{
"filename",
file_status = true,
path = 1,
},
-- Breadcrumbs from "nvim-navic" plugin
{
function()
return require("nvim-navic").get_location()
end,
cond = function()
return package.loaded["nvim-navic"] and require("nvim-navic").is_available()
end,
},
},
lualine_x = {
{
function()
return require("noice").api.status.command.get()
end,
cond = function()
return package.loaded["noice"] and require("noice").api.status.command.has()
end,
color = config.fg("Statement"),
},
{
function()
return require("noice").api.status.mode.get()
end,
cond = function()
return package.loaded["noice"] and require("noice").api.status.mode.has()
end,
color = config.fg("Constant"),
},
{
function()
return "" .. require("dap").status()
end,
cond = function()
return package.loaded["dap"] and require("dap").status() ~= ""
end,
color = config.fg("Debug"),
},
{
"diff",
symbols = {
added = config.icons.git.added,
modified = config.icons.git.modified,
removed = config.icons.git.removed,
},
source = function()
local gitsigns = vim.b.gitsigns_status_dict
if gitsigns then
return {
added = gitsigns.added,
modified = gitsigns.changed,
removed = gitsigns.removed,
}
end
end,
},
},
lualine_y = {
{ "progress", separator = " ", padding = { left = 1, right = 0 } },
{ "location", padding = { left = 0, right = 1 } },
},
lualine_z = {
function()
return "" .. os.date("%R")
end,
},
},
}
end,
},
}