Skip to content

Commit

Permalink
[neovim] Add conform plugin / Fix issue with cmp confirmation key
Browse files Browse the repository at this point in the history
  • Loading branch information
sestrella committed Apr 9, 2024
1 parent ca47f4a commit f244a53
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
1 change: 1 addition & 0 deletions home/neovim/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
./plugins/auto-dark-mode
./plugins/cmp
./plugins/comment
./plugins/conform
./plugins/gitsigns
./plugins/lspconfig
./plugins/lualine
Expand Down
8 changes: 6 additions & 2 deletions home/neovim/plugins/cmp/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ cmp.setup({
documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
["<C-Space>"] = cmp.mapping.complete(),
["<C-y>"] = cmp.mapping.confirm({ select = true }),

["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<Tab>"] = cmp.mapping.confirm({ select = true }),

["<C-n>"] = cmp.mapping.select_next_item(),
["<C-p>"] = cmp.mapping.select_prev_item(),
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
Expand Down
19 changes: 19 additions & 0 deletions home/neovim/plugins/conform/config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
local conform = require("conform")

conform.setup({
notify_on_error = false,
format_on_save = {
timeout_ms = 500,
lsp_fallback = true,
},
formatters_by_ft = {
lua = { "stylua" },
},
})

vim.api.nvim_create_autocmd("BufWritePre", {
pattern = "*",
callback = function(args)
require("conform").format({ bufnr = args.buf })
end,
})
9 changes: 9 additions & 0 deletions home/neovim/plugins/conform/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{ pkgs, ... }:

[
{
plugin = pkgs.vimPlugins.conform-nvim;
config = builtins.readFile ./config.lua;
type = "lua";
}
]
5 changes: 0 additions & 5 deletions home/neovim/plugins/lspconfig/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,5 @@ vim.api.nvim_create_autocmd("LspAttach", {
map("<leader>ca", vim.lsp.buf.code_action, "[C]ode [A]ction")
map("<leader>rn", vim.lsp.buf.rename, "[R]e[n]ame")
map("K", vim.lsp.buf.hover, "Hover Documentation")

-- TODO: Replace this with https://github.com/stevearc/conform.nvim
map("<space>f", function()
vim.lsp.buf.format({ async = true })
end, "[F]ormat [C]ode")
end,
})

0 comments on commit f244a53

Please sign in to comment.