fix formatter and add keymaps to init.lua
This commit is contained in:
parent
b1bbff8470
commit
fd3d096603
15
init.lua
15
init.lua
|
@ -206,6 +206,16 @@ vim.keymap.set('n', '<leader>j', '<cmd>lprev<CR>zz')
|
||||||
|
|
||||||
vim.keymap.set('n', '<leader>x', '<cmd>!chmod +x %<CR>', { silent = true })
|
vim.keymap.set('n', '<leader>x', '<cmd>!chmod +x %<CR>', { silent = true })
|
||||||
|
|
||||||
|
|
||||||
|
-- formatter autoformat on save
|
||||||
|
local augroup = vim.api.nvim_create_augroup
|
||||||
|
local autocmd = vim.api.nvim_create_autocmd
|
||||||
|
augroup("__formatter__", { clear = true })
|
||||||
|
autocmd("BufWritePost", {
|
||||||
|
group = "__formatter__",
|
||||||
|
command = ":FormatWrite",
|
||||||
|
})
|
||||||
|
|
||||||
-- Keybinds to make split navigation easier.
|
-- Keybinds to make split navigation easier.
|
||||||
-- Use CTRL+<hjkl> to switch between windows
|
-- Use CTRL+<hjkl> to switch between windows
|
||||||
--
|
--
|
||||||
|
@ -908,7 +918,7 @@ require('lazy').setup({
|
||||||
main = 'nvim-treesitter.configs', -- Sets main module to use for opts
|
main = 'nvim-treesitter.configs', -- Sets main module to use for opts
|
||||||
-- [[ Configure Treesitter ]] See `:help nvim-treesitter`
|
-- [[ Configure Treesitter ]] See `:help nvim-treesitter`
|
||||||
opts = {
|
opts = {
|
||||||
ensure_installed = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' },
|
ensure_installed = { 'bash', 'astro', 'scala', 'c', 'go', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc', 'java', 'javascript', 'typescript' },
|
||||||
-- Autoinstall languages that are not installed
|
-- Autoinstall languages that are not installed
|
||||||
auto_install = true,
|
auto_install = true,
|
||||||
highlight = {
|
highlight = {
|
||||||
|
@ -924,7 +934,7 @@ require('lazy').setup({
|
||||||
-- with nvim-treesitter. You should go explore a few and see what interests you:
|
-- with nvim-treesitter. You should go explore a few and see what interests you:
|
||||||
--
|
--
|
||||||
-- - Incremental selection: Included, see `:help nvim-treesitter-incremental-selection-mod`
|
-- - Incremental selection: Included, see `:help nvim-treesitter-incremental-selection-mod`
|
||||||
-- - Show your current context: https://github.com/nvim-treesitter/nvim-treesitter-context
|
-- - Show your current context: https://:github.com/nvim-treesitter/nvim-treesitter-context
|
||||||
-- - Treesitter + textobjects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects
|
-- - Treesitter + textobjects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -944,6 +954,7 @@ require('lazy').setup({
|
||||||
require 'kickstart.plugins.neo-tree',
|
require 'kickstart.plugins.neo-tree',
|
||||||
require 'custom.plugins.harpoon',
|
require 'custom.plugins.harpoon',
|
||||||
require 'custom.plugins.copilot',
|
require 'custom.plugins.copilot',
|
||||||
|
require 'custom.plugins.formatter',
|
||||||
-- require 'kickstart.plugins.gitsigns', -- adds gitsigns recommend keymaps
|
-- require 'kickstart.plugins.gitsigns', -- adds gitsigns recommend keymaps
|
||||||
|
|
||||||
-- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua`
|
-- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua`
|
||||||
|
|
|
@ -0,0 +1,108 @@
|
||||||
|
-- You can add your own plugins here or in other files in this directory!
|
||||||
|
-- I promise not to create any merge conflicts in this directory :)
|
||||||
|
--
|
||||||
|
-- See the kickstart.nvim README for more information
|
||||||
|
return {
|
||||||
|
'mhartington/formatter.nvim',
|
||||||
|
config = function()
|
||||||
|
local util = require 'formatter.util'
|
||||||
|
|
||||||
|
require('formatter').setup {
|
||||||
|
|
||||||
|
|
||||||
|
-- Enable or disable logging
|
||||||
|
logging = true,
|
||||||
|
-- Set the log level
|
||||||
|
log_level = vim.log.levels.WARN,
|
||||||
|
-- All formatter configurations are opt-in
|
||||||
|
filetype = {
|
||||||
|
typescript = {
|
||||||
|
function()
|
||||||
|
return {
|
||||||
|
exe = 'prettier',
|
||||||
|
args = {
|
||||||
|
'--stdin-filepath',
|
||||||
|
util.escape_path(util.get_current_buffer_file_path()),
|
||||||
|
},
|
||||||
|
stdin = true,
|
||||||
|
try_node_modules = true,
|
||||||
|
}
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
javascript = {
|
||||||
|
function()
|
||||||
|
return {
|
||||||
|
exe = 'prettier',
|
||||||
|
args = {
|
||||||
|
'--stdin-filepath',
|
||||||
|
util.escape_path(util.get_current_buffer_file_path()),
|
||||||
|
},
|
||||||
|
stdin = true,
|
||||||
|
try_node_modules = true,
|
||||||
|
}
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
javascriptreact = {
|
||||||
|
require('formatter.filetypes.javascriptreact').prettier,
|
||||||
|
|
||||||
|
function()
|
||||||
|
return {
|
||||||
|
exe = 'prettier',
|
||||||
|
args = {
|
||||||
|
'--stdin-filepath',
|
||||||
|
util.escape_path(util.get_current_buffer_file_path()),
|
||||||
|
},
|
||||||
|
stdin = true,
|
||||||
|
try_node_modules = true,
|
||||||
|
}
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
typescriptreact = {
|
||||||
|
require('formatter.filetypes.typescriptreact').prettier,
|
||||||
|
|
||||||
|
function()
|
||||||
|
return {
|
||||||
|
exe = 'prettier',
|
||||||
|
args = {
|
||||||
|
'--stdin-filepath',
|
||||||
|
util.escape_path(util.get_current_buffer_file_path()),
|
||||||
|
},
|
||||||
|
stdin = true,
|
||||||
|
try_node_modules = true,
|
||||||
|
}
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
go = {
|
||||||
|
require('formatter.filetypes.go').gofmt,
|
||||||
|
require('formatter.filetypes.go').goimports,
|
||||||
|
},
|
||||||
|
|
||||||
|
astro = {
|
||||||
|
function()
|
||||||
|
return {
|
||||||
|
exe = 'prettier',
|
||||||
|
args = {
|
||||||
|
'--stdin-filepath',
|
||||||
|
util.escape_path(util.get_current_buffer_file_path()),
|
||||||
|
},
|
||||||
|
stdin = true,
|
||||||
|
try_node_modules = true,
|
||||||
|
}
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
-- Use the special "*" filetype for defining formatter configurations on
|
||||||
|
-- any filetype
|
||||||
|
['*'] = {
|
||||||
|
-- "formatter.filetypes.any" defines default configurations for any
|
||||||
|
-- filetype
|
||||||
|
require('formatter.filetypes.any').remove_trailing_whitespace,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end,
|
||||||
|
}
|
Loading…
Reference in New Issue