Added refactoring and friendly-snippets

This commit is contained in:
2025-01-30 23:11:04 +11:00
parent d1a9f40a4a
commit 70c668cd2c
4 changed files with 182 additions and 112 deletions

View File

@@ -22,6 +22,7 @@ Plugins are managed using [lazy.nvim](https://github.com/folke/lazy.nvim)
- [Markdown Preview](#markdown-preview)
- [NVIM Web Devicons](#nvim-web-devicons)
- [Oil](#oil)
- [Refactoring](#refactoring)
- [SUDA](#suda)
- [Surround](#surround)
- [Telescope](#telescope)
@@ -121,6 +122,20 @@ Provides Nerd font icons for other plugins to use
#### [Oil](https://github.com/stevearc/oil.nvim)
Edit/view your filesystem like a normal NeoVim buffer
---
#### [Refactoring](https://github.com/ThePrimeagen/refactoring.nvim)
Quickly refactor variables and functions
| Keybind | Functionality | Mode |
|---------|---------------|------|
| `<leader>re` | Extract selection to new function | Visual, Select |
| `<leader>rf` | Extract selection to new file | Visual, Select |
| `<leader>rv` | Extract selection to new variable | Visual, Select |
| `<leader>ri` | Inline variation | Normal, Visual, Select |
| `<leader>rI` | Inline function | Normal |
| `<leader>rb` | Extract current block | Normal |
| `<leader>rbf` | Extract current block to file | Normal |
---
#### [SUDA](https://github.com/lambdalisue/vim-suda)
Write files using sudo inside NeoVim
@@ -260,6 +275,13 @@ LSP has been setup with the following dependencies:
- html
- jsonls
- pyright
- ts_ls
LuaSnip has been configured with the following dependencies:
- rafamadriz/friendly-snippets
- benfowler/telescope-luasnip.nvim
Run `:Telescope luasnip` to search the loaded snippets
| Keybind | Functionality | Mode |
|---------|---------------|------|
@@ -267,6 +289,7 @@ LSP has been setup with the following dependencies:
| `Ctrl + n` | auto-complete select next item | Normal |
| `Ctrl + y` | auto-complete confirm selected item | Normal |
| `Ctrl + space` | invoke auto-complete | Normal |
| `Enter` | Confirm the selected auto-complete/snippet (excluding preselect), otherwise CR | Normal |
| `gd` | jumps to the definition of the symbol under the cursor | Normal |
| `K` | displays hover information about the symbol under the cursor | Normal |
| `<leader>vws` | lists all symbols in the current workspace matching {query} | Normal |

View File

@@ -1,44 +1,44 @@
{
"Comment.nvim": { "branch": "master", "commit": "e30b7f2008e52442154b66f7c519bfd2f1e32acb" },
"LuaSnip": { "branch": "master", "commit": "c9b9a22904c97d0eb69ccb9bab76037838326817" },
"aerial.nvim": { "branch": "master", "commit": "4c959cf65c5420d54b24b61a77b681dcfca0bc57" },
"animation.nvim": { "branch": "main", "commit": "fb77091ab72ec9971aee0562e7081182527aaa6a" },
"aerial.nvim": { "branch": "master", "commit": "2aeafd99937602fc40609ffffbdd2f99d77343e9" },
"cellular-automaton.nvim": { "branch": "main", "commit": "11aea08aa084f9d523b0142c2cd9441b8ede09ed" },
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
"cmp-cmdline": { "branch": "main", "commit": "d250c63aa13ead745e3a40f61fdd3470efde3923" },
"cmp-nvim-lsp": { "branch": "main", "commit": "99290b3ec1322070bcfb9e846450a46f6efa50f0" },
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" },
"conform.nvim": { "branch": "master", "commit": "bf94626f32fbc3c9987ce2f4aab60d96866587df" },
"feline.nvim": { "branch": "main", "commit": "9f1313f61a75ec5ebe805fedd46bdc130c420963" },
"conform.nvim": { "branch": "master", "commit": "363243c03102a531a8203311d4f2ae704c620d9b" },
"feline.nvim": { "branch": "main", "commit": "8184e3765d2a604b73c059f7eeab73212575fb0e" },
"fidget.nvim": { "branch": "main", "commit": "a0abbf18084b77d28bc70e24752e4f4fd54aea17" },
"gitsigns.nvim": { "branch": "main", "commit": "632fda72df903255dc1683cd739dceaa7338128a" },
"friendly-snippets": { "branch": "main", "commit": "efff286dd74c22f731cdec26a70b46e5b203c619" },
"gitsigns.nvim": { "branch": "main", "commit": "c6fedfd0b1715ee624384b134becec0a7b0a3d28" },
"harpoon": { "branch": "harpoon2", "commit": "a84ab829eaf3678b586609888ef52f7779102263" },
"hererocks": { "branch": "master", "commit": "c9c5444dea1e07e005484014a8231aa667be30b6" },
"lazy.nvim": { "branch": "main", "commit": "d8f26efd456190241afd1b0f5235fe6fdba13d4a" },
"markdown-preview.nvim": { "branch": "master", "commit": "a923f5fc5ba36a3b17e289dc35dc17f66d0548ee" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "e942edf5c85b6a2ab74059ea566cac5b3e1514a4" },
"mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" },
"middleclass": { "branch": "master", "commit": "9fab4d5bca67262614960960ca35c4740eb2be2c" },
"nvim": { "branch": "main", "commit": "f67b886d65a029f12ffa298701fb8f1efd89295d" },
"nvim-cmp": { "branch": "main", "commit": "8c82d0bd31299dbff7f8e780f5e06d2283de9678" },
"nvim-lspconfig": { "branch": "master", "commit": "513f4f0bde469ecb3abe2e1b606f63cf142e751e" },
"nvim-cmp": { "branch": "main", "commit": "12509903a5723a876abd65953109f926f4634c30" },
"nvim-lspconfig": { "branch": "master", "commit": "bf81bef7d75a0f4a0cf61462b318ea00b3c97cc8" },
"nvim-surround": { "branch": "main", "commit": "ae298105122c87bbe0a36b1ad20b06d417c0433e" },
"nvim-treesitter": { "branch": "master", "commit": "4862ab0aca21e92771b72e2d7e70424b250f0dd4" },
"nvim-web-devicons": { "branch": "master", "commit": "aafa5c187a15701a7299a392b907ec15d9a7075f" },
"oil.nvim": { "branch": "master", "commit": "c80fa5c415b882c1c694a32748cea09b7dafc2c5" },
"nvim-treesitter": { "branch": "master", "commit": "13f4346876f394973ff676670304a2b734174538" },
"nvim-web-devicons": { "branch": "master", "commit": "1c9136332840edee0c593f2f4f89598c8ed97f5f" },
"oil.nvim": { "branch": "master", "commit": "add50252b5e9147c0a09d36480d418c7e2737472" },
"plenary": { "branch": "master", "commit": "3707cdb1e43f5cea73afb6037e6494e7ce847a66" },
"plenary.nvim": { "branch": "master", "commit": "3707cdb1e43f5cea73afb6037e6494e7ce847a66" },
"refactoring.nvim": { "branch": "master", "commit": "2db6d378e873de31d18ade549c2edba64ff1c2e3" },
"telescope-luasnip.nvim": { "branch": "master", "commit": "07a2a2936a7557404c782dba021ac0a03165b343" },
"telescope.nvim": { "branch": "master", "commit": "d90956833d7c27e73c621a61f20b29fdb7122709" },
"todo-comments.nvim": { "branch": "main", "commit": "304a8d204ee787d2544d8bc23cd38d2f929e7cc5" },
"trouble.nvim": { "branch": "main", "commit": "50481f414bd3c1a40122c1d759d7e424d5fafe84" },
"trouble.nvim": { "branch": "main", "commit": "6f380b8826fb819c752c8fd7daaee9ef96d4c689" },
"undotree": { "branch": "master", "commit": "2556c6800b210b2096b55b66e74b4cc1d9ebbe4f" },
"vim-be-good": { "branch": "master", "commit": "0ae3de14eb8efc6effe7704b5e46495e91931cc5" },
"vim-dadbod": { "branch": "master", "commit": "96997dac981d50717a63d4dbd48d4a43e09ecf57" },
"vim-dadbod-completion": { "branch": "master", "commit": "95cbcf21ea7a5c8c025f387280c2e261b8cb3a89" },
"vim-dadbod-ui": { "branch": "master", "commit": "65454e2011c029922c2c972d63f8bf04282de033" },
"vim-dadbod": { "branch": "master", "commit": "9f0ca8bcef704659820a95c3bbd2c262583a66a1" },
"vim-dadbod-completion": { "branch": "master", "commit": "c7f1be21a08b8fc9d927a19db89a4aa995402787" },
"vim-dadbod-ui": { "branch": "master", "commit": "f4d37b7312ae6489e5c04bee654ca521baac188a" },
"vim-fugitive": { "branch": "master", "commit": "d74a7cff4cfcf84f83cc7eccfa365488f3bbabc2" },
"vim-suda": { "branch": "master", "commit": "9adda7d195222d4e2854efb2a88005a120296c47" },
"vim-tmux-navigator": { "branch": "master", "commit": "d847ea942a5bb4d4fab6efebc9f30d787fd96e65" },
"windows.nvim": { "branch": "main", "commit": "c7492552b23d0ab30325e90b56066ec51242adc8" }
"vim-tmux-navigator": { "branch": "master", "commit": "d847ea942a5bb4d4fab6efebc9f30d787fd96e65" }
}

View File

@@ -8,20 +8,34 @@ return {
"hrsh7th/cmp-path",
"hrsh7th/cmp-cmdline",
"hrsh7th/nvim-cmp",
{
"L3MON4D3/LuaSnip",
dependencies = {
"rafamadriz/friendly-snippets",
"benfowler/telescope-luasnip.nvim",
},
config = function(_, opts)
if opts then
require("luasnip").config.setup(opts)
end
vim.tbl_map(function(type)
require("luasnip.loaders.from_" .. type).lazy_load()
end, { "vscode", "snipmate", "lua" })
end,
},
"saadparwaiz1/cmp_luasnip",
"j-hui/fidget.nvim",
},
config = function()
local cmp = require('cmp')
local cmp = require("cmp")
local cmp_lsp = require("cmp_nvim_lsp")
local capabilities = vim.tbl_deep_extend(
"force",
{},
vim.lsp.protocol.make_client_capabilities(),
cmp_lsp.default_capabilities())
cmp_lsp.default_capabilities()
)
require("fidget").setup({})
require("mason").setup()
require("mason-lspconfig").setup({
@@ -36,30 +50,30 @@ return {
"html",
"jsonls",
"pyright",
"ts_ls",
},
handlers = {
function(server_name) -- default handler (optional)
require("lspconfig")[server_name].setup {
capabilities = capabilities
}
require("lspconfig")[server_name].setup({
capabilities = capabilities,
})
end,
["lua_ls"] = function()
local lspconfig = require("lspconfig")
lspconfig.lua_ls.setup {
lspconfig.lua_ls.setup({
capabilities = capabilities,
settings = {
Lua = {
runtime = { version = "Lua 5.1" },
diagnostics = {
globals = { "vim", "it", "describe", "before_each", "after_each" },
}
}
}
}
},
},
},
})
end,
}
},
})
local cmp_select = { behavior = cmp.SelectBehavior.Select }
@@ -67,21 +81,32 @@ return {
cmp.setup({
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
require("luasnip").lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
['<C-y>'] = cmp.mapping.confirm({ select = true }),
["<C-p>"] = cmp.mapping.select_prev_item(cmp_select),
["<C-n>"] = cmp.mapping.select_next_item(cmp_select),
["<C-y>"] = cmp.mapping.confirm({ select = true }),
["<C-Space>"] = cmp.mapping.complete(),
["<CR>"] = cmp.mapping({
i = function(fallback)
if cmp.visible() and cmp.get_active_entry() then
cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false })
else
fallback()
end
end,
s = cmp.mapping.confirm({ select = true }),
c = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }),
}),
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'luasnip' }, -- For luasnip users.
{ name = "luasnip" }, -- For luasnip users.
{ name = "nvim_lsp" },
}, {
{ name = 'buffer' },
})
{ name = "buffer" },
}),
})
vim.diagnostic.config({
@@ -98,5 +123,5 @@ return {
prefix = "",
},
})
end
end,
}

View File

@@ -0,0 +1,22 @@
return {
"ThePrimeagen/refactoring.nvim",
dependencies = {
{ "nvim-lua/plenary.nvim" },
{ "nvim-treesitter/nvim-treesitter" },
},
lazy = false,
config = function()
require("refactoring").setup()
vim.keymap.set("x", "<leader>re", ":Refactor extract ")
vim.keymap.set("x", "<leader>rf", ":Refactor extract_to_file ")
vim.keymap.set("x", "<leader>rv", ":Refactor extract_var ")
vim.keymap.set({ "n", "x" }, "<leader>ri", ":Refactor inline_var")
vim.keymap.set("n", "<leader>rI", ":Refactor inline_func")
vim.keymap.set("n", "<leader>rb", ":Refactor extract_block")
vim.keymap.set("n", "<leader>rbf", ":Refactor extract_block_to_file")
end,
}