498 lines
14 KiB
Lua
498 lines
14 KiB
Lua
-- Locals
|
||
local keymap = vim.keymap.set
|
||
|
||
-- Vim pack plugins list
|
||
vim.pack.add(
|
||
{
|
||
'https://github.com/nvim-treesitter/nvim-treesitter',
|
||
'https://github.com/folke/snacks.nvim',
|
||
'https://github.com/stevearc/oil.nvim',
|
||
'https://github.com/neovim/nvim-lspconfig',
|
||
'https://github.com/folke/which-key.nvim',
|
||
'https://github.com/mason-org/mason.nvim',
|
||
'https://github.com/ibhagwan/fzf-lua',
|
||
'https://github.com/nvim-lualine/lualine.nvim',
|
||
'https://github.com/L3MON4D3/LuaSnip',
|
||
'https://github.com/danymat/neogen',
|
||
'https://github.com/christoomey/vim-tmux-navigator',
|
||
'https://github.com/folke/todo-comments.nvim',
|
||
-- Colorschemes
|
||
'https://github.com/ellisonleao/gruvbox.nvim',
|
||
'https://github.com/sainnhe/everforest',
|
||
'https://github.com/sainnhe/gruvbox-material',
|
||
'https://github.com/rebelot/kanagawa.nvim',
|
||
'https://github.com/catppuccin/nvim',
|
||
'https://github.com/folke/tokyonight.nvim',
|
||
'https://github.com/luisiacc/gruvbox-baby',
|
||
-- Completion
|
||
'https://github.com/hrsh7th/nvim-cmp',
|
||
'https://github.com/hrsh7th/cmp-buffer',
|
||
'https://github.com/hrsh7th/cmp-path',
|
||
'https://github.com/hrsh7th/cmp-nvim-lsp',
|
||
'https://github.com/saadparwaiz1/cmp_luasnip',
|
||
}
|
||
)
|
||
-- ################################## Plugins ##################################
|
||
-- → → → → → → Colorschemes ← ← ← ← ← ←
|
||
vim.opt.termguicolors = true
|
||
vim.opt.background = "dark"
|
||
vim.opt.signcolumn = "yes"
|
||
|
||
vim.g.gruvbox_material_enable_italic = true
|
||
vim.cmd.colorscheme("catppuccin-mocha")
|
||
|
||
-- → → → → → → Oil ← ← ← ← ← ←
|
||
-- Oil setup
|
||
require("oil").setup()
|
||
-- Oil Keymaps
|
||
vim.keymap.set("n", "-", "<CMD>Oil<CR>", { desc = "Open parent directory" })
|
||
|
||
-- → → → → → → Snacks ← ← ← ← ← ←
|
||
-- Snacks setup
|
||
require("snacks").setup({
|
||
input = { enabled = true },
|
||
picker = { enabled = true },
|
||
})
|
||
|
||
-- → → → → → → Treesitter ← ← ← ← ← ←
|
||
-- Treesitter setup
|
||
require("nvim-treesitter").setup(
|
||
{
|
||
-- Directory to install parsers and queries to (prepended to `runtimepath` to have priority)
|
||
install_dir = vim.fn.stdpath('data') .. '/site',
|
||
sync_install = false,
|
||
highlight = { enable = true },
|
||
indent = { enable = true },
|
||
}
|
||
)
|
||
require('nvim-treesitter').install { 'python', 'lua', 'vim', 'vimdoc', 'javascript', 'html', 'go', 'markdown' }
|
||
|
||
-- → → → → → → Mason ← ← ← ← ← ←
|
||
-- Mason setup
|
||
require("mason").setup()
|
||
|
||
-- → → → → → → FZF-lua ← ← ← ← ← ←
|
||
-- FZF-lua setup
|
||
local fzf_lua = require("fzf-lua")
|
||
fzf_lua.setup(
|
||
{
|
||
winopts = {
|
||
height = 0.85,
|
||
width = 0.80,
|
||
},
|
||
fzf_opts = {
|
||
['--layout'] = 'reverse-list',
|
||
},
|
||
files = {
|
||
fd_opts = "--color=never --type f",
|
||
rg_opts = "--color=never --files",
|
||
},
|
||
keymap = {
|
||
fzf = {
|
||
["ctrl-q"] = "select-all+accept",
|
||
},
|
||
builtin = {
|
||
["<C-j>"] = "down",
|
||
["<C-k>"] = "up",
|
||
["<S-tab>"] = "toggle+up",
|
||
["<tab>"] = "toggle+down",
|
||
},
|
||
},
|
||
}
|
||
)
|
||
-- FZF-lua support functions
|
||
-- Glob pattern searcher
|
||
local function live_grep_with_glob()
|
||
vim.ui.input({
|
||
prompt = "Glob pattern: ",
|
||
default = "/home/user/Work/root/ivideon/audio_storage/",
|
||
}, function(input)
|
||
if input then
|
||
fzf_lua.live_grep({
|
||
cwd = input,
|
||
})
|
||
end
|
||
end)
|
||
end
|
||
|
||
local function live_grep_in_current_dir()
|
||
local current_file = vim.fn.expand('%:p')
|
||
local current_dir = current_file:match("(.*/)")
|
||
|
||
vim.ui.input({
|
||
prompt = "Glob pattern: ",
|
||
default = current_dir or vim.fn.getcwd(),
|
||
}, function(input)
|
||
if input then
|
||
fzf_lua.live_grep({
|
||
cwd = input,
|
||
})
|
||
end
|
||
end)
|
||
end
|
||
|
||
local function copy_current_file_path()
|
||
local filepath = vim.fn.expand('%:p')
|
||
vim.fn.setreg("+", filepath)
|
||
print("Copied: " .. filepath)
|
||
end
|
||
|
||
local function copy_file_path_and_position()
|
||
local filepath = vim.fn.expand('%:p')
|
||
local cursor_pos = vim.api.nvim_win_get_cursor(0)
|
||
local line = cursor_pos[1]
|
||
local col = cursor_pos[2] + 1 -- fzf-lua uses 1-indexed columns
|
||
|
||
local output = string.format("%s:%d:%d", filepath, line, col)
|
||
vim.fn.setreg("+", output)
|
||
print("Copied: " .. output)
|
||
end
|
||
|
||
local function live_grep_in_quick_fix_list_files()
|
||
local qf_items = vim.fn.getqflist()
|
||
local files = {}
|
||
|
||
for _, item in ipairs(qf_items) do
|
||
if item.bufnr > 0 then
|
||
local filename = vim.api.nvim_buf_get_name(item.bufnr)
|
||
if filename ~= "" then
|
||
table.insert(files, filename)
|
||
end
|
||
end
|
||
end
|
||
|
||
if #files > 0 then
|
||
fzf_lua.live_grep({
|
||
search_dirs = files,
|
||
})
|
||
else
|
||
print("No files in quickfix list")
|
||
end
|
||
end
|
||
|
||
local function find_all_files_including_hidden()
|
||
fzf_lua.files(
|
||
{
|
||
fd_opts = "--type f --hidden --no-ignore"
|
||
}
|
||
)
|
||
end
|
||
|
||
-- Function for getting filename and copy it to + buffer
|
||
local function copy_filename()
|
||
local filepath = vim.fn.expand('%:t')
|
||
local output = string.format("%s", filepath)
|
||
vim.fn.setreg("+", output)
|
||
print("Copied: " .. output)
|
||
end
|
||
|
||
-- FZF-lua keymaps
|
||
keymap("n", "<leader>ff", function() fzf_lua.files() end, { desc = "FZF: find files in cwd" })
|
||
keymap("n", "<leader>fg", function() fzf_lua.live_grep() end, { desc = "FZF: find string in cwd" })
|
||
keymap("n", "<leader>fs", function() fzf_lua.grep_cword() end, { desc = "FZF: find string under cursor" })
|
||
keymap("n", "<leader>fb", function() fzf_lua.buffers() end, { desc = "FZF: display opened buffers" })
|
||
keymap("n", "<leader>fh", function() fzf_lua.help_tags() end, { desc = "FZF: display help tags" })
|
||
keymap("n", "<leader>fml", function() fzf_lua.marks() end, { desc = "FZF: find marks list" })
|
||
keymap("n", "<leader>fmp", function() fzf_lua.man_pages() end, { desc = "FZF: find available man pages" })
|
||
keymap("n", "<leader>fds", function() fzf_lua.lsp_document_symbols() end, { desc = "Grep: Document symbols" })
|
||
-- keymap("n", "<leader>fgb", function() fzf_lua.git_blame() end, { desc = "Grep: Document symbols" })
|
||
keymap("n", "<leader>ft", function() fzf_lua.tabs() end, { desc = "Pick opened tabs" })
|
||
|
||
keymap("n", "<leader>fa", find_all_files_including_hidden, { desc = "FZF: Find all files" })
|
||
keymap('n', '<leader>fp', live_grep_with_glob, { desc = 'Live grep with glob pattern' })
|
||
keymap('n', '<leader>fcp', live_grep_in_current_dir, { desc = 'Live grep in current directory' })
|
||
keymap('n', '<leader>ccp', copy_file_path_and_position, { desc = "Copy cursor position" })
|
||
keymap('n', '<leader>ccd', copy_current_file_path, { desc = 'Copy current file path' })
|
||
keymap('n', '<leader>ccf', copy_filename, { desc = 'Copy current file path' })
|
||
keymap("n", "<leader>fcgb", function()
|
||
fzf_lua.git_blame({
|
||
winopts = {
|
||
preview = { hidden = "hidden" }
|
||
}
|
||
})
|
||
end, { desc = "Grep: Document symbols" })
|
||
|
||
keymap('n', '<leader>fq', live_grep_in_quick_fix_list_files, { desc = "Live grep in quickfix files" })
|
||
|
||
keymap('n', '<leader>fcf', function()
|
||
fzf_lua.live_grep({
|
||
cwd = vim.fn.expand('%:p:h'),
|
||
search = '',
|
||
fzf_cli_args = '--no-sort',
|
||
})
|
||
end, { desc = "Live grep in current file" })
|
||
|
||
|
||
keymap("n", "<leader>fn", function()
|
||
fzf_lua.grep({
|
||
prompt = 'Todo❯ ',
|
||
search = 'TODO|FIXME|XXX|HACK|BUG|NOTE|PERF|OPTIMIZE',
|
||
no_esc = true,
|
||
})
|
||
end, { desc = "FZF: display TODO comments" })
|
||
|
||
-- → → → → → → Lualine ← ← ← ← ← ←
|
||
-- Lualine setup
|
||
require("lualine").setup({
|
||
options = {
|
||
theme = "catppuccin-mocha",
|
||
},
|
||
sections = {
|
||
lualine_c = {
|
||
{
|
||
"filename",
|
||
file_status = true,
|
||
path = 2,
|
||
},
|
||
},
|
||
},
|
||
})
|
||
|
||
-- → → → → → → LuaSnip ← ← ← ← ← ←
|
||
-- LuaSnip config
|
||
local ls = require "luasnip"
|
||
|
||
-- Load custom snippets
|
||
for _, ft_path in ipairs(vim.api.nvim_get_runtime_file("snippets/*.lua", true)) do
|
||
loadfile(ft_path)()
|
||
end
|
||
|
||
-- LuaSnip keymaps
|
||
ls.config.set_config {
|
||
history = true,
|
||
updateevents = "TextChanged, TextChangedI",
|
||
enable_autosnippets = true,
|
||
store_selection_keys = "<c-s>",
|
||
}
|
||
|
||
vim.keymap.set({ "i", "s" }, "<c-j>", function()
|
||
if ls.expand_or_jumpable() then
|
||
ls.expand_or_jump()
|
||
end
|
||
end, { silent = true })
|
||
|
||
vim.keymap.set({ "i", "s" }, "<c-k>", function()
|
||
if ls.jumpable() then
|
||
ls.jump(-1)
|
||
end
|
||
end, { silent = true })
|
||
|
||
vim.keymap.set({ "i", "s" }, "<c-l>", function()
|
||
if ls.choice_active() then
|
||
ls.change_choice(1)
|
||
end
|
||
end, { silent = true })
|
||
|
||
vim.keymap.set("n", "<leader><leader>s", "<cmd>source ~/.config/nvim/lua/custom/luasnip.lua<CR>")
|
||
|
||
|
||
-- → → → → → → Neogen ← ← ← ← ← ←
|
||
-- Neogen setup
|
||
require("neogen").setup {
|
||
enabled = true,
|
||
languages = {
|
||
python = {
|
||
template = {
|
||
annotation_convention = "reST"
|
||
}
|
||
}
|
||
},
|
||
}
|
||
|
||
-- Neogen keymaps
|
||
local opts = { noremap = true, silent = true }
|
||
vim.keymap.set("n", "<Leader>ids", ":lua require('neogen').generate()<CR>", opts)
|
||
|
||
-- → → → → → → Vim Tmux Navigator ← ← ← ← ← ←
|
||
-- Keymaps
|
||
vim.keymap.set("n", "<c-h>", "<cmd>TmuxNavigateLeft<cr>", { noremap = true, silent = true })
|
||
vim.keymap.set("n", "<c-j>", "<cmd>TmuxNavigateDown<cr>", { noremap = true, silent = true })
|
||
vim.keymap.set("n", "<c-k>", "<cmd>TmuxNavigateUp<cr>", { noremap = true, silent = true })
|
||
vim.keymap.set("n", "<c-l>", "<cmd>TmuxNavigateRight<cr>", { noremap = true, silent = true })
|
||
vim.keymap.set("n", "<c-\\>", "<cmd>TmuxNavigatePrevious<cr>", { noremap = true, silent = true })
|
||
|
||
-- → → → → → → Completion ← ← ← ← ← ←
|
||
vim.opt.completeopt = { "menu", "menuone", "noselect" }
|
||
|
||
local cmp = require "cmp"
|
||
|
||
cmp.setup {
|
||
sources = {
|
||
{ name = "luasnip" },
|
||
{ name = "nvim_lsp" },
|
||
{ name = "path" },
|
||
{ name = "buffer" },
|
||
},
|
||
mapping = {
|
||
["<C-n>"] = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Insert },
|
||
["<C-p>"] = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Insert },
|
||
["<C-y>"] = cmp.mapping(
|
||
cmp.mapping.confirm {
|
||
behavior = cmp.ConfirmBehavior.Insert,
|
||
select = true,
|
||
},
|
||
{ "i", "c" }
|
||
),
|
||
},
|
||
snippet = {
|
||
expand = function(args)
|
||
require("luasnip").lsp_expand(args.body)
|
||
end,
|
||
},
|
||
}
|
||
|
||
-- → → → → → → LspConfig ← ← ← ← ← ←
|
||
-- Locals
|
||
local picker = "FzfLua"
|
||
local capabilities = nil
|
||
local servers = {
|
||
gopls = {
|
||
settings = {
|
||
gopls = {
|
||
hints = {
|
||
assignVariableTypes = true,
|
||
compositeLiteralFields = true,
|
||
compositeLiteralTypes = true,
|
||
constantValues = true,
|
||
functionTypeParameters = true,
|
||
parameterNames = true,
|
||
rangeVariableTypes = true,
|
||
},
|
||
},
|
||
},
|
||
},
|
||
ruff = {
|
||
init_options = {
|
||
settings = {
|
||
-- Ruff language server settings go here
|
||
logLevel = "error",
|
||
},
|
||
},
|
||
},
|
||
pyright = {
|
||
settings = {
|
||
pyright = {
|
||
-- Using Ruff's import organizer
|
||
disableOrganizeImports = true,
|
||
},
|
||
python = {
|
||
analysis = {
|
||
-- Ignore all files for analysis to exclusively use Ruff for linting
|
||
-- ignore = { "*" },
|
||
diagnosticMode = "off",
|
||
-- typeCheckingMode = "off",
|
||
},
|
||
},
|
||
},
|
||
},
|
||
lua_ls = {
|
||
capabilities = capabilities,
|
||
settings = {
|
||
Lua = {
|
||
-- make the language server recognize "vim" global
|
||
diagnostics = {
|
||
globals = { "vim" },
|
||
},
|
||
completion = {
|
||
callSnippet = "Replace",
|
||
},
|
||
},
|
||
},
|
||
},
|
||
clangd = {
|
||
filetypes = { "c", "cpp" },
|
||
cmd = {
|
||
"clangd",
|
||
"--offset-encoding=utf-16",
|
||
},
|
||
},
|
||
html = {
|
||
filetypes = { "html", "gohtml" },
|
||
},
|
||
eslint = {
|
||
filetypes = { "javascript", "typescript", "html", "gohtml" },
|
||
},
|
||
ts_ls = {
|
||
filetypes = { "javascript", "typescript" },
|
||
},
|
||
}
|
||
|
||
-- Setup
|
||
if pcall(require, "cmp_nvim_lsp") then
|
||
capabilities = require("cmp_nvim_lsp").default_capabilities()
|
||
end
|
||
|
||
-- Enable the configured servers
|
||
vim.lsp.enable(vim.tbl_keys(servers))
|
||
|
||
-- Keymaps
|
||
-- Here it is used the LSP server attaches to file
|
||
vim.api.nvim_create_autocmd("LspAttach", {
|
||
-- Grouping together autocommands.
|
||
-- Here we creating new group and calling it "UserLspConfig"
|
||
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
|
||
-- callback defining logic to execute on the event
|
||
callback = function(ev)
|
||
-- Buffer local mappings.
|
||
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
||
local opts = { buffer = ev.buf, silent = true }
|
||
|
||
-- set keybinds
|
||
-- show definition, references
|
||
opts.desc = "Show LSP references"
|
||
vim.keymap.set("n", "gR", string.format("<cmd>%s lsp_references<CR>", picker), opts)
|
||
|
||
-- go to declaration
|
||
opts.desc = "Go to declaration"
|
||
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
|
||
|
||
-- show lsp definitions
|
||
opts.desc = "Show LSP definitions"
|
||
vim.keymap.set("n", "gd", string.format("<cmd>%s lsp_definitions<CR>", picker), opts)
|
||
|
||
-- show lsp implementations
|
||
opts.desc = "Show LSP implementations"
|
||
vim.keymap.set("n", "gi", string.format("<cmd>%s lsp_implementations<CR>", picker), opts)
|
||
|
||
-- show lsp type definitions
|
||
opts.desc = "Show LSP type definitions"
|
||
vim.keymap.set("n", "glt", string.format("<cmd>%s lsp_type_definitions<CR>", picker), opts)
|
||
|
||
-- see available code actions, in visual mode will apply to selection
|
||
opts.desc = "See available code actions"
|
||
vim.keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, opts)
|
||
|
||
-- smart rename
|
||
opts.desc = "Smart rename"
|
||
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
|
||
|
||
-- show diagnostics for file
|
||
opts.desc = "Show buffer diagnostics"
|
||
vim.keymap.set("n", "<leader>D", string.format("<cmd>%s diagnostics bufnr=0<CR>", picker), opts)
|
||
|
||
-- show diagnostics for line
|
||
opts.desc = "Show line diagnostics"
|
||
vim.keymap.set("n", "<leader>d", vim.diagnostic.open_float, opts)
|
||
|
||
-- jump to previous diagnostic in buffer
|
||
opts.desc = "Go to previous diagnostic"
|
||
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
|
||
|
||
-- jump to next diagnostic in buffer
|
||
opts.desc = "Go to next diagnostic"
|
||
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
|
||
|
||
-- show documentation for what is under cursor
|
||
opts.desc = "Show documentation for what is under cursor"
|
||
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
|
||
|
||
-- mapping to restart lsp if necessary
|
||
opts.desc = "Restart LSP"
|
||
vim.keymap.set("n", "<leader>rs", ":LspRestart<CR>", opts)
|
||
|
||
opts.desc = "Run formatting on current buffer"
|
||
vim.keymap.set("n", "<space>f", function()
|
||
vim.lsp.buf.format({ async = true })
|
||
end, opts)
|
||
end,
|
||
})
|