removed dupication and refactored my keymaps
This commit is contained in:
parent
116c91c155
commit
c5d1b0ac8f
5 changed files with 217 additions and 149 deletions
|
|
@ -1,15 +1,19 @@
|
|||
-- [plugins/editing.lua]
|
||||
-- [plugins/editor.lua]
|
||||
|
||||
return {
|
||||
|
||||
|
||||
|
||||
{ -- Autoformat
|
||||
-- -- Autoformat: `conform.nvim`
|
||||
-- This plugin provides a non-LSP based way to format your code.
|
||||
{
|
||||
'stevearc/conform.nvim',
|
||||
-- Only load this plugin right before a buffer is written.
|
||||
event = { 'BufWritePre' },
|
||||
-- Add the `ConformInfo` command for debugging.
|
||||
cmd = { 'ConformInfo' },
|
||||
-- Set up keybinds for manual formatting.
|
||||
keys = {
|
||||
{
|
||||
-- The leader key followed by 'f' to format the current buffer.
|
||||
'<leader>f',
|
||||
function()
|
||||
require('conform').format { async = true, lsp_format = 'fallback' }
|
||||
|
|
@ -19,18 +23,115 @@ return {
|
|||
},
|
||||
},
|
||||
opts = {
|
||||
-- Disable notifications on formatting errors to avoid pop-ups.
|
||||
notify_on_error = false,
|
||||
-- This function runs before saving a file to check if it should be formatted.
|
||||
format_on_save = function(bufnr)
|
||||
-- A list of filetypes where auto-formatting on save is disabled.
|
||||
local disable_filetypes = { c = true, cpp = true }
|
||||
|
||||
-- Determine if LSP formatting should be used.
|
||||
local lsp_format_opt
|
||||
if disable_filetypes[vim.bo[bufnr].filetype] then
|
||||
-- If the filetype is in the disabled list, don't use LSP formatting.
|
||||
lsp_format_opt = 'never'
|
||||
else
|
||||
-- Otherwise, use LSP formatting as a fallback.
|
||||
lsp_format_opt = 'fallback'
|
||||
end
|
||||
|
||||
return {
|
||||
timeout_ms = 500,
|
||||
lsp_format = lsp_format_opt,
|
||||
}
|
||||
end,
|
||||
-- Map filetypes to specific formatters.
|
||||
formatters_by_ft = {
|
||||
lua = { 'stylua' },
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
-- -- Autocompletion: `nvim-cmp` and its dependencies
|
||||
-- This is the core of the autocompletion system.
|
||||
{
|
||||
'hrsh7th/nvim-cmp',
|
||||
-- Only load this plugin when entering insert mode.
|
||||
event = 'InsertEnter',
|
||||
dependencies = {
|
||||
-- `LuaSnip` is the snippet engine.
|
||||
{
|
||||
'L3MON4D3/LuaSnip',
|
||||
-- This build command ensures the `jsregexp` dependency is installed if needed.
|
||||
build = (function()
|
||||
if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then
|
||||
return
|
||||
end
|
||||
return { timeout_ms = 500, lsp_format = 'fallback' }
|
||||
end,
|
||||
formatters_by_ft = {
|
||||
lua = { 'stylua' },
|
||||
},
|
||||
return 'make install_jsregexp'
|
||||
end)(),
|
||||
},
|
||||
-- `cmp_luasnip` connects the snippet engine to the autocompletion.
|
||||
'saadparwaiz1/cmp_luasnip',
|
||||
-- `cmp-nvim-lsp` provides completion items from the language server.
|
||||
'hrsh7th/cmp-nvim-lsp',
|
||||
-- `cmp-path` provides completion for file paths.
|
||||
'hrsh7th/cmp-path',
|
||||
-- `lazydev` is used for runtime completion of `lazy.nvim` plugin names.
|
||||
'folke/lazydev.nvim',
|
||||
},
|
||||
config = function()
|
||||
-- Get local references to the required modules.
|
||||
local cmp = require 'cmp'
|
||||
local luasnip = require 'luasnip'
|
||||
luasnip.config.setup {}
|
||||
|
||||
-- Set up the `nvim-cmp` plugin.
|
||||
cmp.setup {
|
||||
-- Define how snippets are expanded.
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
luasnip.lsp_expand(args.body)
|
||||
end,
|
||||
},
|
||||
-- Configure the completion menu.
|
||||
completion = { completeopt = 'menu,menuone,noinsert' },
|
||||
-- Set up key mappings for various completion actions.
|
||||
mapping = cmp.mapping.preset.insert {
|
||||
-- Navigate the completion menu.
|
||||
['<C-n>'] = cmp.mapping.select_next_item(),
|
||||
['<C-p>'] = cmp.mapping.select_prev_item(),
|
||||
-- Scroll documentation.
|
||||
['<C-b>'] = cmp.mapping.scroll_docs(-4),
|
||||
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
||||
-- Confirm the selected completion item.
|
||||
['<C-y>'] = cmp.mapping.confirm { select = true },
|
||||
-- Manually trigger completion.
|
||||
['<C-Space>'] = cmp.mapping.complete {},
|
||||
-- Jump to the next part of a snippet.
|
||||
['<C-l>'] = cmp.mapping(function()
|
||||
if luasnip.expand_or_locally_jumpable() then
|
||||
luasnip.expand_or_jump()
|
||||
end
|
||||
end, { 'i', 's' }),
|
||||
-- Jump to the previous part of a snippet.
|
||||
['<C-h>'] = cmp.mapping(function()
|
||||
if luasnip.locally_jumpable(-1) then
|
||||
luasnip.jump(-1)
|
||||
end
|
||||
end, { 'i', 's' }),
|
||||
},
|
||||
-- Define the sources for completion items and their priority.
|
||||
sources = {
|
||||
{
|
||||
name = 'lazydev',
|
||||
group_index = 0,
|
||||
},
|
||||
{ name = 'nvim_lsp' },
|
||||
{ name = 'luasnip' },
|
||||
{ name = 'path' },
|
||||
},
|
||||
}
|
||||
end,
|
||||
},
|
||||
|
||||
{ -- Linting
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue