Skip to content

Commit

Permalink
feat(nvim): customize mini.visits
Browse files Browse the repository at this point in the history
  • Loading branch information
aikow committed Jan 27, 2025
1 parent 389be80 commit b0e5186
Show file tree
Hide file tree
Showing 14 changed files with 196 additions and 1,474 deletions.
56 changes: 18 additions & 38 deletions config/nvim/lua/user/mappings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,49 +15,29 @@ map("n", "<leader>rs", [[:%s/\v]], { desc = "search and replace" })
map("x", "<leader>rs", [[:s/\v]], { desc = "region search and replace" })
map("n", "<leader>rS", [[:cfdo %s/\v]], { desc = "global search and replace" })

-- Correct last spelling mistake
map("n", "<leader>zz", "<cmd>set invspell<CR>", { desc = "toggle spellcheck" })
map("n", "<leader>zw", "<cmd>set invwrap<CR>", { desc = "toggle wrap" })
map("n", "<leader>tz", "<cmd>set invspell<CR>", { desc = "toggle spellcheck" })
map("n", "<leader>tw", "<cmd>set invwrap<CR>", { desc = "toggle wrap" })

map("i", "<C-.>", [[<C-g>u<Esc>[s1z=`]a<C-g>u]], { desc = "correct last spelling mistake" })

-- Set the working directory
map("n", "g.", function()
local path = vim.api.nvim_buf_get_name(0)
if path ~= "" then
vim.fn.chdir(vim.fs.dirname(path))
else
vim.notify("unable to change directory, not a valid path", vim.log.levels.WARN)
end
end, { desc = "set the working directory to the dir of the current file" })
map("n", "g>", function()
local path = vim.api.nvim_buf_get_name(0)
if path ~= "" then
path = vim.fs.dirname(path)
else
path = vim.uv.cwd() or vim.fn.getcwd()
end
local root = vim.fs.root(path, {
".editorconfig", -- general editor settings
".exrc", -- nvim config
".git", -- git
"Cargo.toml", -- rust
"Makefile", -- c/c++
"package.json", -- javascript
"pyproject.toml", -- python
"setup.py", -- python
})

if root then
vim.fn.chdir(root)
else
vim.notify("unable to find a root directory", vim.log.levels.WARN)
end
end, { desc = "recursively search for a root directory from the current file" })
map(
"n",
"g.",
require("user.util").chdir_parent,
{ desc = "set the working directory to the dir of the current file" }
)
map(
"n",
"g>",
require("user.util").chdir_root,
{ desc = "recursively search for a root directory from the current file" }
)

-- Clear the search buffer to remove highlighting from the last search. The extra mapping for <C-_>
-- is needed for alacritty.
map("n", "<C-/>", [[:let @/ = ""<CR>]], { desc = "clear search buffer register" })
map("n", "<C-_>", [[:let @/ = ""<CR>]], { desc = "clear search buffer register" })
map("n", "<C-/>", [[:let @/ = ""<CR>]], { desc = "clear search buffer register", silent = true })
map("n", "<C-_>", [[:let @/ = ""<CR>]], { desc = "clear search buffer register", silent = true })

-- Select the text that was last pasted
map(
Expand Down Expand Up @@ -109,7 +89,7 @@ map("n", "<leader><leader>", "<c-^>", { desc = "switch to most recent buffer" })
map("n", "<leader>c", "ct_", { desc = "change upto next underscore '_'" })

-- Source the current buffer.
map("n", "<leader>.", "<cmd>source %<CR>", { desc = "source lua or vimscript file" })
map("n", "<leader>.", "<cmd>source %<CR>", { desc = "source current file" })

-- Enter a lua command.
map("n", "<leader>e", [[:lua =]], { desc = "evaluate lua expression" })
Expand Down
97 changes: 52 additions & 45 deletions config/nvim/lua/user/options.lua
Original file line number Diff line number Diff line change
@@ -1,30 +1,62 @@
local opt = vim.opt

-- Use bash as the default shell regardless of what the user shell is
-- ------------------------------------------------------------------------
-- | General
-- ------------------------------------------------------------------------
-- Always use bash as the shell
opt.shell = "bash"

-- Add snippets directory to the runtime path
opt.runtimepath:append("~/.dotfiles/config/snippets")

-- Back-up, undo files, and automatically write changes.
-- Enable local config files using a trustdb.
opt.exrc = true

-- Use system clipboard
opt.clipboard = "unnamedplus"

-- Don't store backup while overwriting the file
opt.backup = false
opt.writebackup = false
opt.updatetime = 1000
opt.undofile = true
opt.autowrite = true
opt.updatetime = 1000

--
-- Set the timeout times
opt.timeoutlen = 500
opt.ttimeoutlen = 5

-- Use system clipboard
opt.clipboard = "unnamedplus"
-- Enable all mouse options
opt.mouse = "a"

-- Enable local config files using a trustdb.
opt.exrc = true
-- Remove default mouse menu options
vim.api.nvim_create_autocmd("VimEnter", {
group = vim.api.nvim_create_augroup("remove mouse", {}),
once = true,
callback = function()
vim.cmd.aunmenu({ "PopUp.How-to\\ disable\\ mouse" })
vim.cmd.aunmenu({ "PopUp.-1-" })
end,
})

-- Enable all filetype plugins
vim.cmd.filetype({ "plugin", "indent", "on" })

-- Set 7 lines to the cursor - when moving vertically using j/k
opt.smoothscroll = true
opt.scrolloff = 7

-- Open new splits to the right or down instead of moving current window.
opt.splitright = true
opt.splitbelow = true
opt.splitkeep = "screen"

-- Default to a maximum of 80 characters per line
opt.textwidth = 80

-- ------------------------------------------------------------------------
-- | Editing and Searching
-- ------------------------------------------------------------------------
--
-- Tab key enters 2 spaces
opt.expandtab = true
opt.tabstop = 2
Expand All @@ -40,20 +72,12 @@ opt.ignorecase = true
opt.smartcase = true
opt.inccommand = "split"

-- Set grepprg to use ripgrep
opt.grepprg = "rg --vimgrep --no-heading --smart-case"
opt.grepformat = "%f:%l:%c:%m"

-- Format options
-- "t" Auto-wrap using 'textwidth'
-- "c" Auto-wrap comments using 'textwidth'
-- "r" Automatically insert current comment leader in insert mode (<CR>)
-- "o" Automatically insert current comment leader in normal mode (o or O)
-- "q" Allow formatting with 'gq'
-- "n" Recognize numbered lists
-- "b" Only auto-wrap if line was entered at or before the wrap margin
-- "l" Long lines when entering insert mode are not wrapped automatically
-- "j" Remove comment leader when joining lines
opt.formatoptions:append("tcroqnblj")
opt.formatoptions = "qjl1ortc"

-- Builtin completion options
opt.infercase = true -- Make completion case-insensitive.
Expand All @@ -67,29 +91,12 @@ if vim.fn.has("nvim-0.11") == 1 then opt.completeopt:append({ "fuzzy" }) end
-- Don't give ins-complete-menu messages
opt.shortmess:append("WcCI")

-- Wildmenu options
opt.wildoptions:append("fuzzy")
opt.wildmode = "longest:full,full"
opt.wildignore:append({ ".o", ".so", ".a", ".git" })

-- Pop-up menu options
opt.pumheight = 16

-- -- Use treesitter for folding
opt.foldmethod = "expr"
opt.foldexpr = "v:lua.require'user.util'.foldexpr()"
opt.foldtext = ""
opt.foldlevel = 99 -- Nothing is folded by default

-- Set 7 lines to the cursor - when moving vertically using j/k
opt.smoothscroll = true
opt.scrolloff = 7

-- Open new splits to the right or down instead of moving current window.
opt.splitright = true
opt.splitbelow = true
opt.splitkeep = "screen"

-- Spell options.
opt.spelloptions = { "camel" }

Expand All @@ -104,11 +111,20 @@ opt.diffopt:append({
-- ------------------------------------------------------------------------
-- | Appearance and Themes
-- ------------------------------------------------------------------------

-- Wildmenu options
opt.wildoptions:append("fuzzy")
opt.wildmode = "longest:full,full"

-- Pop-up menu options
opt.pumheight = 16

-- Color scheme and background
opt.termguicolors = true -- 24-bit RGB color support

-- Tabline
vim.o.tabline = "%!v:lua.require'user.ui.tabline'.tabline()"
opt.showmode = false

-- Define which helper symbols to show
opt.listchars = "tab:󰌒 ,extends:…,precedes:…,nbsp:␣"
Expand All @@ -120,19 +136,10 @@ opt.showbreak = " -> "
opt.linebreak = true
opt.breakindent = true

-- Default to a maximum of 80 characters per line
opt.textwidth = 80

-- Enable line numbers
opt.number = true
opt.numberwidth = 2

-- Enable all mouse options.
opt.mouse = "a"
-- Remove default mouse menu options
vim.cmd.aunmenu({ "PopUp.How-to\\ disable\\ mouse" })
vim.cmd.aunmenu({ "PopUp.-1-" })

-- Conceal
opt.conceallevel = 2
opt.fillchars = {
Expand Down
54 changes: 37 additions & 17 deletions config/nvim/lua/user/plugins/lsp/mappings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,59 @@ function M.diagnostic_goto(next, severity)
return function() vim.diagnostic.jump({ count = next and 1 or -1, severity = severity }) end
end

function M.document_symbols(kinds)
return function()
vim.lsp.buf.document_symbol({
on_list = function(options)
options.items = vim
.iter(options.items)
:filter(function(o) return vim.tbl_contains(kinds, o.kind) end)
:totable()
vim.fn.setqflist({}, " ", options)
vim.cmd.copen()
end,
})
end
end

function M.typehierarchy(direction)
return function() vim.lsp.buf.typehierarchy(direction) end
end

function M.on_attach(client, buffer)
local self = M.new(client, buffer)

-- stylua: ignore start
-- Extend default LSP actions.
self:map("<leader>s", vim.lsp.buf.signature_help, { desc = "lsp signature help" })
self:map("gD", vim.lsp.buf.declaration, { desc = "lsp go to declaration" })
self:map("gd", vim.lsp.buf.definition, { desc = "lsp go to definition" })
self:map("grS", function() vim.lsp.buf.typehierarchy("supertypes") end, { desc = "lsp list supertypes" })
self:map("grci", vim.lsp.buf.incoming_calls, { desc = "lsp list incoming calls" })
self:map("grco", vim.lsp.buf.outgoing_calls, { desc = "lsp list outgoing calls" })
self:map("grs", function() vim.lsp.buf.typehierarchy("subtypes") end, { desc = "lsp list subtypes" })
self:map("gry", vim.lsp.buf.type_definition, { desc = "lsp type declarations" })
self:map("<leader>s", vim.lsp.buf.signature_help, { desc = "lsp signature help" })
self:map("gD", vim.lsp.buf.declaration, { desc = "lsp go to declaration" })
self:map("gd", vim.lsp.buf.definition, { desc = "lsp go to definition" })
self:map("gO", M.document_symbols({ "Function", "Method", "Class" }), { desc = "vim.lsp.buf.document_symbol" })
self:map("grS", M.typehierarchy("supertypes"), { desc = "lsp list supertypes" })
self:map("grci", vim.lsp.buf.incoming_calls, { desc = "lsp list incoming calls" })
self:map("grco", vim.lsp.buf.outgoing_calls, { desc = "lsp list outgoing calls" })
self:map("grs", M.typehierarchy("subtypes"), { desc = "lsp list subtypes" })
self:map("gry", vim.lsp.buf.type_definition, { desc = "lsp type declarations" })

-- LSP go-to actions
self:map("<leader>ld", "Pick lsp scope='definition'", { desc = "mini.pick lsp definitions" })
self:map("<leader>lr", "Pick lsp scope='references'", { desc = "mini.pick lsp references" })
self:map("<leader>li", "Pick lsp scope='implementation'", { desc = "mini.pick lsp implementations" })
self:map("<leader>ld", "Pick lsp scope='definition'", { desc = "mini.pick lsp definitions" })
self:map("<leader>lr", "Pick lsp scope='references'", { desc = "mini.pick lsp references" })
self:map("<leader>li", "Pick lsp scope='implementation'", { desc = "mini.pick lsp implementations" })
self:map("<leader>ly", "Pick lsp scope='type_definition'", { desc = "mini.pick lsp type definitions" })

-- Search for symbols
self:map("<leader>ls", "Pick lsp scope='document_symbol'", { desc = "mini.pick document symbols" })
self:map("<leader>ls", "Pick lsp scope='document_symbol'", { desc = "mini.pick document symbols" })
self:map("<leader>lS", "Pick lsp scope='workspace_symbol'", { desc = "mini.pick workspace symbols" })

-- Diagnostics
self:map("<leader>dl", vim.diagnostic.setloclist, { desc = "diagnostic set location list" })
self:map("<leader>dq", vim.diagnostic.setqflist, { desc = "diagnostic set quickfix list" })
self:map("<leader>do", "Pick diagnostic", { desc = "mini.pick diagnostics" })
self:map("<leader>dq", vim.diagnostic.setqflist, { desc = "diagnostic set quickfix list" })
self:map("<leader>do", "Pick diagnostic", { desc = "mini.pick diagnostics" })

-- Diagnostic movements with [ and ]
self:map("]e", M.diagnostic_goto(true, "ERROR"), { desc = "next error" })
self:map("[e", M.diagnostic_goto(false, "ERROR"), { desc = "previous error" })
self:map("]w", M.diagnostic_goto(true, "WARNING"), { desc = "next warning" })
self:map("]e", M.diagnostic_goto(true, "ERROR"), { desc = "next error" })
self:map("[e", M.diagnostic_goto(false, "ERROR"), { desc = "previous error" })
self:map("]w", M.diagnostic_goto(true, "WARNING"), { desc = "next warning" })
self:map("[w", M.diagnostic_goto(false, "WARNING"), { desc = "previous warning" })
-- stylua: ignore end
end
Expand Down
2 changes: 1 addition & 1 deletion config/nvim/lua/user/plugins/mini/clue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function M.setup()
{ mode = "n", keys = "<leader>k", desc = "+Iron" },
{ mode = "n", keys = "<leader>l", desc = "+LSP" },
{ mode = "n", keys = "<leader>r", desc = "+Refactor/Reformat" },
{ mode = "n", keys = "<leader>z", desc = "+Toggle" },
{ mode = "n", keys = "<leader>t", desc = "+Toggle" },

miniclue.gen_clues.builtin_completion(),
miniclue.gen_clues.g(),
Expand Down
15 changes: 9 additions & 6 deletions config/nvim/lua/user/plugins/mini/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,22 @@ MiniDeps.later(function()
require("user.plugins.mini.files").setup()
require("user.plugins.mini.git").setup()
require("user.plugins.mini.pick").setup()
require("user.plugins.mini.visits").setup()

require("mini.align").setup({})
require("mini.cursorword").setup({})
require("mini.visits").setup({})

-- ------------------------------------------------------------------------
-- | mini.basics
-- ------------------------------------------------------------------------
local minibasics = require("mini.basics")
vim.keymap.set("n", "<leader>td", minibasics.toggle_diagnostic, { desc = "toggle diagnostics" })

-- ------------------------------------------------------------------------
-- | mini.misc
-- ------------------------------------------------------------------------
local minimisc = require("mini.misc")
minimisc.setup({})
minimisc.setup_termbg_sync()
minimisc.setup_restore_cursor()

Expand Down Expand Up @@ -101,11 +108,7 @@ MiniDeps.later(function()
-- ------------------------------------------------------------------------
-- | mini.splitjoin
-- ------------------------------------------------------------------------
require("mini.splitjoin").setup({
mappings = {
toggle = "gS",
},
})
require("mini.splitjoin").setup({})

-- ------------------------------------------------------------------------
-- | mini.bracketed
Expand Down
2 changes: 1 addition & 1 deletion config/nvim/lua/user/plugins/mini/pick.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function M.setup()

-- mini.visits
vim.keymap.set("n", "<leader>jl", extra.visit_labels, { desc = "mini.pick visit labels" })
vim.keymap.set("n", "<leader>jp", extra.visit_paths, { desc = "mini.pick visit paths" })
vim.keymap.set("n", "<leader>jj", extra.visit_paths, { desc = "mini.pick visit paths" })

-- Finding searching and navigating
vim.keymap.set("n", "<leader>o", builtin.files, { desc = "mini.pick find files" })
Expand Down
Loading

0 comments on commit b0e5186

Please sign in to comment.