Skip to content

Commit c2d2a0c

Browse files
committed
Move most of the plugins to a dedicated file
1 parent 8fd8e92 commit c2d2a0c

File tree

8 files changed

+439
-546
lines changed

8 files changed

+439
-546
lines changed

init.lua

Lines changed: 1 addition & 546 deletions
Large diffs are not rendered by default.

lua/custom/plugins/cmp.lua

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
return { -- Autocompletion
2+
'hrsh7th/nvim-cmp',
3+
event = 'InsertEnter',
4+
dependencies = {
5+
-- Snippet Engine & its associated nvim-cmp source
6+
{
7+
'L3MON4D3/LuaSnip',
8+
build = (function()
9+
-- Build Step is needed for regex support in snippets.
10+
-- This step is not supported in many windows environments.
11+
-- Remove the below condition to re-enable on windows.
12+
if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then
13+
return
14+
end
15+
return 'make install_jsregexp'
16+
end)(),
17+
dependencies = {
18+
-- `friendly-snippets` contains a variety of premade snippets.
19+
-- See the README about individual language/framework/plugin snippets:
20+
-- https://github.com/rafamadriz/friendly-snippets
21+
-- {
22+
-- 'rafamadriz/friendly-snippets',
23+
-- config = function()
24+
-- require('luasnip.loaders.from_vscode').lazy_load()
25+
-- end,
26+
-- },
27+
},
28+
},
29+
'saadparwaiz1/cmp_luasnip',
30+
31+
-- Adds other completion capabilities.
32+
-- nvim-cmp does not ship with all sources by default. They are split
33+
-- into multiple repos for maintenance purposes.
34+
'hrsh7th/cmp-nvim-lsp',
35+
'hrsh7th/cmp-path',
36+
},
37+
config = function()
38+
-- See `:help cmp`
39+
local cmp = require 'cmp'
40+
local luasnip = require 'luasnip'
41+
luasnip.config.setup {}
42+
43+
cmp.setup {
44+
snippet = {
45+
expand = function(args)
46+
luasnip.lsp_expand(args.body)
47+
end,
48+
},
49+
completion = { completeopt = 'menu,menuone,noinsert' },
50+
51+
-- For an understanding of why these mappings were
52+
-- chosen, you will need to read `:help ins-completion`
53+
--
54+
-- No, but seriously. Please read `:help ins-completion`, it is really good!
55+
mapping = cmp.mapping.preset.insert {
56+
-- Select the [n]ext item
57+
['<C-n>'] = cmp.mapping.select_next_item(),
58+
-- Select the [p]revious item
59+
['<C-p>'] = cmp.mapping.select_prev_item(),
60+
61+
-- Scroll the documentation window [b]ack / [f]orward
62+
['<C-b>'] = cmp.mapping.scroll_docs(-4),
63+
['<C-f>'] = cmp.mapping.scroll_docs(4),
64+
65+
-- Accept ([y]es) the completion.
66+
-- This will auto-import if your LSP supports it.
67+
-- This will expand snippets if the LSP sent a snippet.
68+
['<C-y>'] = cmp.mapping.confirm { select = true },
69+
70+
-- Manually trigger a completion from nvim-cmp.
71+
-- Generally you don't need this, because nvim-cmp will display
72+
-- completions whenever it has completion options available.
73+
['<C-Space>'] = cmp.mapping.complete {},
74+
75+
-- Think of <c-l> as moving to the right of your snippet expansion.
76+
-- So if you have a snippet that's like:
77+
-- function $name($args)
78+
-- $body
79+
-- end
80+
--
81+
-- <c-l> will move you to the right of each of the expansion locations.
82+
-- <c-h> is similar, except moving you backwards.
83+
['<C-l>'] = cmp.mapping(function()
84+
if luasnip.expand_or_locally_jumpable() then
85+
luasnip.expand_or_jump()
86+
end
87+
end, { 'i', 's' }),
88+
['<C-h>'] = cmp.mapping(function()
89+
if luasnip.locally_jumpable(-1) then
90+
luasnip.jump(-1)
91+
end
92+
end, { 'i', 's' }),
93+
94+
-- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see:
95+
-- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps
96+
},
97+
sources = {
98+
{ name = 'nvim_lsp' },
99+
{ name = 'luasnip' },
100+
{ name = 'path' },
101+
},
102+
}
103+
end,
104+
}

lua/custom/plugins/conform.lua

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
return { -- Autoformat
2+
'stevearc/conform.nvim',
3+
lazy = false,
4+
keys = {
5+
{
6+
'<leader>f',
7+
function()
8+
require('conform').format { async = true, lsp_fallback = true }
9+
end,
10+
mode = '',
11+
desc = '[F]ormat buffer',
12+
},
13+
},
14+
opts = {
15+
notify_on_error = false,
16+
format_on_save = function(bufnr)
17+
-- Disable "format_on_save lsp_fallback" for languages that don't
18+
-- have a well standardized coding style. You can add additional
19+
-- languages here or re-enable it for the disabled ones.
20+
local disable_filetypes = { c = true, cpp = true }
21+
return {
22+
timeout_ms = 500,
23+
lsp_fallback = not disable_filetypes[vim.bo[bufnr].filetype],
24+
}
25+
end,
26+
formatters_by_ft = {
27+
lua = { 'stylua' },
28+
-- Conform can also run multiple formatters sequentially
29+
-- python = { "isort", "black" },
30+
--
31+
-- You can use a sub-list to tell conform to run *until* a formatter
32+
-- is found.
33+
-- javascript = { { "prettierd", "prettier" } },
34+
},
35+
},
36+
}

lua/custom/plugins/init.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
--
44
-- See the kickstart.nvim README for more information
55
return {
6+
{ 'tpope/vim-sleuth' }, -- Detect tabstop and shiftwidth automatically
67
{ 'ThePrimeagen/vim-be-good' },
78
{ 'ThePrimeagen/vim-be-good' },
89
{ 'github/copilot.vim' },
@@ -13,6 +14,8 @@ return {
1314
{ 'AndrewRadev/tagalong.vim' },
1415
{ 'kburdett/vim-nuuid' },
1516
{ 'vim-scripts/ReplaceWithRegister' },
17+
-- "gc" to comment visual regions/lines
18+
{ 'numToStr/Comment.nvim', opts = {} },
1619
{
1720
'windwp/nvim-autopairs',
1821
event = 'InsertEnter',
@@ -21,4 +24,6 @@ return {
2124
enable_check_bracket_line = true,
2225
},
2326
},
27+
-- Highlight todo, notes, etc in comments
28+
{ 'folke/todo-comments.nvim', event = 'VimEnter', dependencies = { 'nvim-lua/plenary.nvim' }, opts = { signs = false } },
2429
}

lua/custom/plugins/lsp.lua

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
return { -- LSP Configuration & Plugins
2+
'neovim/nvim-lspconfig',
3+
dependencies = {
4+
-- Automatically install LSPs and related tools to stdpath for Neovim
5+
'williamboman/mason.nvim',
6+
'williamboman/mason-lspconfig.nvim',
7+
'WhoIsSethDaniel/mason-tool-installer.nvim',
8+
9+
-- Useful status updates for LSP.
10+
-- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})`
11+
{ 'j-hui/fidget.nvim', opts = {} },
12+
13+
-- `neodev` configures Lua LSP for your Neovim config, runtime and plugins
14+
-- used for completion, annotations and signatures of Neovim apis
15+
{ 'folke/neodev.nvim', opts = {} },
16+
},
17+
config = function()
18+
-- Brief aside: **What is LSP?**
19+
--
20+
-- LSP is an initialism you've probably heard, but might not understand what it is.
21+
--
22+
-- LSP stands for Language Server Protocol. It's a protocol that helps editors
23+
-- and language tooling communicate in a standardized fashion.
24+
--
25+
-- In general, you have a "server" which is some tool built to understand a particular
26+
-- language (such as `gopls`, `lua_ls`, `rust_analyzer`, etc.). These Language Servers
27+
-- (sometimes called LSP servers, but that's kind of like ATM Machine) are standalone
28+
-- processes that communicate with some "client" - in this case, Neovim!
29+
--
30+
-- LSP provides Neovim with features like:
31+
-- - Go to definition
32+
-- - Find references
33+
-- - Autocompletion
34+
-- - Symbol Search
35+
-- - and more!
36+
--
37+
-- Thus, Language Servers are external tools that must be installed separately from
38+
-- Neovim. This is where `mason` and related plugins come into play.
39+
--
40+
-- If you're wondering about lsp vs treesitter, you can check out the wonderfully
41+
-- and elegantly composed help section, `:help lsp-vs-treesitter`
42+
43+
-- This function gets run when an LSP attaches to a particular buffer.
44+
-- That is to say, every time a new file is opened that is associated with
45+
-- an lsp (for example, opening `main.rs` is associated with `rust_analyzer`) this
46+
-- function will be executed to configure the current buffer
47+
vim.api.nvim_create_autocmd('LspAttach', {
48+
group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }),
49+
callback = function(event)
50+
-- NOTE: Remember that Lua is a real programming language, and as such it is possible
51+
-- to define small helper and utility functions so you don't have to repeat yourself.
52+
--
53+
-- In this case, we create a function that lets us more easily define mappings specific
54+
-- for LSP related items. It sets the mode, buffer and description for us each time.
55+
local map = function(keys, func, desc)
56+
vim.keymap.set('n', keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
57+
end
58+
59+
-- Jump to the definition of the word under your cursor.
60+
-- This is where a variable was first declared, or where a function is defined, etc.
61+
-- To jump back, press <C-t>.
62+
map('<leader>gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition')
63+
64+
-- Find references for the word under your cursor.
65+
map('<leader>gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
66+
67+
-- Jump to the implementation of the word under your cursor.
68+
-- Useful when your language has ways of declaring types without an actual implementation.
69+
map('<leader>gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
70+
71+
-- Jump to the type of the word under your cursor.
72+
-- Useful when you're not sure what type a variable is and you want to see
73+
-- the definition of its *type*, not where it was *defined*.
74+
map('<leader>D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition')
75+
76+
-- Fuzzy find all the symbols in your current document.
77+
-- Symbols are things like variables, functions, types, etc.
78+
map('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
79+
80+
-- Fuzzy find all the symbols in your current workspace.
81+
-- Similar to document symbols, except searches over your entire project.
82+
map('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
83+
84+
-- Rename the variable under your cursor.
85+
-- Most Language Servers support renaming across files, etc.
86+
map('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
87+
88+
-- Execute a code action, usually your cursor needs to be on top of an error
89+
-- or a suggestion from your LSP for this to activate.
90+
map('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
91+
92+
-- Opens a popup that displays documentation about the word under your cursor
93+
-- See `:help K` for why this keymap.
94+
map('K', vim.lsp.buf.hover, 'Hover Documentation')
95+
96+
-- WARN: This is not Goto Definition, this is Goto Declaration.
97+
-- For example, in C this would take you to the header.
98+
map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
99+
100+
-- The following two autocommands are used to highlight references of the
101+
-- word under your cursor when your cursor rests there for a little while.
102+
-- See `:help CursorHold` for information about when this is executed
103+
--
104+
-- When you move your cursor, the highlights will be cleared (the second autocommand).
105+
local client = vim.lsp.get_client_by_id(event.data.client_id)
106+
if client and client.server_capabilities.documentHighlightProvider then
107+
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
108+
buffer = event.buf,
109+
callback = vim.lsp.buf.document_highlight,
110+
})
111+
112+
vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
113+
buffer = event.buf,
114+
callback = vim.lsp.buf.clear_references,
115+
})
116+
end
117+
end,
118+
})
119+
120+
-- LSP servers and clients are able to communicate to each other what features they support.
121+
-- By default, Neovim doesn't support everything that is in the LSP specification.
122+
-- When you add nvim-cmp, luasnip, etc. Neovim now has *more* capabilities.
123+
-- So, we create new capabilities with nvim cmp, and then broadcast that to the servers.
124+
local capabilities = vim.lsp.protocol.make_client_capabilities()
125+
capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities())
126+
127+
-- Enable the following language servers
128+
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
129+
--
130+
-- Add any additional override configuration in the following tables. Available keys are:
131+
-- - cmd (table): Override the default command used to start the server
132+
-- - filetypes (table): Override the default list of associated filetypes for the server
133+
-- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features.
134+
-- - settings (table): Override the default settings passed when initializing the server.
135+
-- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
136+
local servers = {
137+
-- clangd = {},
138+
-- gopls = {},
139+
-- pyright = {},
140+
-- rust_analyzer = {},
141+
-- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs
142+
--
143+
-- Some languages (like typescript) have entire language plugins that can be useful:
144+
-- https://github.com/pmizio/typescript-tools.nvim
145+
--
146+
-- But for many setups, the LSP (`tsserver`) will work just fine
147+
-- tsserver = {},
148+
--
149+
150+
lua_ls = {
151+
-- cmd = {...},
152+
-- filetypes = { ...},
153+
-- capabilities = {},
154+
settings = {
155+
Lua = {
156+
completion = {
157+
callSnippet = 'Replace',
158+
},
159+
-- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings
160+
-- diagnostics = { disable = { 'missing-fields' } },
161+
},
162+
},
163+
},
164+
}
165+
166+
-- Ensure the servers and tools above are installed
167+
-- To check the current status of installed tools and/or manually install
168+
-- other tools, you can run
169+
-- :Mason
170+
--
171+
-- You can press `g?` for help in this menu.
172+
require('mason').setup()
173+
174+
-- You can add other tools here that you want Mason to install
175+
-- for you, so that they are available from within Neovim.
176+
local ensure_installed = vim.tbl_keys(servers or {})
177+
vim.list_extend(ensure_installed, {
178+
'stylua', -- Used to format Lua code
179+
})
180+
require('mason-tool-installer').setup { ensure_installed = ensure_installed }
181+
182+
require('mason-lspconfig').setup {
183+
handlers = {
184+
function(server_name)
185+
local server = servers[server_name] or {}
186+
-- This handles overriding only values explicitly passed
187+
-- by the server configuration above. Useful when disabling
188+
-- certain features of an LSP (for example, turning off formatting for tsserver)
189+
server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {})
190+
require('lspconfig')[server_name].setup(server)
191+
end,
192+
},
193+
}
194+
end,
195+
}

lua/custom/plugins/mini.lua

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
return { -- Collection of various small independent plugins/modules
2+
'echasnovski/mini.nvim',
3+
config = function()
4+
-- Better Around/Inside textobjects
5+
--
6+
-- Examples:
7+
-- - va) - [V]isually select [A]round [)]paren
8+
-- - yinq - [Y]ank [I]nside [N]ext [']quote
9+
-- - ci' - [C]hange [I]nside [']quote
10+
require('mini.ai').setup { n_lines = 500 }
11+
12+
-- Add/delete/replace surroundings (brackets, quotes, etc.)
13+
--
14+
-- - saiw) - [S]urround [A]dd [I]nner [W]ord [)]Paren
15+
-- - sd' - [S]urround [D]elete [']quotes
16+
-- - sr)' - [S]urround [R]eplace [)] [']
17+
require('mini.surround').setup()
18+
19+
-- Simple and easy statusline.
20+
-- You could remove this setup call if you don't like it,
21+
-- and try some other statusline plugin
22+
local statusline = require 'mini.statusline'
23+
-- set use_icons to true if you have a Nerd Font
24+
statusline.setup { use_icons = vim.g.have_nerd_font }
25+
26+
-- You can configure sections in the statusline by overriding their
27+
-- default behavior. For example, here we set the section for
28+
-- cursor location to LINE:COLUMN
29+
---@diagnostic disable-next-line: duplicate-set-field
30+
statusline.section_location = function()
31+
return '%2l:%-2v'
32+
end
33+
34+
-- ... and there is more!
35+
-- Check out: https://github.com/echasnovski/mini.nvim
36+
end,
37+
}

0 commit comments

Comments
 (0)