Skip to content

Commit

Permalink
refactor(nvim): use snacks.nvim
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Nov 8, 2024
1 parent 2590324 commit 5301eb8
Show file tree
Hide file tree
Showing 15 changed files with 287 additions and 776 deletions.
5 changes: 4 additions & 1 deletion .config/nix/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
outputs = inputs: {
darwinConfigurations.tmm = inputs.darwin.lib.darwinSystem {
system = "aarch64-darwin";
pkgs = import inputs.nixpkgs { system = "aarch64-darwin"; };
pkgs = import inputs.nixpkgs {
system = "aarch64-darwin";
config.allowUnfree = true;
};
modules = [
./modules/darwin.nix
inputs.home-manager.darwinModules.home-manager
Expand Down
1 change: 1 addition & 0 deletions .config/nix/modules/home-manager.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
programs.gh = {
enable = true;
extensions = with pkgs; [
gh-copilot
gh-poi
];
};
Expand Down
1 change: 1 addition & 0 deletions .config/nix/modules/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
fup = "echo $fish_user_paths | tr \" \" \"\n\" | nl";
ghostty = "/Applications/Ghostty.app/Contents/MacOS/ghostty";
h = "env GIT_WORK_TREE=$HOME GIT_DIR=$HOME/.files";
howto = "gh copilot suggest -t shell";
ls = "eza";
reload = "exec $SHELL -l";
vim = "nvim";
Expand Down
1 change: 1 addition & 0 deletions .config/nvim/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- add lazyvim news https://github.com/LazyVim/LazyVim/blob/3dbace941ee935c89c73fd774267043d12f57fe2/lua/lazyvim/util/news.lua
- .files show up in telescope (e.g. `.env`)
- separate repo for dotfiles (remove bare git repo)
- https://starship.rs

## Issues

Expand Down
19 changes: 10 additions & 9 deletions .config/nvim/lazy-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,45 @@
"conform.nvim": { "branch": "master", "commit": "d28ccf945374edd9f1c34a82f6c22261dbd8ab98" },
"copilot-cmp": { "branch": "master", "commit": "b6e5286b3d74b04256d0a7e3bd2908eabec34b44" },
"copilot.lua": { "branch": "master", "commit": "f8d8d872bb319f640d5177dad5fbf01f7a16d7d0" },
"dressing.nvim": { "branch": "master", "commit": "c334ac73e031f0dc93d6d91f3658ee75b8be1d3b" },
"dressing.nvim": { "branch": "master", "commit": "6ef1ca479d37d4ff66f13eed44d08912caff483a" },
"edgy.nvim": { "branch": "main", "commit": "7e8dedc39abebe40c289b8012cc89b11c69aa7a0" },
"flash.nvim": { "branch": "main", "commit": "34c7be146a91fec3555c33fe89c7d643f6ef5cf1" },
"friendly-snippets": { "branch": "main", "commit": "de8fce94985873666bd9712ea3e49ee17aadb1ed" },
"gitsigns.nvim": { "branch": "main", "commit": "4daf7022f1481edf1e8fb9947df13bb07c18e89a" },
"indent-blankline.nvim": { "branch": "master", "commit": "04e44b09ee3ff189c69ab082edac1ef7ae2e256c" },
"lazy.nvim": { "branch": "main", "commit": "b1134ab82ee4279e31f7ddf7e34b2a99eb9b7bc9" },
"lualine.nvim": { "branch": "master", "commit": "640260d7c2d98779cab89b1e7088ab14ea354a02" },
"lualine.nvim": { "branch": "master", "commit": "2a5bae925481f999263d6f5ed8361baef8df4f83" },
"lush.nvim": { "branch": "main", "commit": "45a79ec4acb5af783a6a29673a999ce37f00497e" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "4d0e5b49363cac187326998b96aa6a2884e0e89b" },
"mason-nvim-dap.nvim": { "branch": "main", "commit": "8b9363d83b5d779813cdd2819b8308651cec2a09" },
"mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" },
"mini.nvim": { "branch": "main", "commit": "c8bc67a35e627908da644c5f8cd26b3f987f2627" },
"mini.nvim": { "branch": "main", "commit": "998cfcf1fdd0a6830d0fc35f1c054a6f55de1e7f" },
"neo-tree.nvim": { "branch": "main", "commit": "a77af2e764c5ed4038d27d1c463fa49cd4794e07" },
"neotest": { "branch": "master", "commit": "6d3d22cdad49999ef774ebe1bc250a4994038964" },
"neotest-elixir": { "branch": "master", "commit": "c5067bcc3ec6a0bba7b5694fa15aeb17f16aeb3c" },
"neotest-vitest": { "branch": "main", "commit": "9e30dca989a2287cf3fde86b3e138ea7fa4de935" },
"noice.nvim": { "branch": "main", "commit": "5a78b42bec5e775f2db03bf93f6d1e0f3636306c" },
"nui.nvim": { "branch": "main", "commit": "b58e2bfda5cea347c9d58b7f11cf3012c7b3953f" },
"nvim-cmp": { "branch": "main", "commit": "f17d9b4394027ff4442b298398dfcaab97e40c4f" },
"nvim-dap": { "branch": "master", "commit": "7ff6936010b7222fea2caea0f67ed77f1b7c60dd" },
"nvim-dap": { "branch": "master", "commit": "8517126e9323e346f6a99b3b594c5a940b914dcd" },
"nvim-dap-ui": { "branch": "master", "commit": "ffa89839f97bad360e78428d5c740fdad9a0ff02" },
"nvim-dap-virtual-text": { "branch": "master", "commit": "76d80c3d171224315b61c006502a1e30c213a9ab" },
"nvim-lastplace": { "branch": "main", "commit": "0bb6103c506315044872e0f84b1f736c4172bb20" },
"nvim-lspconfig": { "branch": "master", "commit": "bc6ada4b0892b7f10852c0b8ca7209fd39a6d754" },
"nvim-lspconfig": { "branch": "master", "commit": "d01864641c6e43c681c3e9f6cf4745c75fdd9dcc" },
"nvim-nio": { "branch": "master", "commit": "a428f309119086dc78dd4b19306d2d67be884eee" },
"nvim-notify": { "branch": "master", "commit": "fbef5d32be8466dd76544a257d3f3dce20082a07" },
"nvim-scrollbar": { "branch": "main", "commit": "6994eb9f73d5fdc36ee2c8717940e8c853e51a49" },
"nvim-snippets": { "branch": "main", "commit": "56b4052f71220144689caaa2e5b66222ba5661eb" },
"nvim-treesitter": { "branch": "master", "commit": "dfd3207ed43a0c572c13acc02bf9d7dc270f4030" },
"nvim-treesitter": { "branch": "master", "commit": "425b58968340bd5b4621c2a0d626c73556516d3d" },
"nvim-treesitter-context": { "branch": "master", "commit": "a2a334900d3643de585ac5c6140b03403454124f" },
"nvim-ts-autotag": { "branch": "main", "commit": "e239a560f338be31337e7abc3ee42515daf23f5e" },
"plenary.nvim": { "branch": "master", "commit": "2d9b06177a975543726ce5c73fca176cedbffe9d" },
"snacks.nvim": { "branch": "main", "commit": "7f9f691a12d0665146b25a44323f21e18aa46c24" },
"telescope-fzf-native.nvim": { "branch": "main", "commit": "cf48d4dfce44e0b9a2e19a008d6ec6ea6f01a83b" },
"telescope.nvim": { "branch": "master", "commit": "85922dde3767e01d42a08e750a773effbffaea3e" },
"trouble.nvim": { "branch": "main", "commit": "2f3b537f2207ce32f4459f9d56746ee013b5e01b" },
"trouble.nvim": { "branch": "main", "commit": "3dc00c0447c016cd43e03054c3d49436a1f2076d" },
"ts-comments.nvim": { "branch": "main", "commit": "2002692ad1d3f6518d016550c20c2a890f0cbf0e" },
"twoslash-queries.nvim": { "branch": "main", "commit": "b92622c7b71eceefabd02eef24236041069904b1" },
"vim-illuminate": { "branch": "master", "commit": "5eeb7951fc630682c322e88a9bbdae5c224ff0aa" },
"vim-repeat": { "branch": "master", "commit": "65846025c15494983dafe5e3b46c8f88ab2e9635" },
"which-key.nvim": { "branch": "main", "commit": "8badb359f7ab8711e2575ef75dfe6fbbd87e4821" }
"which-key.nvim": { "branch": "main", "commit": "68e37e12913a66b60073906f5d3f14dee0de19f2" }
}
29 changes: 2 additions & 27 deletions .config/nvim/lua/config/autocmds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ vim.api.nvim_create_autocmd("FileType", {
"PlenaryTestPopup",
"checkhealth",
"dbout",
"gitsigns.blame",
"gitsigns-blame",
"grug-far",
"help",
"lspinfo",
Expand All @@ -83,7 +83,7 @@ vim.api.nvim_create_autocmd("FileType", {
"neotest-summary",
"notify",
"qf",
"spectre_panel",
"snacks_win",
"startuptime",
"tsplayground",
},
Expand Down Expand Up @@ -142,31 +142,6 @@ vim.api.nvim_create_autocmd({ "BufWritePre" }, {
end,
})

vim.filetype.add({
pattern = {
[".*"] = {
function(path, buf)
return vim.bo[buf]
and vim.bo[buf].filetype ~= "bigfile"
and path
and vim.fn.getfsize(path) > vim.g.bigfile_size
and "bigfile"
or nil
end,
},
},
})

vim.api.nvim_create_autocmd({ "FileType" }, {
group = augroup("bigfile"),
pattern = "bigfile",
callback = function(ev)
vim.schedule(function()
vim.bo[ev.buf].syntax = vim.filetype.match({ buf = ev.buf }) or ""
end)
end,
})

-- allow C-l to clear terminal
vim.api.nvim_create_autocmd("TermOpen", {
callback = function(ev)
Expand Down
82 changes: 39 additions & 43 deletions .config/nvim/lua/config/keymaps.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
local map = vim.keymap.set

local ui = require("util.ui")
local Snacks = require("snacks")

-- Better up/down
map({ "n", "x" }, "j", "v:count == 0 ? 'gj' : 'j'", { desc = "Down", expr = true, silent = true })
Expand Down Expand Up @@ -55,7 +54,9 @@ map("n", "[b", "<cmd>bprevious<cr>", { desc = "Prev Buffer" })
map("n", "]b", "<cmd>bnext<cr>", { desc = "Next Buffer" })
map("n", "<leader>bb", "<cmd>e #<cr>", { desc = "Switch to Other Buffer" })
map("n", "<leader>`", "<cmd>e #<cr>", { desc = "Switch to Other Buffer" })
map("n", "<leader>bd", ui.bufremove, { desc = "Delete Buffer" })
map("n", "<leader>bd", function()
Snacks.bufdelete()
end, { desc = "Delete Buffer" })
map("n", "<leader>bD", "<cmd>:bd<cr>", { desc = "Delete Buffer and Window" })

-- Clear search with <esc>
Expand Down Expand Up @@ -131,38 +132,30 @@ map("n", "]w", diagnostic_goto(true, "WARN"), { desc = "Next Warning" })
map("n", "[w", diagnostic_goto(false, "WARN"), { desc = "Prev Warning" })

-- toggle options
local toggle = require("util.toggle")
toggle.map("<leader>uf", toggle.format())
toggle.map("<leader>uF", toggle.format(true))
toggle.map("<leader>us", toggle("spell", { name = "Spelling" }))
toggle.map("<leader>uw", toggle("wrap", { name = "Wrap" }))
toggle.map("<leader>uL", toggle("relativenumber", { name = "Relative Number" }))
toggle.map("<leader>ud", toggle.diagnostics)
toggle.map("<leader>ul", toggle.number)
toggle.map("<leader>uc", toggle("conceallevel", { values = { 0, vim.o.conceallevel > 0 and vim.o.conceallevel or 2 } }))
toggle.map("<leader>uT", toggle.treesitter)
toggle.map("<leader>ub", toggle("background", { values = { "light", "dark" }, name = "Background" }))
local format = require("util.format")
format.snacks_toggle():map("<leader>uf")
format.snacks_toggle(true):map("<leader>uF")
Snacks.toggle.option("spell", { name = "Spelling" }):map("<leader>us")
Snacks.toggle.option("wrap", { name = "Wrap" }):map("<leader>uw")
Snacks.toggle.option("relativenumber", { name = "Relative Number" }):map("<leader>uL")
Snacks.toggle.diagnostics():map("<leader>ud")
Snacks.toggle.line_number():map("<leader>ul")
Snacks.toggle
.option("conceallevel", { off = 0, on = vim.o.conceallevel > 0 and vim.o.conceallevel or 2 })
:map("<leader>uc")
Snacks.toggle.treesitter():map("<leader>uT")
Snacks.toggle.option("background", { off = "light", on = "dark", name = "Dark Background" }):map("<leader>ub")
if vim.lsp.inlay_hint then
toggle.map("<leader>uh", toggle.inlay_hints)
Snacks.toggle.inlay_hints():map("<leader>uh")
end

-- lazygit
-- map("n", "<leader>gg", function() LazyVim.lazygit( { cwd = LazyVim.root.git() }) end, { desc = "Lazygit (Root Dir)" })
-- map("n", "<leader>gG", function() LazyVim.lazygit() end, { desc = "Lazygit (cwd)" })
-- map("n", "<leader>gb", LazyVim.lazygit.blame_line, { desc = "Git Blame Line" })
-- map("n", "<leader>gB", LazyVim.lazygit.browse, { desc = "Git Browse" })
--
-- map("n", "<leader>gf", function()
-- local git_path = vim.api.nvim_buf_get_name(0)
-- LazyVim.lazygit({args = { "-f", vim.trim(git_path) }})
-- end, { desc = "Lazygit Current File History" })
--
-- map("n", "<leader>gl", function()
-- LazyVim.lazygit({ args = { "log" }, cwd = LazyVim.root.git() })
-- end, { desc = "Lazygit Log" })
-- map("n", "<leader>gL", function()
-- LazyVim.lazygit({ args = { "log" } })
-- end, { desc = "Lazygit Log (cwd)" })
-- TODO: lazygit
map("n", "<leader>gb", function()
Snacks.git.blame_line()
end, { desc = "Git Blame Line" })
map("n", "<leader>gB", function()
Snacks.gitbrowse()
end, { desc = "Git Browse" })

-- quit
map("n", "<leader>qq", "<cmd>qa<cr>", { desc = "Quit All" })
Expand All @@ -172,18 +165,21 @@ map("n", "<leader>ui", vim.show_pos, { desc = "Inspect Pos" })
map("n", "<leader>uI", "<cmd>InspectTree<cr>", { desc = "Inspect Tree" })

-- floating terminal
local lazyterm = function()
require("util.terminal")()
end
map("n", "<c-/>", lazyterm, { desc = "Terminal" })
map("n", "<c-_>", lazyterm, { desc = "which_key_ignore" })
local root = require("util.root")
map("n", "<leader>fT", function()
Snacks.terminal()
end, { desc = "Terminal (cwd)" })
map("n", "<leader>ft", function()
Snacks.terminal(nil, { cwd = root() })
end, { desc = "Terminal (Root Dir)" })
map("n", "<c-/>", function()
Snacks.terminal(nil, { cwd = root() })
end, { desc = "Terminal (Root Dir)" })
map("n", "<c-_>", function()
Snacks.terminal(nil, { cwd = root() })
end, { desc = "which_key_ignore" })

-- Terminal Mappings
map("t", "<esc><esc>", "<c-\\><c-n>", { desc = "Enter Normal Mode" })
map("t", "<C-h>", "<cmd>wincmd h<cr>", { desc = "Go to Left Window" })
map("t", "<C-j>", "<cmd>wincmd j<cr>", { desc = "Go to Lower Window" })
map("t", "<C-k>", "<cmd>wincmd k<cr>", { desc = "Go to Upper Window" })
map("t", "<C-l>", "<cmd>wincmd l<cr>", { desc = "Go to Right Window" })
map("t", "<C-/>", "<cmd>close<cr>", { desc = "Hide Terminal" })
map("t", "<c-_>", "<cmd>close<cr>", { desc = "which_key_ignore" })

Expand All @@ -192,7 +188,7 @@ map("n", "<leader>w", "<c-w>", { desc = "Windows", remap = true })
map("n", "<leader>-", "<C-W>s", { desc = "Split Window Below", remap = true })
map("n", "<leader>|", "<C-W>v", { desc = "Split Window Right", remap = true })
map("n", "<leader>wd", "<C-W>c", { desc = "Delete Window", remap = true })
toggle.map("<leader>wm", toggle.maximize)
require("util.ui").maximize():map("<leader>wm")

-- tabs
map("n", "<leader><tab>l", "<cmd>tablast<cr>", { desc = "Last Tab" })
Expand Down
14 changes: 1 addition & 13 deletions .config/nvim/lua/config/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,13 @@ vim.g.autoformat = true
-- * a function with signature `function(buf) -> string|string[]`
vim.g.root_spec = { "lsp", { ".git", "lua" }, "cwd" }

-- Options for the statuscolumn
vim.g.tmm_statuscolumn = {
folds_open = false, -- show fold sign when fold is open
folds_githl = false, -- highlight fold sign with git sign color
}

-- Set LSP servers to be ignored when used with `util.root.detectors.lsp`
-- for detecting the LSP root
vim.g.root_lsp_ignore = { "copilot" }

-- Hide deprecation warnings
vim.g.deprecation_warnings = false

-- Set filetype to `bigfile` for files larger than 1.5 MB
-- Only vim syntax will be enabled (with the correct filetype)
-- LSP, treesitter and other ft plugins will be disabled.
-- mini.animate will also be disabled.
vim.g.bigfile_size = 1024 * 1024 * 1.5 -- 1.5 MB

-- Show the current document symbols location from Trouble in lualine
-- You can disable this for a buffer by setting `vim.b.trouble_lualine = false`
vim.g.trouble_lualine = true
Expand Down Expand Up @@ -69,6 +57,7 @@ opt.number = true -- Print line number
opt.pumblend = 10 -- Popup blend
opt.pumheight = 10 -- Maximum number of entries in a popup
opt.relativenumber = true -- Relative line numbers
opt.ruler = false -- Disable the default ruler
opt.scrolloff = 4 -- Lines of context
opt.sessionoptions = { "buffers", "curdir", "tabpages", "winsize", "help", "globals", "skiprtp", "folds" }
opt.shiftround = true -- Round indent
Expand All @@ -85,7 +74,6 @@ opt.spelloptions:append("noplainbuffer")
opt.splitbelow = true -- Put new windows below current
opt.splitkeep = "screen"
opt.splitright = true -- Put new windows right of current
opt.statuscolumn = [[%!v:lua.require'util.ui'.statuscolumn()]]
opt.tabstop = 2 -- Number of spaces tabs count for
opt.termguicolors = true -- True color support
opt.timeoutlen = 300 -- Lower than default (1000) to quickly trigger which-key
Expand Down
Loading

0 comments on commit 5301eb8

Please sign in to comment.