mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-01-26 11:14:08 +00:00
chore(nvim): configs, keymaps, utils.lua, docs
This commit is contained in:
@@ -11,6 +11,9 @@ trim_trailing_whitespace = true
|
|||||||
[*.md]
|
[*.md]
|
||||||
max_line_length = 100
|
max_line_length = 100
|
||||||
|
|
||||||
|
[*.lua]
|
||||||
|
max_line_length = 120
|
||||||
|
|
||||||
[*.php]
|
[*.php]
|
||||||
indent_size = 4
|
indent_size = 4
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ if not vim.loop.fs_stat(lazypath) then
|
|||||||
if vim.v.shell_error ~= 0 then
|
if vim.v.shell_error ~= 0 then
|
||||||
vim.api.nvim_echo({
|
vim.api.nvim_echo({
|
||||||
{ 'Failed to clone lazy.nvim:\n', 'ErrorMsg' },
|
{ 'Failed to clone lazy.nvim:\n', 'ErrorMsg' },
|
||||||
{ out, 'WarningMsg' },
|
{ out, 'WarningMsg' },
|
||||||
{ '\nPress any key to exit...' },
|
{ '\nPress any key to exit...' },
|
||||||
}, true, {})
|
}, true, {})
|
||||||
vim.fn.getchar()
|
vim.fn.getchar()
|
||||||
@@ -38,7 +38,7 @@ require 'autogroups'
|
|||||||
|
|
||||||
-- ── Load plugins ────────────────────────────────────────────────────
|
-- ── Load plugins ────────────────────────────────────────────────────
|
||||||
require('lazy').setup(
|
require('lazy').setup(
|
||||||
-- Automatically load plugins from lua/plugins
|
-- Automatically load plugins from lua/plugins
|
||||||
'plugins',
|
'plugins',
|
||||||
-- Lazy Configuration
|
-- Lazy Configuration
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -83,6 +83,8 @@ autocmd({ 'FileType' }, {
|
|||||||
})
|
})
|
||||||
|
|
||||||
-- Set filetype for SSH config directory
|
-- Set filetype for SSH config directory
|
||||||
|
-- Pattern handles directories with files like:
|
||||||
|
-- .dotfiles/ssh/config.d/*, .ssh/config.local, .ssh/config.work
|
||||||
autocmd({ 'BufRead', 'BufNewFile' }, {
|
autocmd({ 'BufRead', 'BufNewFile' }, {
|
||||||
desc = 'Set filetype for SSH config directory',
|
desc = 'Set filetype for SSH config directory',
|
||||||
pattern = { '*/?.ssh/{config|shared}.d/*', '*/?.ssh/config.local', '*/?.ssh/config.work' },
|
pattern = { '*/?.ssh/{config|shared}.d/*', '*/?.ssh/config.local', '*/?.ssh/config.work' },
|
||||||
|
|||||||
@@ -1,142 +1,91 @@
|
|||||||
-- ╭─────────────────────────────────────────────────────────╮
|
-- vim: set ft=lua ts=2 sw=2 tw=0 et cc=120 :
|
||||||
-- │ Function shortcuts for keymap set │
|
|
||||||
-- ╰─────────────────────────────────────────────────────────╯
|
|
||||||
-- vim: set ft=lua ts=2 sw=2 tw=0 et cc=80 :
|
|
||||||
|
|
||||||
-- Keymap set shortcut
|
require('utils')
|
||||||
--@type vim.keymap.set
|
|
||||||
local s = vim.keymap.set
|
|
||||||
|
|
||||||
-- Handle description
|
|
||||||
---@param desc string|table? Optional description. Can be a string or a table.
|
|
||||||
---@return table -- The description as a table.
|
|
||||||
local function handleDesc(desc)
|
|
||||||
if type(desc) == "string" then
|
|
||||||
-- Convert string to table with `desc` as a key
|
|
||||||
-- If the string is empty, just return as an empty description
|
|
||||||
return { desc = desc }
|
|
||||||
elseif type(desc) == "table" then
|
|
||||||
-- If desc doesn't have 'desc' key, combine it with
|
|
||||||
-- others with empty description
|
|
||||||
if not desc.desc then
|
|
||||||
desc.desc = ''
|
|
||||||
return desc
|
|
||||||
end
|
|
||||||
-- Use the table as is
|
|
||||||
return desc
|
|
||||||
else
|
|
||||||
-- Default to an empty table if `desc` is nil or an unsupported type
|
|
||||||
return { desc = '' }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Normal mode keymaps
|
|
||||||
---@param key string rhs, required
|
|
||||||
---@param cmd string|function lhs, required
|
|
||||||
---@param opts table? Options, optional
|
|
||||||
local n = function(key, cmd, opts) s('n', key, cmd, opts) end
|
|
||||||
|
|
||||||
-- Leader keymap shortcut function
|
|
||||||
-- It prepends '<leader>' to the key
|
|
||||||
---@param key string rhs, required, but will be prepended with '<leader>'
|
|
||||||
---@param cmd string|function lhs, required
|
|
||||||
---@param opts table|string? Options (or just description), optional
|
|
||||||
local nl = function(key, cmd, opts)
|
|
||||||
opts = handleDesc(opts)
|
|
||||||
n('<leader>' .. key, cmd, opts)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Local leader keymap shortcut function
|
|
||||||
-- It prepends '<leader>' to the key and uses desc from opts
|
|
||||||
---@param key string rhs, required, but will be prepended with '<leader>'
|
|
||||||
---@param cmd string|function lhs, required
|
|
||||||
---@param opts table|string description, required
|
|
||||||
local nld = function(key, cmd, opts)
|
|
||||||
opts = handleDesc(opts)
|
|
||||||
nl(key, cmd, opts)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Keymap shortcut function with mode defined, good for sorting by rhs
|
|
||||||
---@param key string rhs, required
|
|
||||||
---@param mode string|string[] one of n, v, x, or table of modes { 'n', 'v' }
|
|
||||||
---@param cmd string|function lhs, required
|
|
||||||
---@param opts string|table description, required
|
|
||||||
local d = function(key, mode, cmd, opts)
|
|
||||||
opts = handleDesc(opts)
|
|
||||||
s(mode, key, cmd, opts)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Leader based keymap shortcut function with mode defined
|
|
||||||
---@param key string rhs, required, but will be prepended with '<leader>'
|
|
||||||
---@param mode string|string[] one of n, v, x, or table of modes { 'n', 'v' }
|
|
||||||
---@param cmd string|function lhs, required
|
|
||||||
---@param opts string|table description (or opts), required
|
|
||||||
local ld = function(key, mode, cmd, opts)
|
|
||||||
opts = handleDesc(opts)
|
|
||||||
s(mode, '<leader>' .. key, cmd, opts)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- ╭─────────────────────────────────────────────────────────╮
|
-- ╭─────────────────────────────────────────────────────────╮
|
||||||
-- │ Keymaps │
|
-- │ Keymaps │
|
||||||
-- ╰─────────────────────────────────────────────────────────╯
|
-- ╰─────────────────────────────────────────────────────────╯
|
||||||
|
|
||||||
-- Disable arrow keys in normal mode
|
-- ── Disable arrow keys in normal mode ───────────────────────────────
|
||||||
n('<left>', ':echo "Use h to move!!"<CR>')
|
K.n('<left>', ':echo "Use h to move!!"<CR>')
|
||||||
n('<right>', ':echo "Use l to move!!"<CR>')
|
K.n('<right>', ':echo "Use l to move!!"<CR>')
|
||||||
n('<up>', ':echo "Use k to move!!"<CR>')
|
K.n('<up>', ':echo "Use k to move!!"<CR>')
|
||||||
n('<down>', ':echo "Use j to move!!"<CR>')
|
K.n('<down>', ':echo "Use j to move!!"<CR>')
|
||||||
|
|
||||||
n('<C-s>', ':w!<cr>', { desc = 'Save', noremap = true })
|
-- ── Splits ──────────────────────────────────────────────────────────
|
||||||
n('<esc><esc>', ':nohlsearch<cr>', { desc = 'Clear Search Highlighting' })
|
K.n('<C-w>,', ':vertical resize -10<CR>', { desc = 'V Resize -' })
|
||||||
|
K.n('<C-w>.', ':vertical resize +10<CR>', { desc = 'V Resize +' })
|
||||||
|
K.n('<C-w>-', ':resize -10<CR>', { desc = 'H Resize -' })
|
||||||
|
K.n('<C-w>+', ':resize +10<CR>', { desc = 'H Resize +' })
|
||||||
|
K.n('<C-w>=', '<C-w>=', { desc = 'Equal Size Splits' })
|
||||||
|
|
||||||
-- Buffer operations
|
-- ── Deal with word wrap ─────────────────────────────────────────────
|
||||||
|
K.n('k', "v:count == 0 ? 'gk' : 'k'", { desc = 'Move up', noremap = true, expr = true })
|
||||||
|
K.n('j', "v:count == 0 ? 'gj' : 'j'", { desc = 'Move down', noremap = true, expr = true })
|
||||||
|
|
||||||
|
-- ── Text manipulation ───────────────────────────────────────────────
|
||||||
|
K.d('<', { 'n', 'v' }, '<gv', 'Indent Left')
|
||||||
|
K.d('>', { 'n', 'v' }, '>gv', 'Indent Right')
|
||||||
|
K.d('<C-k>', { 'n', 'v' }, ":m '<-2<CR>gv=gv", 'Move Block Up')
|
||||||
|
K.d('<C-j>', { 'n', 'v' }, ":m '>+1<CR>gv=gv", 'Move Block Down')
|
||||||
|
|
||||||
|
-- ── Other operations ────────────────────────────────────────────────
|
||||||
|
K.nl('o', function() require('snacks').gitbrowse() end, 'Open repo in browser')
|
||||||
|
K.n('<C-s>', ':w!<cr>', { desc = 'Save', noremap = true })
|
||||||
|
K.n('<esc><esc>', ':nohlsearch<cr>', { desc = 'Clear Search Highlighting' })
|
||||||
|
|
||||||
|
-- ── Buffer operations ───────────────────────────────────────────────
|
||||||
-- Mappings for buffer management operations like switching, deleting, etc.
|
-- Mappings for buffer management operations like switching, deleting, etc.
|
||||||
-- Convention: All mappings start with 'b' followed by the operation
|
-- Convention: All mappings start with 'b' followed by the operation
|
||||||
nld('ba', ':%bd|e#|bd#<cr>', 'Close all except current')
|
K.nl('ba', ':%bd|e#|bd#<cr>', 'Close all except current')
|
||||||
nld('bd', ':lua MiniBufremove.delete()<CR>', 'Delete')
|
K.nl('bd', ':lua MiniBufremove.delete()<CR>', 'Delete')
|
||||||
nld('bh', ':bprev<cr>', 'Prev')
|
K.nl('bh', ':bprev<cr>', 'Prev')
|
||||||
nld('bj', ':bfirst<cr>', 'First')
|
K.nl('bj', ':bfirst<cr>', 'First')
|
||||||
nld('bk', ':blast<cr>', 'Last')
|
K.nl('bk', ':blast<cr>', 'Last')
|
||||||
nld('bl', ':bnext<cr>', 'Next')
|
K.nl('bl', ':bnext<cr>', 'Next')
|
||||||
nld('bw', ':lua MiniBufremove.wipeout()<CR>', 'Wipeout')
|
K.nl('bw', ':lua MiniBufremove.wipeout()<CR>', 'Wipeout')
|
||||||
|
|
||||||
-- Code
|
-- ── Code & LSP operations ───────────────────────────────────────────
|
||||||
nld('cg', ':lua require("neogen").generate()<CR>', 'Generate annotations')
|
-- Mappings for code and LSP operations like code actions, formatting, etc.
|
||||||
|
-- Convention: All mappings start with 'c' followed by the operation
|
||||||
|
-- unless it's a generic operation like signature help or hover
|
||||||
|
K.n('<C-l>', ':lua vim.lsp.buf.signature_help()<CR>', { desc = 'Signature' })
|
||||||
|
K.n('K', ':Lspsaga hover_doc<cr>', { desc = 'Hover Documentation' })
|
||||||
|
K.ld('ca', 'n', ':Lspsaga code_action<cr>', 'Code Action')
|
||||||
|
K.ld('cci', 'n', ':Lspsaga incoming_calls<cr>', 'Incoming Calls')
|
||||||
|
K.ld('cco', 'n', ':Lspsaga outgoing_calls<cr>', 'Outgoing Calls')
|
||||||
|
K.ld('cd', 'n', ':Lspsaga show_line_diagnostics<cr>', 'Line Diagnostics')
|
||||||
|
K.ld('cf', { 'n', 'x' }, ':lua vim.lsp.buf.format()<CR>', 'Format')
|
||||||
|
K.ld('cg', 'n', ':lua require("neogen").generate()<CR>', 'Generate annotations')
|
||||||
|
K.ld('ci', 'n', ':Lspsaga implement<cr>', 'Implementations')
|
||||||
|
K.ld('cl', 'n', ':Lspsaga show_cursor_diagnostics<cr>', 'Cursor Diagnostics')
|
||||||
|
K.ld('cp', 'n', ':Lspsaga peek_definition<cr>', 'Peek Definition')
|
||||||
|
K.ld('cr', 'n', ':Lspsaga rename<cr>', 'Rename')
|
||||||
|
K.ld('cR', 'n', ':Lspsaga rename ++project<cr>', 'Rename Project wide')
|
||||||
|
K.ld('cs', 'n', ':Telescope lsp_document_symbols<CR>', 'LSP Document Symbols')
|
||||||
|
K.ld('ct', 'n', ':Lspsaga peek_type_definition<cr>', 'Peek Type Definition')
|
||||||
|
K.ld('cT', 'n', ':Telescope lsp_type_definitions<CR>', 'LSP Type Definitions')
|
||||||
|
K.ld('cu', 'n', ':Lspsaga preview_definition<cr>', 'Preview Definition')
|
||||||
|
K.ld('cv', 'n', ':Lspsaga diagnostic_jump_prev<cr>', 'Diagnostic Jump Prev')
|
||||||
|
K.ld('cw', 'n', ':Lspsaga diagnostic_jump_next<cr>', 'Diagnostic Jump Next')
|
||||||
|
|
||||||
-- LSP
|
-- ── CommentBox operations ───────────────────────────────────────────
|
||||||
n('<C-l>', ':lua vim.lsp.buf.signature_help()<CR>', { desc = 'Signature' })
|
|
||||||
n('K', ':Lspsaga hover_doc<cr>', { desc = 'Hover Documentation' })
|
|
||||||
ld('ca', 'n', ':Lspsaga code_action<cr>', 'Code Action')
|
|
||||||
ld('cci', 'n', ':Lspsaga incoming_calls<cr>', 'Incoming Calls')
|
|
||||||
ld('cco', 'n', ':Lspsaga outgoing_calls<cr>', 'Outgoing Calls')
|
|
||||||
ld('cd', 'n', ':Lspsaga show_line_diagnostics<cr>', 'Line Diagnostics')
|
|
||||||
ld('cf', { 'n', 'x' }, ':lua vim.lsp.buf.format()<CR>', 'Format')
|
|
||||||
ld('ci', 'n', ':Lspsaga implement<cr>', 'Implementations')
|
|
||||||
ld('cl', 'n', ':Lspsaga show_cursor_diagnostics<cr>', 'Cursor Diagnostics')
|
|
||||||
ld('cp', 'n', ':Lspsaga peek_definition<cr>', 'Peek Definition')
|
|
||||||
ld('cr', 'n', ':Lspsaga rename<cr>', 'Rename')
|
|
||||||
ld('cR', 'n', ':Lspsaga rename ++project<cr>', 'Rename Project wide')
|
|
||||||
ld('cs', 'n', ':Telescope lsp_document_symbols<CR>', 'LSP Document Symbols')
|
|
||||||
ld('ct', 'n', ':Lspsaga peek_type_definition<cr>', 'Peek Type Definition')
|
|
||||||
ld('cT', 'n', ':Telescope lsp_type_definitions<CR>', 'LSP Type Definitions')
|
|
||||||
ld('cu', 'n', ':Lspsaga preview_definition<cr>', 'Preview Definition')
|
|
||||||
ld('cv', 'n', ':Lspsaga diagnostic_jump_prev<cr>', 'Diagnostic Jump Prev')
|
|
||||||
ld('cw', 'n', ':Lspsaga diagnostic_jump_next<cr>', 'Diagnostic Jump Next')
|
|
||||||
|
|
||||||
-- CommentBox operations
|
|
||||||
-- Mappings for creating and managing comment boxes
|
-- Mappings for creating and managing comment boxes
|
||||||
-- Convention: All mappings start with 'cb' followed by the box type
|
-- Convention: All mappings start with 'cb' followed by the box type
|
||||||
nld('cbb', '<Cmd>CBccbox<CR>', 'CB: Box Title')
|
K.nl('cbb', '<Cmd>CBccbox<CR>', 'CB: Box Title')
|
||||||
nld('cbd', '<Cmd>CBd<CR>', 'CB: Remove a box')
|
K.nl('cbd', '<Cmd>CBd<CR>', 'CB: Remove a box')
|
||||||
nld('cbl', '<Cmd>CBline<CR>', 'CB: Simple Line')
|
K.nl('cbl', '<Cmd>CBline<CR>', 'CB: Simple Line')
|
||||||
nld('cbm', '<Cmd>CBllbox14<CR>', 'CB: Marked')
|
K.nl('cbm', '<Cmd>CBllbox14<CR>', 'CB: Marked')
|
||||||
nld('cbt', '<Cmd>CBllline<CR>', 'CB: Titled Line')
|
K.nl('cbt', '<Cmd>CBllline<CR>', 'CB: Titled Line')
|
||||||
|
|
||||||
|
|
||||||
-- Telescope
|
-- ── Telescope operations ────────────────────────────────────────────
|
||||||
nld('f', ':Telescope find_files<cr>', 'Find Files')
|
-- Mappings for Telescope operations like finding files, buffers, etc.
|
||||||
nld(',', ':Telescope buffers<cr>', 'Find existing buffers')
|
-- Convention: All mappings start with 's' followed by the operation
|
||||||
nld('/', function()
|
-- unless it's a generic operation like searching or finding buffers
|
||||||
|
K.nl('f', ':Telescope find_files<cr>', 'Find Files')
|
||||||
|
K.nl(',', ':Telescope buffers<cr>', 'Find existing buffers')
|
||||||
|
K.nl('/', function()
|
||||||
require('telescope.builtin').current_buffer_fuzzy_find(
|
require('telescope.builtin').current_buffer_fuzzy_find(
|
||||||
require('telescope.themes').get_dropdown {
|
require('telescope.themes').get_dropdown {
|
||||||
winblend = 20,
|
winblend = 20,
|
||||||
@@ -145,75 +94,48 @@ nld('/', function()
|
|||||||
)
|
)
|
||||||
end, 'Fuzzily search in current buffer')
|
end, 'Fuzzily search in current buffer')
|
||||||
|
|
||||||
nld('sc', ':Telescope commands<cr>', 'Commands')
|
K.nl('sc', ':Telescope commands<cr>', 'Commands')
|
||||||
nld('sd', ':Telescope diagnostics<cr>', 'Search Diagnostics')
|
K.nl('sd', ':Telescope diagnostics<cr>', 'Search Diagnostics')
|
||||||
nld('sg', ':Telescope live_grep<cr>', 'Search by Grep')
|
K.nl('sg', ':Telescope live_grep<cr>', 'Search by Grep')
|
||||||
nld('sh', ':Telescope highlights<cr>', 'List Highlights')
|
K.nl('sh', ':Telescope help_tags<cr>', 'Help tags')
|
||||||
nld('sk', ':Telescope keymaps<cr>', 'Search Keymaps')
|
K.nl('sk', ':Telescope keymaps<cr>', 'Search Keymaps')
|
||||||
nld('sl', ':Telescope luasnip<CR>', 'Search LuaSnip')
|
K.nl('sl', ':Telescope luasnip<CR>', 'Search LuaSnip')
|
||||||
nld('so', ':Telescope oldfiles<CR>', 'Old Files')
|
K.nl('so', ':Telescope oldfiles<CR>', 'Old Files')
|
||||||
nld('sp',
|
K.nl('sp', ':lua require("telescope").extensions.lazy_plugins.lazy_plugins()<cr>', 'Lazy Plugins')
|
||||||
':lua require("telescope").extensions.lazy_plugins.lazy_plugins()<cr>',
|
K.nl('sq', ':Telescope quickfix<cr>', 'Quickfix')
|
||||||
'Lazy Plugins')
|
K.nl('ss', ':Telescope treesitter<cr>', 'Treesitter')
|
||||||
nld('sq', ':Telescope quickfix<cr>', 'Quickfix')
|
K.nl('st', ':TodoTelescope<cr>', 'Search Todos')
|
||||||
nld('ss', ':Telescope treesitter<cr>', 'Treesitter')
|
K.nl('sw', ':Telescope grep_string<cr>', 'Grep String')
|
||||||
nld('st', ':TodoTelescope<cr>', 'Search Todos')
|
K.nl('sx', ':Telescope import<cr>', 'Telescope: Import')
|
||||||
nld('sw', ':Telescope grep_string<cr>', 'Grep String')
|
|
||||||
nld('sx', ':Telescope import<cr>', 'Telescope: Import')
|
|
||||||
|
|
||||||
-- Trouble
|
-- ── Trouble operations ──────────────────────────────────────────────
|
||||||
nld('xd',
|
-- Convention is 'x' followed by the operation
|
||||||
':Trouble document_diagnostics<cr>', 'Trouble: Document Diagnostics')
|
K.nl('xd', ':Trouble document_diagnostics<cr>', 'Document Diagnostics')
|
||||||
nld('xl', ':Trouble loclist<cr>', 'Trouble: Location List')
|
K.nl('xl', ':Trouble loclist<cr>', 'Location List')
|
||||||
nld('xq', ':Trouble quickfix<cr>', 'Trouble: Quickfix')
|
K.nl('xq', ':Trouble quickfix<cr>', 'Quickfix')
|
||||||
nld('xw',
|
K.nl('xw', ':Trouble workspace_diagnostics<cr>', 'Workspace Diagnostics')
|
||||||
':Trouble workspace_diagnostics<cr>', 'Trouble: Workspace Diagnostics')
|
K.nl('xx', ':Trouble diagnostics<cr>', 'Diagnostic')
|
||||||
nld('xx', ':Trouble diagnostics<cr>', 'Trouble: Diagnostic')
|
|
||||||
|
|
||||||
-- Text manipulation
|
-- ── Toggle settings ─────────────────────────────────────────────────
|
||||||
d('<', { 'n', 'v' }, '<gv', 'Indent Left')
|
-- Convention is 't' followed by the operation
|
||||||
d('>', { 'n', 'v' }, '>gv', 'Indent Right')
|
K.nl('tc', ':CloakToggle<cr>', 'Cloak: Toggle')
|
||||||
d('<C-k>', { 'n', 'v' }, ":m '<-2<CR>gv=gv", 'Move Block Up')
|
K.nl('te', ':Neotree toggle<cr>', 'Toggle Neotree')
|
||||||
d('<C-j>', { 'n', 'v' }, ":m '>+1<CR>gv=gv", 'Move Block Down')
|
K.nl('tl', ToggleBackground, 'Toggle Light/Dark Mode')
|
||||||
|
K.nl('tn', ':Noice dismiss<cr>', 'Noice: Dismiss Notification')
|
||||||
|
|
||||||
-- Other functionality
|
-- ── Quit operations ─────────────────────────────────────────────────
|
||||||
nld('o', function() require('snacks').gitbrowse() end, 'Open repo in browser')
|
-- Convention is 'q' followed by the operation
|
||||||
|
K.nl('qf', ':q<CR>', 'Quicker close split')
|
||||||
-- Toggle settings
|
K.nl('qq', function()
|
||||||
local function toggle_background()
|
|
||||||
vim.o.bg = vim.o.bg == "light" and "dark" or "light"
|
|
||||||
end
|
|
||||||
|
|
||||||
nld('tc', ':CloakToggle<cr>', 'Cloak: Toggle')
|
|
||||||
nld('te', ':Neotree toggle<cr>', 'Toggle Neotree')
|
|
||||||
nld('tl', toggle_background, 'Toggle Light/Dark Mode')
|
|
||||||
nld('tn', ':Noice dismiss<cr>', 'Noice: Dismiss Notification')
|
|
||||||
|
|
||||||
-- Splits
|
|
||||||
n('<C-w>,', ':vertical resize -10<CR>', { desc = 'V Resize -' })
|
|
||||||
n('<C-w>.', ':vertical resize +10<CR>', { desc = 'V Resize +' })
|
|
||||||
n('<C-w>-', ':resize -5<CR>', { desc = 'H Resize -' })
|
|
||||||
n('<C-w>+', ':resize +5<CR>', { desc = 'H Resize +' })
|
|
||||||
n('<C-w>=', '<C-w>=', { desc = 'Equal Size Splits' })
|
|
||||||
|
|
||||||
-- Deal with word wrap
|
|
||||||
n('k',
|
|
||||||
"v:count == 0 ? 'gk' : 'k'",
|
|
||||||
{ desc = 'Move up', noremap = true, expr = true })
|
|
||||||
n('j',
|
|
||||||
"v:count == 0 ? 'gj' : 'j'",
|
|
||||||
{ desc = 'Move down', noremap = true, expr = true })
|
|
||||||
|
|
||||||
-- Quit
|
|
||||||
nld('qf', ':q<CR>', 'Quicker close split')
|
|
||||||
nld('qq', function()
|
|
||||||
if vim.fn.confirm("Force save and quit?", "&Yes\n&No", 2) == 1 then
|
if vim.fn.confirm("Force save and quit?", "&Yes\n&No", 2) == 1 then
|
||||||
vim.cmd('wq!')
|
vim.cmd('wq!')
|
||||||
end
|
end
|
||||||
end, 'Quit with force saving')
|
end, 'Quit with force saving')
|
||||||
nld('qw', ':wq<CR>', 'Write and quit')
|
K.nl('qw', ':wq<CR>', 'Write and quit')
|
||||||
nld('qQ', function()
|
K.nl('qQ', function()
|
||||||
if vim.fn.confirm("Force quit without saving?", "&Yes\n&No", 2) == 1 then
|
if vim.fn.confirm("Force quit without saving?", "&Yes\n&No", 2) == 1 then
|
||||||
vim.cmd('q!')
|
vim.cmd('q!')
|
||||||
end
|
end
|
||||||
end, 'Force quit without saving')
|
end, 'Force quit without saving')
|
||||||
|
|
||||||
|
-- That concludes the keymaps section of the config.
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ o.numberwidth = 3 -- Set the width of the number column
|
|||||||
o.relativenumber = true -- Show relative line numbers
|
o.relativenumber = true -- Show relative line numbers
|
||||||
o.scrolloff = 15 -- Show context around cursor
|
o.scrolloff = 15 -- Show context around cursor
|
||||||
o.showmode = false -- Don't show mode
|
o.showmode = false -- Don't show mode
|
||||||
o.signcolumn = 'yes:2' -- Keep signcolumn on by default
|
o.signcolumn = 'yes:3' -- Keep signcolumn on by default
|
||||||
o.smartindent = true -- Insert indents automatically
|
o.smartindent = true -- Insert indents automatically
|
||||||
o.spell = true -- Enable spell checking
|
o.spell = true -- Enable spell checking
|
||||||
o.spelllang = 'en_us' -- Set the spell checking language
|
o.spelllang = 'en_us' -- Set the spell checking language
|
||||||
@@ -46,7 +46,7 @@ o.updatetime = 250 -- 250 ms = 2,5 seconds
|
|||||||
o.ignorecase = true -- Ignore case in search patterns
|
o.ignorecase = true -- Ignore case in search patterns
|
||||||
o.smartcase = true -- Override 'ignorecase' if pattern contains upper case chars
|
o.smartcase = true -- Override 'ignorecase' if pattern contains upper case chars
|
||||||
|
|
||||||
|
-- List options
|
||||||
o.list = true -- Show some invisible characters
|
o.list = true -- Show some invisible characters
|
||||||
o.listchars = { tab = '» ', trail = '·', nbsp = '␣' } -- Which invisible chars to show
|
o.listchars = { tab = '» ', trail = '·', nbsp = '␣' } -- Which invisible chars to show
|
||||||
|
|
||||||
|
|||||||
@@ -18,9 +18,11 @@ return {
|
|||||||
impersonate_nvim_cmp = true,
|
impersonate_nvim_cmp = true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
-- Set of preconfigured snippets for different languages.
|
-- Set of preconfigured snippets for different languages.
|
||||||
-- https://github.com/rafamadriz/friendly-snippets
|
-- https://github.com/rafamadriz/friendly-snippets
|
||||||
{ 'rafamadriz/friendly-snippets' },
|
{ 'rafamadriz/friendly-snippets' },
|
||||||
|
|
||||||
-- Lua plugin to turn github copilot into a cmp source
|
-- Lua plugin to turn github copilot into a cmp source
|
||||||
-- https://github.com/giuxtaposition/blink-cmp-copilot
|
-- https://github.com/giuxtaposition/blink-cmp-copilot
|
||||||
{
|
{
|
||||||
@@ -73,7 +75,10 @@ return {
|
|||||||
completion = {
|
completion = {
|
||||||
menu = {
|
menu = {
|
||||||
draw = {
|
draw = {
|
||||||
columns = { { "label", "label_description", gap = 1 }, { "kind_icon", "kind", gap = 1 } },
|
columns = {
|
||||||
|
{ "label", "label_description", gap = 1 },
|
||||||
|
{ "kind_icon", "kind", gap = 1 }
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
documentation = {
|
documentation = {
|
||||||
|
|||||||
@@ -9,8 +9,11 @@ return {
|
|||||||
opts = {
|
opts = {
|
||||||
bigfile = { enabled = true },
|
bigfile = { enabled = true },
|
||||||
gitbrowse = { enabled = true },
|
gitbrowse = { enabled = true },
|
||||||
|
notifier = {
|
||||||
|
enabled = true,
|
||||||
|
timeout = 3000,
|
||||||
|
},
|
||||||
notify = { enabled = true },
|
notify = { enabled = true },
|
||||||
notifier = { enabled = true },
|
|
||||||
quickfile = { enabled = true },
|
quickfile = { enabled = true },
|
||||||
statuscolumn = {
|
statuscolumn = {
|
||||||
enabled = true,
|
enabled = true,
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ return {
|
|||||||
-- Presets for common options and mappings
|
-- Presets for common options and mappings
|
||||||
{ 'echasnovski/mini.basics', version = '*' },
|
{ 'echasnovski/mini.basics', version = '*' },
|
||||||
|
|
||||||
|
-- Extend and create a/i textobjects
|
||||||
|
{ 'echasnovski/mini.ai', version = '*' },
|
||||||
|
|
||||||
-- Animate common Neovim actions
|
-- Animate common Neovim actions
|
||||||
-- Replaced anuvyklack/windows.nvim
|
-- Replaced anuvyklack/windows.nvim
|
||||||
{ 'echasnovski/mini.animate', version = '*', opts = {} },
|
{ 'echasnovski/mini.animate', version = '*', opts = {} },
|
||||||
@@ -69,6 +72,7 @@ return {
|
|||||||
{ mode = 'n', keys = '<Leader>b', desc = '+Buffers' },
|
{ mode = 'n', keys = '<Leader>b', desc = '+Buffers' },
|
||||||
{ mode = 'n', keys = '<Leader>c', desc = '+Code' },
|
{ mode = 'n', keys = '<Leader>c', desc = '+Code' },
|
||||||
{ mode = 'n', keys = '<Leader>cb', desc = '+CommentBox' },
|
{ mode = 'n', keys = '<Leader>cb', desc = '+CommentBox' },
|
||||||
|
{ mode = 'n', keys = '<Leader>cc', desc = '+Calls' },
|
||||||
{ mode = 'n', keys = '<Leader>q', desc = '+Quit' },
|
{ mode = 'n', keys = '<Leader>q', desc = '+Quit' },
|
||||||
{ mode = 'n', keys = '<Leader>s', desc = '+Telescope' },
|
{ mode = 'n', keys = '<Leader>s', desc = '+Telescope' },
|
||||||
{ mode = 'n', keys = '<Leader>t', desc = '+Toggle' },
|
{ mode = 'n', keys = '<Leader>t', desc = '+Toggle' },
|
||||||
@@ -104,7 +108,7 @@ return {
|
|||||||
version = '*',
|
version = '*',
|
||||||
opts = {
|
opts = {
|
||||||
highlighters = {
|
highlighters = {
|
||||||
-- Highlight standalone 'FIXME', 'HACK', 'TODO', 'NOTE'
|
-- Highlight standalone 'FIXME', 'HACK', 'TODO', 'NOTE', 'BUG', 'PERF' words
|
||||||
fixme = {
|
fixme = {
|
||||||
pattern = '%f[%w]()FIXME:?%s*()%f[%W]',
|
pattern = '%f[%w]()FIXME:?%s*()%f[%W]',
|
||||||
group = 'MiniHipatternsFixme',
|
group = 'MiniHipatternsFixme',
|
||||||
@@ -182,15 +186,40 @@ return {
|
|||||||
{ 'echasnovski/mini.operators', version = '*', opts = {} },
|
{ 'echasnovski/mini.operators', version = '*', opts = {} },
|
||||||
|
|
||||||
-- Session management (read, write, delete)
|
-- Session management (read, write, delete)
|
||||||
{ 'echasnovski/mini.sessions', version = '*', opts = {} },
|
{
|
||||||
|
'echasnovski/mini.sessions',
|
||||||
|
version = '*',
|
||||||
|
opts = {
|
||||||
|
autoread = true,
|
||||||
|
autowrite = true,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
-- Split and join arguments, lists, and other sequences
|
-- Split and join arguments, lists, and other sequences
|
||||||
-- Replaced Wansmer/treesj
|
-- Replaced Wansmer/treesj
|
||||||
{ 'echasnovski/mini.splitjoin', version = '*', opts = {} },
|
{ 'echasnovski/mini.splitjoin', version = '*', opts = {} },
|
||||||
|
|
||||||
-- Fast and flexible start screen
|
-- Fast and flexible start screen
|
||||||
-- Replaced glepnir/dashboard-nvim
|
-- Replaced glepnir/dashboard-nvim
|
||||||
{ 'echasnovski/mini.starter', version = '*', opts = {} },
|
{
|
||||||
|
'echasnovski/mini.starter',
|
||||||
|
version = '*',
|
||||||
|
config = function()
|
||||||
|
local starter = require('mini.starter')
|
||||||
|
starter.setup({
|
||||||
|
items = {
|
||||||
|
starter.sections.telescope(),
|
||||||
|
starter.sections.builtin_actions(),
|
||||||
|
starter.sections.sessions(5, true),
|
||||||
|
},
|
||||||
|
content_hooks = {
|
||||||
|
starter.gen_hook.adding_bullet(),
|
||||||
|
starter.gen_hook.indexing('all', { 'Builtin actions' }),
|
||||||
|
starter.gen_hook.aligning('center', 'center'),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
end
|
||||||
|
},
|
||||||
|
|
||||||
-- Minimal and fast statusline module with opinionated default look
|
-- Minimal and fast statusline module with opinionated default look
|
||||||
-- Replaced nvim-lualine/lualine.nvim
|
-- Replaced nvim-lualine/lualine.nvim
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ return {
|
|||||||
{ 'nvim-lua/plenary.nvim' },
|
{ 'nvim-lua/plenary.nvim' },
|
||||||
{ 'nvim-telescope/telescope-symbols.nvim' },
|
{ 'nvim-telescope/telescope-symbols.nvim' },
|
||||||
|
|
||||||
|
-- Telescope plugin for file browsing
|
||||||
|
{ 'nvim-telescope/telescope-file-browser.nvim' },
|
||||||
|
|
||||||
-- A Telescope picker to quickly access configurations
|
-- A Telescope picker to quickly access configurations
|
||||||
-- of plugins managed by lazy.nvim.
|
-- of plugins managed by lazy.nvim.
|
||||||
-- https://github.com/polirritmico/telescope-lazy-plugins.nvim
|
-- https://github.com/polirritmico/telescope-lazy-plugins.nvim
|
||||||
|
|||||||
84
config/nvim/lua/utils.lua
Normal file
84
config/nvim/lua/utils.lua
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
-- These are my utility functions
|
||||||
|
-- I use to make my life bit easier
|
||||||
|
|
||||||
|
-- ╭─────────────────────────────────────────────────────────╮
|
||||||
|
-- │ Function shortcuts for keymap set │
|
||||||
|
-- ╰─────────────────────────────────────────────────────────╯
|
||||||
|
|
||||||
|
-- Keymap set shortcut
|
||||||
|
--@type vim.keymap.set
|
||||||
|
local s = vim.keymap.set
|
||||||
|
|
||||||
|
-- Keymap shortcut functions
|
||||||
|
K = {}
|
||||||
|
|
||||||
|
-- Handle description
|
||||||
|
---@param desc string|table? Optional description. Can be a string or a table.
|
||||||
|
---@return table -- The description as a table.
|
||||||
|
local function handleDesc(desc)
|
||||||
|
if type(desc) == "string" then
|
||||||
|
-- Convert string to table with `desc` as a key
|
||||||
|
-- If the string is empty, just return as an empty description
|
||||||
|
return { desc = desc }
|
||||||
|
elseif type(desc) == "table" then
|
||||||
|
-- If desc doesn't have 'desc' key, combine it with
|
||||||
|
-- others with empty description
|
||||||
|
if not desc.desc then
|
||||||
|
desc.desc = '?'
|
||||||
|
return desc
|
||||||
|
end
|
||||||
|
-- Use the table as is
|
||||||
|
return desc
|
||||||
|
else
|
||||||
|
-- Default to an empty table if `desc` is nil or an unsupported type
|
||||||
|
return { desc = '?' }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Normal mode keymaps
|
||||||
|
---@param key string rhs, required
|
||||||
|
---@param cmd string|function lhs, required
|
||||||
|
---@param opts table? Options, optional
|
||||||
|
K.n = function(key, cmd, opts)
|
||||||
|
opts = handleDesc(opts or {})
|
||||||
|
s('n', key, cmd, opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Leader keymap shortcut function
|
||||||
|
-- It prepends '<leader>' to the key
|
||||||
|
---@param key string rhs, required, but will be prepended with '<leader>'
|
||||||
|
---@param cmd string|function lhs, required
|
||||||
|
---@param opts table|string? Options (or just description), optional
|
||||||
|
K.nl = function(key, cmd, opts)
|
||||||
|
opts = handleDesc(opts)
|
||||||
|
K.n('<leader>' .. key, cmd, opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Keymap shortcut function with mode defined, good for sorting by rhs
|
||||||
|
---@param key string rhs, required
|
||||||
|
---@param mode string|string[] one of n, v, x, or table of modes { 'n', 'v' }
|
||||||
|
---@param cmd string|function lhs, required
|
||||||
|
---@param opts string|table description, required
|
||||||
|
K.d = function(key, mode, cmd, opts)
|
||||||
|
opts = handleDesc(opts or {})
|
||||||
|
s(mode, key, cmd, opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Leader based keymap shortcut function with mode defined
|
||||||
|
---@param key string rhs, required, but will be prepended with '<leader>'
|
||||||
|
---@param mode string|string[] one of n, v, x, or table of modes { 'n', 'v' }
|
||||||
|
---@param cmd string|function lhs, required
|
||||||
|
---@param opts string|table description (or opts), required
|
||||||
|
K.ld = function(key, mode, cmd, opts)
|
||||||
|
opts = handleDesc(opts or {})
|
||||||
|
s(mode, '<leader>' .. key, cmd, opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- ╭─────────────────────────────────────────────────────────╮
|
||||||
|
-- │ Options related helper functions │
|
||||||
|
-- ╰─────────────────────────────────────────────────────────╯
|
||||||
|
|
||||||
|
-- Toggle background between light and dark
|
||||||
|
function ToggleBackground()
|
||||||
|
vim.o.bg = vim.o.bg == "light" and "dark" or "light"
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user