add formatters and cool stuff

This commit is contained in:
Youwen Wu 2024-10-10 00:48:10 -07:00
parent adcd621763
commit c3ee469ed5
Signed by: youwen5
GPG key ID: 865658ED1FE61EC3
10 changed files with 766 additions and 697 deletions

View file

@ -1 +1,2 @@
indent_type = "Spaces"
indent_width = 2

View file

@ -151,6 +151,12 @@
lua-language-server
nixd
nixfmt-rfc-style
nodePackages_latest.prettier
taplo
typstyle
rustfmt
black
stylua
];
};
@ -226,6 +232,7 @@
diffview-nvim
barbecue-nvim
undotree
conform-nvim
];
};

View file

@ -9,10 +9,10 @@ vim.keymap.set("t", "<C-Esc>", "<C-\\><C-n>")
vim.keymap.set("n", "<C-d>", "<C-d>zz")
vim.keymap.set("n", "<C-u>", "<C-u>zz")
vim.keymap.set("n", "<leader>mr", function ()
vim.keymap.set("n", "<leader>mr", function()
vim.cmd.CellularAutomaton("make_it_rain")
end)
vim.keymap.set("n", "<leader>bruh", function ()
vim.keymap.set("n", "<leader>bruh", function()
vim.cmd.CellularAutomaton("game_of_life")
end)
@ -21,21 +21,39 @@ vim.keymap.set("n", "n", "nzzzv")
vim.keymap.set("n", "N", "Nzzzv")
-- The greatest remap of all time -- the primeagen
vim.keymap.set({"n", "v"}, "<leader>d",'"_d', { desc = "same as `d` but send to black hole register"})
vim.keymap.set({"n", "v"}, "<leader>D",'"_D', { desc = "same as `D` but send to black hole register"})
vim.keymap.set({ "n", "v" }, "<leader>d", '"_d', { desc = "same as `d` but send to black hole register" })
vim.keymap.set({ "n", "v" }, "<leader>D", '"_D', { desc = "same as `D` but send to black hole register" })
-- The real greatest remap(s) of all time -- me
vim.keymap.set({"n", "v"}, "<leader>y",'"+y', { desc = "yank to clipboard"})
vim.keymap.set({"n", "v"}, "<leader>Y",'"+Y', { desc = "yank rest of line to clipboard"})
vim.keymap.set({"n", "v"}, "<leader>p",'"+p', { desc = "put after cursor from clipboard"})
vim.keymap.set({"n", "v"}, "<leader>P",'"+P', { desc = "put before cursor from clipboard"})
vim.keymap.set({ "n", "v" }, "<leader>y", '"+y', { desc = "yank to clipboard" })
vim.keymap.set({ "n", "v" }, "<leader>Y", '"+Y', { desc = "yank rest of line to clipboard" })
vim.keymap.set({ "n", "v" }, "<leader>p", '"+p', { desc = "put after cursor from clipboard" })
vim.keymap.set({ "n", "v" }, "<leader>P", '"+P', { desc = "put before cursor from clipboard" })
vim.keymap.set("n", "<leader>gg", function ()
vim.keymap.set("n", "<leader>gg", function()
vim.cmd.Neogit()
end, { desc = "Open neogit" })
vim.keymap.set("n", "<leader>gc", function ()
vim.keymap.set("n", "<leader>gc", function()
vim.cmd.Neogit("kind=floating commit")
end, { desc = "Open neogit commit menu" })
vim.keymap.set("n", "<leader>u", function ()
vim.keymap.set("n", "<leader>u", function()
vim.cmd.UndotreeToggle()
end, {desc = "Toggle undotree"})
end, { desc = "Toggle undotree" })
vim.keymap.set({ "n", "v" }, "<leader>cf", function()
require("conform").format({ async = true })
end)
vim.keymap.set({ "n", "v" }, "<leader>ctf", function()
if vim.g.disable_autoformat then
vim.g.disable_autoformat = false
else
vim.g.disable_autoformat = true
end
end, { desc = "Disable autoformat on save globally" })
vim.keymap.set({ "n", "v" }, "<leader>cbf", function()
if vim.b[0].disable_autoformat then
vim.b[0].disable_autoformat = false
else
vim.b[0].disable_autoformat = true
end
end, { desc = "Disable autoformat on save buffer" })

View file

@ -78,7 +78,7 @@ return {
prebuiltBinaries = {
-- Whether or not to automatically download a prebuilt binary from github. If this is set to `false`
-- you will need to manually build the fuzzy binary dependencies by running `cargo build --release`
download = true,
download = false,
-- When downloading a prebuilt binary force the downloader to resolve this version. If this is uset
-- then the downloader will attempt to infer the version from the checked out git tag (if any).
--

34
lua/plugins/conform.lua Normal file
View file

@ -0,0 +1,34 @@
return {
"conform.nvim",
event = "BufWritePre",
cmd = "ConformInfo",
after = function()
require("conform").setup({
format_on_save = function(bufnr)
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
return
end
return { timeout_ms = 500, lsp_fallback = true }
end,
default_format_opts = {
lsp_format = "fallback",
},
formatters_by_ft = {
lua = { "stylua" },
python = { "black" },
rust = { "rustfmt" },
javascript = { "prettierd", "prettier", stop_after_first = true },
typescript = { "prettierd", "prettier", stop_after_first = true },
nix = { "nixfmt" },
haskell = { "fourmolu", "ormolu", stop_after_first = true },
json = { "prettierd", "prettier", stop_after_first = true },
toml = { "taplo", stop_after_first = true },
yaml = { "prettierd", "prettier", stop_after_first = true },
typst = { "typstyle" },
},
})
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
end,
}

View file

@ -42,4 +42,4 @@ return {
toggle_telescope(harpoon:list())
end, { desc = "Open harpoon window" })
end,
}
}

View file

@ -46,13 +46,12 @@ return {
inactive_winbar = {},
extensions = {},
})
-- listen lsp-progress event and refresh lualine
vim.api.nvim_create_augroup("lualine_augroup", { clear = true })
vim.api.nvim_create_autocmd("User", {
-- listen lsp-progress event and refresh lualine
vim.api.nvim_create_augroup("lualine_augroup", { clear = true })
vim.api.nvim_create_autocmd("User", {
group = "lualine_augroup",
pattern = "LspProgressStatusUpdated",
callback = require("lualine").refresh,
})
})
end,
}

View file

@ -4,7 +4,9 @@ return {
require("plugins.oil"),
require("plugins.harpoon"),
require("plugins.lualine"),
{ "lsp-progress",
require("plugins.conform"),
{
"lsp-progress",
after = function()
require("lsp-progress").setup({
client_format = function(client_name, spinner, series_messages)
@ -37,11 +39,7 @@ return {
end)
local builder = {}
for _, cli in ipairs(lsp_clients) do
if
type(cli) == "table"
and type(cli.name) == "string"
and string.len(cli.name) > 0
then
if type(cli) == "table" and type(cli.name) == "string" and string.len(cli.name) > 0 then
if messages_map[cli.name] then
table.insert(builder, stringify(cli.name, messages_map[cli.name]))
else
@ -56,7 +54,7 @@ return {
return ""
end,
})
end
end,
},
{ "telescope-ui-select.nvim", priority = 70 },
{
@ -148,36 +146,36 @@ return {
event = "BufEnter",
after = function()
require("mini.ai").setup()
end
end,
},
{
"mini.surround",
event = "BufEnter",
after = function()
require("mini.surround").setup()
end
end,
},
{
"mini.starter",
after = function ()
after = function()
require("mini.starter").setup()
end
end,
},
{
"mini.notify",
event = "BufEnter",
after = function ()
after = function()
require("mini.notify").setup({
lsp_progress = { enable = false }
lsp_progress = { enable = false },
})
end
end,
},
{
"mini.trailspace",
event = "BufEnter",
after = function ()
after = function()
require("mini.trailspace").setup()
end
end,
},
{
"cellular-automaton.nvim",
@ -185,7 +183,7 @@ return {
},
{
"indent-blankline.nvim",
after = function ()
after = function()
require("ibl").setup({
indent = {
char = "",
@ -201,35 +199,34 @@ return {
"toggleterm",
},
},
}
)
end
})
end,
},
{
"mini.bufremove",
event = "BufEnter",
after = function ()
after = function()
require("mini.bufremove").setup()
vim.keymap.set({"n", "v"}, "<leader>bd", function ()
vim.keymap.set({ "n", "v" }, "<leader>bd", function()
MiniBufremove.delete()
end)
end
end,
},
{
"mini.hipatterns",
event = "BufEnter",
after = function ()
after = function()
require("mini.hipatterns").setup()
end
end,
},
{
"gitsigns.nvim",
event = "BufEnter",
after = function ()
require('gitsigns').setup{
after = function()
require("gitsigns").setup({
on_attach = function(bufnr)
local gitsigns = require('gitsigns')
local gitsigns = require("gitsigns")
local function map(mode, l, r, opts)
opts = opts or {}
@ -238,59 +235,67 @@ return {
end
-- Navigation
map('n', ']c', function()
map("n", "]c", function()
if vim.wo.diff then
vim.cmd.normal({']c', bang = true})
vim.cmd.normal({ "]c", bang = true })
else
gitsigns.nav_hunk('next')
gitsigns.nav_hunk("next")
end
end)
map('n', '[c', function()
map("n", "[c", function()
if vim.wo.diff then
vim.cmd.normal({'[c', bang = true})
vim.cmd.normal({ "[c", bang = true })
else
gitsigns.nav_hunk('prev')
gitsigns.nav_hunk("prev")
end
end)
-- Actions
map('n', '<leader>gs', gitsigns.stage_hunk)
map('n', '<leader>gr', gitsigns.reset_hunk)
map('v', '<leader>gs', function() gitsigns.stage_hunk {vim.fn.line('.'), vim.fn.line('v')} end)
map('v', '<leader>gr', function() gitsigns.reset_hunk {vim.fn.line('.'), vim.fn.line('v')} end)
map('n', '<leader>gS', gitsigns.stage_buffer)
map('n', '<leader>gu', gitsigns.undo_stage_hunk)
map('n', '<leader>gR', gitsigns.reset_buffer)
map('n', '<leader>gp', gitsigns.preview_hunk)
map('n', '<leader>gb', function() gitsigns.blame_line{full=true} end)
map('n', '<leader>gb', gitsigns.toggle_current_line_blame)
map('n', '<leader>gd', gitsigns.diffthis)
map('n', '<leader>gD', function() gitsigns.diffthis('~') end)
map('n', '<leader>gtd', gitsigns.toggle_deleted)
map("n", "<leader>gs", gitsigns.stage_hunk)
map("n", "<leader>gr", gitsigns.reset_hunk)
map("v", "<leader>gs", function()
gitsigns.stage_hunk({ vim.fn.line("."), vim.fn.line("v") })
end)
map("v", "<leader>gr", function()
gitsigns.reset_hunk({ vim.fn.line("."), vim.fn.line("v") })
end)
map("n", "<leader>gS", gitsigns.stage_buffer)
map("n", "<leader>gu", gitsigns.undo_stage_hunk)
map("n", "<leader>gR", gitsigns.reset_buffer)
map("n", "<leader>gp", gitsigns.preview_hunk)
map("n", "<leader>gb", function()
gitsigns.blame_line({ full = true })
end)
map("n", "<leader>gb", gitsigns.toggle_current_line_blame)
map("n", "<leader>gd", gitsigns.diffthis)
map("n", "<leader>gD", function()
gitsigns.diffthis("~")
end)
map("n", "<leader>gtd", gitsigns.toggle_deleted)
-- Text object
map({'o', 'x'}, 'ih', ':<C-U>Gitsigns select_hunk<CR>')
end
}
end
map({ "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>")
end,
})
end,
},
{
"neogit",
cmd = "Neogit",
after = function ()
after = function()
require("neogit").setup({
graph_style = "unicode",
integrations = {
telescope = true,
diffview = true
}
diffview = true,
},
})
end
end,
},
{
"diffiew.nvim",
cmd = {"DiffviewOpen", "DiffviewClose", "DiffviewToggleFiles", "DiffviewFocusFiles", "DiffviewRefresh"},
cmd = { "DiffviewOpen", "DiffviewClose", "DiffviewToggleFiles", "DiffviewFocusFiles", "DiffviewRefresh" },
},
{
"barbecue.nvim",
@ -318,10 +323,10 @@ return {
require("barbecue.ui").update()
end,
})
end
end,
},
{
"undotree",
cmd = "UndotreeToggle"
}
}
cmd = "UndotreeToggle",
},
}

View file

@ -29,8 +29,13 @@ return {
vim.keymap.set("n", "<leader>gd", builtin.lsp_definitions, { desc = "Go to LSP definition" })
vim.keymap.set("n", "<leader>gi", builtin.lsp_implementations, { desc = "Go to implementations" })
vim.keymap.set("n", "<leader>j", builtin.lsp_document_symbols, { desc = "Search through document symbols" })
vim.keymap.set("n", "<leader>fs", builtin.lsp_workspace_symbols, { desc = "Search through entire workspace symbols" })
vim.keymap.set(
"n",
"<leader>fs",
builtin.lsp_workspace_symbols,
{ desc = "Search through entire workspace symbols" }
)
vim.keymap.set("n", "<leader>fd", builtin.diagnostics, { desc = "Search through LSP diagnostics" })
end,
priority = 60
priority = 60,
}