Added format and auto format support

This commit is contained in:
Wil Simpson 2023-02-28 14:09:49 -05:00
parent 555d200655
commit ca533432a6
1 changed files with 10 additions and 8 deletions

View File

@ -35,7 +35,6 @@ I hope you enjoy your Neovim journey,
P.S. You can delete this when you're done too. It's your config now :) P.S. You can delete this when you're done too. It's your config now :)
--]] --]]
-- Set <space> as the leader key -- Set <space> as the leader key
-- See `:help mapleader` -- See `:help mapleader`
-- NOTE: Must happen before plugins are required (otherwise wrong leader will be used) -- NOTE: Must happen before plugins are required (otherwise wrong leader will be used)
@ -97,7 +96,7 @@ require('lazy').setup({
}, },
-- Useful plugin to show you pending keybinds. -- Useful plugin to show you pending keybinds.
{ 'folke/which-key.nvim', opts = {} }, { 'folke/which-key.nvim', opts = {} },
{ -- Adds git releated signs to the gutter, as well as utilities for managing changes { -- Adds git releated signs to the gutter, as well as utilities for managing changes
'lewis6991/gitsigns.nvim', 'lewis6991/gitsigns.nvim',
opts = { opts = {
@ -144,7 +143,7 @@ require('lazy').setup({
}, },
-- "gc" to comment visual regions/lines -- "gc" to comment visual regions/lines
{ 'numToStr/Comment.nvim', opts = {} }, { 'numToStr/Comment.nvim', opts = {} },
-- Fuzzy Finder (files, lsp, etc) -- Fuzzy Finder (files, lsp, etc)
{ 'nvim-telescope/telescope.nvim', version = '*', dependencies = { 'nvim-lua/plenary.nvim' } }, { 'nvim-telescope/telescope.nvim', version = '*', dependencies = { 'nvim-lua/plenary.nvim' } },
@ -406,6 +405,8 @@ local on_attach = function(_, bufnr)
vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
vim.lsp.buf.format() vim.lsp.buf.format()
end, { desc = 'Format current buffer with LSP' }) end, { desc = 'Format current buffer with LSP' })
nmap('<leader>f', function() vim.lsp.buf.format { async = true } end, 'Auto [F]ormat')
end end
-- Enable the following language servers -- Enable the following language servers
@ -433,7 +434,6 @@ local servers = {
marksman = {}, marksman = {},
volar = {}, volar = {},
yamlls = {}, yamlls = {},
lua_ls = { lua_ls = {
Lua = { Lua = {
workspace = { checkThirdParty = false }, workspace = { checkThirdParty = false },
@ -482,7 +482,7 @@ cmp.setup {
end, end,
}, },
mapping = cmp.mapping.preset.insert { mapping = cmp.mapping.preset.insert {
['<C-d>'] = cmp.mapping.scroll_docs(-4), ['<C-d>'] = cmp.mapping.scroll_docs( -4),
['<C-f>'] = cmp.mapping.scroll_docs(4), ['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete {}, ['<C-Space>'] = cmp.mapping.complete {},
['<CR>'] = cmp.mapping.confirm { ['<CR>'] = cmp.mapping.confirm {
@ -495,14 +495,14 @@ cmp.setup {
elseif luasnip.expand_or_jumpable() then elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump() luasnip.expand_or_jump()
else else
fallback() fallback()
end end
end, { 'i', 's' }), end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback) ['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_prev_item() cmp.select_prev_item()
elseif luasnip.jumpable(-1) then elseif luasnip.jumpable( -1) then
luasnip.jump(-1) luasnip.jump( -1)
else else
fallback() fallback()
end end
@ -514,5 +514,7 @@ cmp.setup {
}, },
} }
vim.cmd [[autocmd BufWritePre * lua vim.lsp.buf.format()]]
-- The line beneath this is called `modeline`. See `:help modeline` -- The line beneath this is called `modeline`. See `:help modeline`
-- vim: ts=2 sts=2 sw=2 et -- vim: ts=2 sts=2 sw=2 et