La idea original de esta selección de plugins es de Mario Carrión en su video Neovim configuration for Golang Development (2023). Este es su repo de GitHub.
Los cambios que se le han hecho son:
<leader> t Me abre una ventana inferior con comentarios sobre el códig o
Aquí está la lista de atajos de teclado en Vim que podemos usar en Neovim.
Algunos ejemplos:
Colapsar funciones con nvim-treesitter
~/.config/nvim/ | Ficheros de configuración |
~/.local/share/nvim/ | Código de los plugins |
Tipo | Repositorio y Dependencias | Descripción |
---|---|---|
Paquetes | wbthomason/packer.nvim | use-package inspired plugin/package management for Neovim. |
Look and Feel | catppuccin/nvim | Provides theme support for other plugins in the Neovim ecosystem and extended Neovim functionality through integrations |
Productivity | romgrk/barbar.nvim | A tabline plugin with re-orderable, auto-sizing, clickable tabs, icons, nice highlighting, sort-by commands and a magic jump-to-buffer mode. Plus the tab names are made unique when two filenames match. |
☝ nvim-tree/nvim-web-devicons | Lua `fork` of vim-web-devicons for neovim. | |
nvim-lualine/lualine.nvim | A blazing fast and easy to configure neovim statusline plugin written in pure lua. | |
nvim-tree/nvim-tree.lua | A file explorer tree for neovim written in lua. | |
☝ nvim-tree/nvim-web-devicons | Lua `fork` of vim-web-devicons for neovim. | |
nvim-telescope/telescope.nvim | A highly extendable fuzzy finder over lists. | |
☝ nvim-lua/plenary.nvim | A Lua module for asynchronous programming using coroutines. | |
☝ BurntSushi/ripgrep | Recursively searches directories for a regex pattern while respecting your gitignore | |
Filetypes | chrisbra/csv.vim | A Filetype plugin for csv files. |
Development | lewis6991/gitsigns.nvim | Git integration for buffers. |
nvim-treesitter/nvim-treesitter | The goal of nvim-treesitter is both to provide a simple and easy way to use the interface for tree-sitter in Neovim and to provide some basic functionality such as highlighting based on it. | |
nvim-treesitter/nvim-treesitter-textobjects | Syntax aware text-objects, select, move, swap, and peek support. | |
rhysd/vim-clang-format | Vim plugin for clang-format, a formatter for C, C++, Obj-C, Java, JavaScript, and so on. | |
fatih/vim-go | Go development plugin for Vim. | |
sirver/UltiSnips | The ultimate snippet solution for Vim. | |
hrsh7th/cmp-nvim-lsp | nvim-cmp source for neovim's built-in language server client (LSP). | |
hrsh7th/nvim-cmp | A completion plugin for neovim coded in Lua. | |
nvim-lspconfig | Quickstart configs for Nvim LSP. | |
onsails/lspkind-nvim | ||
quangnguyen30192/cmp-nvim-ultisnips | UltiSnips completion source for nvim-cmp. | |
williamboman/nvim-lsp-installer | Neovim plugin that allow you to manage LSP servers (servers are installed inside :echo stdpath(“data”) by default). It works in tandem with lspconfig1 by registering a hook that enhances the PATH environment variable, allowing neovim's LSP client to locate the server executable installed by nvim-lsp-installer. | |
numToStr/Comment.nvim | Smart and powerful comment plugin for neovim. Supports treesitter, dot repeat, left-right/up-down motions, hooks, and more. | |
kylechui/nvim-surround | Add/change/delete surrounding delimiter pairs with ease. Written with ❤️ in Lua. |
Esta es la lista de ficheros de configuración en ~/.config/nvim/lua/plugins:
barbar.lua bufferline.lua catppuccin-theme.lua comment.lua default.lua gitsigns.lua lualine.lua nvim-cmp.lua nvim-surround.lua nvim-tree.lua nvim-treesitter.lua setup.lua telescope.lua
Veamos el contenido de cada fichero de configuración:
require("plugins.setup") require("plugins.default") require("plugins.lualine") require("plugins.nvim-tree") require("plugins.comment") require("plugins.telescope") require("plugins.nvim-treesitter") require("plugins.gitsigns") require("plugins.nvim-cmp") require("plugins.catppuccin-theme") require("plugins.barbar") require("plugins.nvim-surround")
local setup, bufferline = pcall(require, "bufferline") if not setup then return end bufferline.setup({ -- closable = false, -- Enable/disable close button clickable = false, -- Enables/disable clickable tabs tabpages = true, -- Enable/disable current/total tabpages indicator (top right corner) icons = "none", -- Enable/disable icons icons = { buffer_index = true, filetype = { enabled = true } } }) local map = vim.api.nvim_set_keymap local opts = { noremap = true, silent = true } -- Move to previous/next map('n', '<A-,>', '<Cmd>BufferPrevious<CR>', opts) map('n', '<A-.>', '<Cmd>BufferNext<CR>', opts) -- Re-order to previous/next map('n', '<A-<>', '<Cmd>BufferMovePrevious<CR>', opts) map('n', '<A->>', '<Cmd>BufferMoveNext<CR>', opts) -- Goto buffer in position... map('n', '<A-1>', '<Cmd>BufferGoto 1<CR>', opts) map('n', '<A-2>', '<Cmd>BufferGoto 2<CR>', opts) map('n', '<A-3>', '<Cmd>BufferGoto 3<CR>', opts) map('n', '<A-4>', '<Cmd>BufferGoto 4<CR>', opts) map('n', '<A-5>', '<Cmd>BufferGoto 5<CR>', opts) map('n', '<A-6>', '<Cmd>BufferGoto 6<CR>', opts) map('n', '<A-7>', '<Cmd>BufferGoto 7<CR>', opts) map('n', '<A-8>', '<Cmd>BufferGoto 8<CR>', opts) map('n', '<A-9>', '<Cmd>BufferGoto 9<CR>', opts) map('n', '<A-0>', '<Cmd>BufferLast<CR>', opts) -- Pin/unpin buffer map('n', '<A-p>', '<Cmd>BufferPin<CR>', opts) -- Close buffer map('n', '<A-c>', '<Cmd>BufferClose<CR>', opts) -- Wipeout buffer -- :BufferWipeout -- Close commands -- :BufferCloseAllButCurrent -- :BufferCloseAllButPinned -- :BufferCloseAllButCurrentOrPinned -- :BufferCloseBuffersLeft -- :BufferCloseBuffersRight -- Magic buffer-picking mode map('n', '<C-p>', '<Cmd>BufferPick<CR>', opts) -- Sort automatically by... map('n', '<Space>bb', '<Cmd>BufferOrderByBufferNumber<CR>', opts) map('n', '<Space>bd', '<Cmd>BufferOrderByDirectory<CR>', opts) map('n', '<Space>bl', '<Cmd>BufferOrderByLanguage<CR>', opts) map('n', '<Space>bw', '<Cmd>BufferOrderByWindowNumber<CR>', opts) -- Other: -- :BarbarEnable - enables barbar (enabled by default) -- :BarbarDisable - very bad command, should never be used
vim.opt.termguicolors = true require("bufferline").setup()
local present, catppuccin = pcall(require, "catppuccin") if not present then return end vim.opt.termguicolors = true catppuccin.setup { flavour = "mocha", term_colors = true, transparent_background = false, no_italic = false, no_bold = false, styles = { comments = { "italic" }, conditionals = {}, loops = {}, functions = { "italic" }, keywords = {}, strings = {}, variables = {}, numbers = {}, booleans = {}, properties = {}, types = { "bold" }, }, color_overrides = { mocha = { base = "#171717", -- background surface2 = "#9A9A9A", -- comments text = "#F6F6F6", }, }, highlight_overrides = { mocha = function(C) return { NvimTreeNormal = { bg = C.none }, CmpBorder = { fg = C.surface2 }, Pmenu = { bg = C.none }, NormalFloat = { bg = C.none }, TelescopeBorder = { link = "FloatBorder" }, } end, }, } vim.cmd.colorscheme "catppuccin"
local setup, comment = pcall(require, "Comment") if not setup then return end comment.setup()
vim.g.mapleader = "," vim.opt.encoding="utf-8" vim.opt.compatible=false vim.opt.hlsearch=true vim.opt.relativenumber = true vim.opt.laststatus = 2 vim.opt.vb = true vim.opt.ruler = true vim.opt.spelllang="es_es" vim.opt.autoindent=true vim.opt.colorcolumn="120" vim.opt.textwidth=120 vim.opt.mouse="a" vim.opt.clipboard="unnamed" vim.opt.scrollbind=false vim.opt.wildmenu=true
local setup, gitsigns = pcall(require, "gitsigns") if not setup then return end gitsigns.setup()
local setup, lualine = pcall(require, "lualine") if not setup then return end lualine.setup({ options = { theme = 'ayu_dark', }, })
local cmp_setup, cmp = pcall(require, "cmp") if not cmp_setup then return end local lspkind_setup, lspkind = pcall(require, "lspkind") if not lspkind_setup then return end local lspconfig_setup, lspconfig = pcall(require, "lspconfig") if not lspconfig_setup then return end local cmp_nvim_lsp_setup, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") if not cmp_nvim_lsp_setup then return end cmp.setup({ snippet = { expand = function(args) vim.fn["UltiSnips#Anon"](args.body) end, }, window = { completion = cmp.config.window.bordered(), documentation = cmp.config.window.bordered(), }, mapping = cmp.mapping.preset.insert({ ['<C-b>'] = cmp.mapping.scroll_docs(-4), ['<C-f>'] = cmp.mapping.scroll_docs(4), ['<C-Space>'] = cmp.mapping.complete(), ['<C-e>'] = cmp.mapping.abort(), ['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. }), sources = cmp.config.sources({ { name = 'nvim_lsp' }, { name = 'ultisnips' }, }, { { name = 'buffer' }, }) }) local capabilities = cmp_nvim_lsp.default_capabilities() local on_attach = function(client, bufnr) -- Enable completion triggered by <c-x><c-o> vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') -- Mappings. -- See `:help vim.lsp.*` for documentation on any of the below functions local bufopts = { noremap=true, silent=true, buffer=bufnr } vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts) vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts) vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts) vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) end lspconfig['gopls'].setup { capabilities = capabilities, on_attach = on_attach, settings = { gopls = { analyses = { assign = true, atomic = true, bools = true, composites = true, copylocks = true, deepequalerrors = true, embed = true, errorsas = true, fieldalignment = true, httpresponse = true, ifaceassert = true, loopclosure = true, lostcancel = true, nilfunc = true, nilness = true, nonewvars = true, printf = true, shadow = true, shift = true, simplifycompositelit = true, simplifyrange = true, simplifyslice = true, sortslice = true, stdmethods = true, stringintconv = true, structtag = true, testinggoroutine = true, tests = true, timeformat = true, unmarshal = true, unreachable = true, unsafeptr = true, unusedparams = true, unusedresult = true, unusedvariable = true, unusedwrite = true, useany = true, }, hoverKind = "FullDocumentation", linkTarget = "pkg.go.dev", usePlaceholders = true, vulncheck = "Imports", }, }, } lspconfig['pyright'].setup{} cmp.setup { formatting = { format = lspkind.cmp_format({ mode = "symbol_text", maxwidth = 50, before = function(entry, vim_item) return vim_item end }) } }
local setup, surround = pcall(require, "nvim-surround") if not setup then return end surround.setup()
local setup, nvimtree = pcall(require, "nvim-tree") if not setup then return end vim.cmd([[ nnoremap - :NvimTreeToggle<CR> ]]) local keymap = vim.keymap -- for conciseness keymap.set("n", "<leader>e", ":NvimTreeToggle<CR>") -- toggle file explorer vim.opt.foldmethod = "expr" vim.opt.foldexpr = "nvim_treesitter#foldexpr()" vim.opt.foldenable = false -- " Disable folding at startup. vim.g.loaded_netrw = 1 vim.g.loaded_netrwPlugin = 1 vim.opt.termguicolors = true local HEIGHT_RATIO = 0.8 -- You can change this local WIDTH_RATIO = 0.5 -- You can change this too nvimtree.setup({ disable_netrw = true, hijack_netrw = true, respect_buf_cwd = true, sync_root_with_cwd = true, view = { relativenumber = true, float = { enable = true, open_win_config = function() local screen_w = vim.opt.columns:get() local screen_h = vim.opt.lines:get() - vim.opt.cmdheight:get() local window_w = screen_w * WIDTH_RATIO local window_h = screen_h * HEIGHT_RATIO local window_w_int = math.floor(window_w) local window_h_int = math.floor(window_h) local center_x = (screen_w - window_w) / 2 local center_y = ((vim.opt.lines:get() - window_h) / 2) - vim.opt.cmdheight:get() return { border = "rounded", relative = "editor", row = center_y, col = center_x, width = window_w_int, height = window_h_int, } end, }, width = function() return math.floor(vim.opt.columns:get() * WIDTH_RATIO) end, }, -- filters = { -- custom = { "^.git$" }, -- }, -- renderer = { -- indent_width = 1, -- }, })
local setup, treesitter = pcall(require, "nvim-treesitter.configs") if not setup then return end vim.opt.foldmethod="expr" vim.opt.foldexpr="nvim_treesitter#foldexpr()" vim.opt.foldenable=false treesitter.setup { ensure_installed = { "dockerfile", "gitignore", "go", "gomod", "gowork", "javascript", "json", "lua", "markdown", "proto", "python", "rego", "ruby", "sql", "svelte", "yaml", }, indent = { enable = true, }, auto_install = true, sync_install = false, highlight = { enable = true, disable = { "markdown" }, -- -- Setting this to true will run `:h syntax` and tree-sitter at the same time. -- -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). -- -- Using this option may slow down your editor, and you may see some duplicate highlights. -- -- Instead of true it can also be a list of languages -- additional_vim_regex_highlighting = false, }, }
-- Packer, manually install it: -- git clone --depth 1 https://github.com/wbthomason/packer.nvim \ -- ~/.config/nvim/pack/packer/start/packer.nvim -- OR auto install packer if not installed -- $PWD/.local/share/nvim/ + .. local ensure_packer = function() local fn = vim.fn local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim" if fn.empty(fn.glob(install_path)) > 0 then fn.system({ "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path }) vim.cmd([[packadd packer.nvim]]) return true end return false end local packer_bootstrap = ensure_packer() -- true if packer was just installed return require("packer").startup(function() use "wbthomason/packer.nvim" -- https://github.com/wbthomason/packer.nvim -- Look and Feel use { "catppuccin/nvim", as = "catppuccin" } -- https://github.com/catppuccin/nvim -- Productivity use { "romgrk/barbar.nvim", wants = "nvim-tree/nvim-web-devicons" } -- https://github.com/romgrk/barbar.nvim use "nvim-lualine/lualine.nvim" -- https://github.com/nvim-lualine/lualine.nvim use { "nvim-tree/nvim-tree.lua", -- https://github.com/nvim-tree/nvim-tree.lua requires = { "nvim-tree/nvim-web-devicons", -- https://github.com/nvim-tree/nvim-web-devicons }, } -- use { -- "nvim-telescope/telescope-fzf-native.nvim", -- https://github.com/nvim-telescope/telescope-fzf-native.nvim -- run = "make", -- } use { "nvim-telescope/telescope.nvim", -- https://github.com/nvim-telescope/telescope.nvim requires = { "nvim-lua/plenary.nvim", "BurntSushi/ripgrep", }, branch = "0.1.x", } -- Filetypes use "chrisbra/csv.vim" -- https://github.com/chrisbra/csv.vim -- Development use "lewis6991/gitsigns.nvim" -- https://github.com/lewis6991/gitsigns.nvim use { "nvim-treesitter/nvim-treesitter", -- https://github.com/nvim-treesitter/nvim-treesitter run = ":TSUpdate" } use "nvim-treesitter/nvim-treesitter-textobjects" -- https://github.com/nvim-treesitter/nvim-treesitter-textobjects use "rhysd/vim-clang-format" -- https://github.com/rhysd/vim-clang-format use "fatih/vim-go" -- https://github.com/fatih/vim-go use "SirVer/ultisnips" -- https://github.com/sirver/UltiSnips use "hrsh7th/cmp-nvim-lsp" -- https://github.com/hrsh7th/cmp-nvim-lsp use "hrsh7th/nvim-cmp" -- https://github.com/hrsh7th/nvim-cmp use "neovim/nvim-lspconfig" -- https://github.com/neovim/nvim-lspconfig use "onsails/lspkind-nvim" -- https://github.com/onsails/lspkind-nvim use "quangnguyen30192/cmp-nvim-ultisnips" -- https://github.com/quangnguyen30192/cmp-nvim-ultisnips use "williamboman/nvim-lsp-installer" -- https://github.com/williamboman/nvim-lsp-installer use "numToStr/Comment.nvim" -- https://github.com/numToStr/Comment.nvim use { "kylechui/nvim-surround", tag = "*" } -- https://github.com/kylechui/nvim-surround if packer_bootstrap then require("packer").sync() end end)
local telescope_setup, telescope = pcall(require, "telescope") if not telescope_setup then return end local actions_setup, actions = pcall(require, "telescope.actions") if not actions_setup then return end telescope.setup({ defaults = { mappings = { i = { ["<C-k>"] = actions.move_selection_previous, -- move to prev result ["<C-j>"] = actions.move_selection_next, -- move to next result ["<C-q>"] = actions.send_selected_to_qflist + actions.open_qflist, -- send selected to quickfixlist }, }, }, }) --- telescope.load_extension("fzf") local builtin = require('telescope.builtin') vim.keymap.set('n', '<leader>ff', builtin.find_files, {}) vim.keymap.set('n', '<leader>fg', builtin.live_grep, {}) vim.keymap.set('n', '<leader>fb', builtin.buffers, {}) vim.keymap.set('n', '<leader>fh', builtin.help_tags, {}) vim.keymap.set('n', '<leader>fx', builtin.treesitter, {})