-- 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', 'https://github.com/nvim-tree/nvim-web-devicons', -- 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", "-", "Oil", { 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 = { [""] = "down", [""] = "up", [""] = "toggle+up", [""] = "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", "ff", function() fzf_lua.files() end, { desc = "FZF: find files in cwd" }) keymap("n", "fg", function() fzf_lua.live_grep() end, { desc = "FZF: find string in cwd" }) keymap("n", "fs", function() fzf_lua.grep_cword() end, { desc = "FZF: find string under cursor" }) keymap("n", "fb", function() fzf_lua.buffers() end, { desc = "FZF: display opened buffers" }) keymap("n", "fh", function() fzf_lua.help_tags() end, { desc = "FZF: display help tags" }) keymap("n", "fml", function() fzf_lua.marks() end, { desc = "FZF: find marks list" }) keymap("n", "fmp", function() fzf_lua.man_pages() end, { desc = "FZF: find available man pages" }) keymap("n", "fds", function() fzf_lua.lsp_document_symbols() end, { desc = "Grep: Document symbols" }) -- keymap("n", "fgb", function() fzf_lua.git_blame() end, { desc = "Grep: Document symbols" }) keymap("n", "ft", function() fzf_lua.tabs() end, { desc = "Pick opened tabs" }) keymap("n", "fa", find_all_files_including_hidden, { desc = "FZF: Find all files" }) keymap('n', 'fp', live_grep_with_glob, { desc = 'Live grep with glob pattern' }) keymap('n', 'fcp', live_grep_in_current_dir, { desc = 'Live grep in current directory' }) keymap('n', 'ccp', copy_file_path_and_position, { desc = "Copy cursor position" }) keymap('n', 'ccd', copy_current_file_path, { desc = 'Copy current file path' }) keymap('n', 'ccf', copy_filename, { desc = 'Copy current file path' }) keymap("n", "fcgb", function() fzf_lua.git_blame({ winopts = { preview = { hidden = "hidden" } } }) end, { desc = "Grep: Document symbols" }) keymap('n', 'fq', live_grep_in_quick_fix_list_files, { desc = "Live grep in quickfix files" }) keymap('n', '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", "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 = "", } vim.keymap.set({ "i", "s" }, "", function() if ls.expand_or_jumpable() then ls.expand_or_jump() end end, { silent = true }) vim.keymap.set({ "i", "s" }, "", function() if ls.jumpable() then ls.jump(-1) end end, { silent = true }) vim.keymap.set({ "i", "s" }, "", function() if ls.choice_active() then ls.change_choice(1) end end, { silent = true }) vim.keymap.set("n", "s", "source ~/.config/nvim/lua/custom/luasnip.lua") -- → → → → → → 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", "ids", ":lua require('neogen').generate()", opts) -- → → → → → → Vim Tmux Navigator ← ← ← ← ← ← -- Keymaps vim.keymap.set("n", "", "TmuxNavigateLeft", { noremap = true, silent = true }) vim.keymap.set("n", "", "TmuxNavigateDown", { noremap = true, silent = true }) vim.keymap.set("n", "", "TmuxNavigateUp", { noremap = true, silent = true }) vim.keymap.set("n", "", "TmuxNavigateRight", { noremap = true, silent = true }) vim.keymap.set("n", "", "TmuxNavigatePrevious", { 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 = { [""] = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Insert }, [""] = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Insert }, [""] = 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("%s lsp_references", 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("%s lsp_definitions", picker), opts) -- show lsp implementations opts.desc = "Show LSP implementations" vim.keymap.set("n", "gi", string.format("%s lsp_implementations", picker), opts) -- show lsp type definitions opts.desc = "Show LSP type definitions" vim.keymap.set("n", "glt", string.format("%s lsp_type_definitions", picker), opts) -- see available code actions, in visual mode will apply to selection opts.desc = "See available code actions" vim.keymap.set({ "n", "v" }, "ca", vim.lsp.buf.code_action, opts) -- smart rename opts.desc = "Smart rename" vim.keymap.set("n", "rn", vim.lsp.buf.rename, opts) -- show diagnostics for file opts.desc = "Show buffer diagnostics" vim.keymap.set("n", "D", string.format("%s diagnostics bufnr=0", picker), opts) -- show diagnostics for line opts.desc = "Show line diagnostics" vim.keymap.set("n", "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", "rs", ":LspRestart", opts) opts.desc = "Run formatting on current buffer" vim.keymap.set("n", "f", function() vim.lsp.buf.format({ async = true }) end, opts) end, })