diff --git a/nvim/lua/config/helpers.lua b/nvim/lua/config/helpers.lua index 52f8ea6..70cadc5 100644 --- a/nvim/lua/config/helpers.lua +++ b/nvim/lua/config/helpers.lua @@ -1,3 +1,4 @@ return { keymap = require 'config.helpers.keymap', + visual = require 'config.helpers.visual', } diff --git a/nvim/lua/config/helpers/visual.lua b/nvim/lua/config/helpers/visual.lua new file mode 100644 index 0000000..1de1dd0 --- /dev/null +++ b/nvim/lua/config/helpers/visual.lua @@ -0,0 +1,19 @@ +---@class VisualArea +---@field sr number Start row +---@field sc number Start col +---@field er number End row +---@field ec number End col + +---Get current visual selection area +---@return VisualArea +return function() + local select = vim.fn.getpos 'v' + local cursor = vim.fn.getpos '.' + local sr, er = select[2], cursor[2] + local sc, ec = select[3], cursor[3] + + if sc > ec then sc, ec = ec, sc end + if sr > er then sr, er = er, sr end + + return { sr = sr, sc = sc, er = er, ec = ec } +end diff --git a/nvim/lua/config/keymaps.lua b/nvim/lua/config/keymaps.lua index 17e23cb..9051fa5 100644 --- a/nvim/lua/config/keymaps.lua +++ b/nvim/lua/config/keymaps.lua @@ -1,11 +1,11 @@ +local indent = require 'config.keymaps.indent' local map = require 'config.helpers.keymap' local n = map 'n' +local v = map 'v' local t = map 't' local nv = map {'n', 'v'} -n 'ex' ':Explore' 'Netrw: open' -n 'hl' ':nohl' 'Hide highlights' n 'j' 'gj' 'Move: down by line' n 'k' 'gk' 'Move: up by line' @@ -22,26 +22,29 @@ n '' 'k' 'Window: move up' n '' 'l' 'Window: move right' --- Diagnostics +-- Indentation +v '>' '>gv' 'Indent right' +v '<' 'e' (vim.diagnostic.open_float) 'Open error diagnostics' -n '[d' (vim.diagnostic.goto_prev) 'Previous diagnostic message' -n ']d' (vim.diagnostic.goto_next) 'Next diagnostic message' -n 'dl' (vim.diagnostic.setloclist) 'Diagnostic: list messages' + +-- Diagnostics +n 'e' (vim.diagnostic.open_float) 'Open error diagnostics' +n '[d' (vim.diagnostic.goto_prev) 'Previous diagnostic message' +n ']d' (vim.diagnostic.goto_next) 'Next diagnostic message' +n 'dl' (vim.diagnostic.setloclist) 'Diagnostic: list messages' -- Meta - local function open_config() vim.fn.chdir '~/.config/nvim' - vim.cmd [[:Explore]] + vim.cmd 'Explore' end n 'mn' (open_config) 'Meta: neovim config' -- LSP - do local group = vim.api.nvim_create_augroup('UserLspConfig', {}) diff --git a/nvim/lua/config/keymaps/indent.lua b/nvim/lua/config/keymaps/indent.lua new file mode 100644 index 0000000..11eaaed --- /dev/null +++ b/nvim/lua/config/keymaps/indent.lua @@ -0,0 +1,29 @@ +local get_visual = require 'config.helpers.visual' +local M = {} + + +function M.normalize() + local c = vim.fn.getpos '.' + local s = get_visual() + + local max = 0 + for line = s.sr, s.er do + local indent = vim.fn.indent(line) + max = indent > max and indent or max + end + + for line = s.sr, s.er do + local content = vim.fn.getline(line) + if content:len() > 0 then + local current = vim.fn.indent(line) + if current ~= max then + local new = string.rep(' ', max - current) + vim.fn.setline(line, new .. content) + end + end + end + + vim.fn.setpos('.', c) +end + +return M diff --git a/nvim/lua/config/plugins.lua b/nvim/lua/config/plugins.lua index 4c2e6cc..a26bd0e 100644 --- a/nvim/lua/config/plugins.lua +++ b/nvim/lua/config/plugins.lua @@ -274,7 +274,17 @@ return { config = function() local dap = require 'dap' - n 'b' (dap.toggle_breakpoint) 'DAP: Toggle breakpoint' + local function cond_breakpoint() + local cond = vim.fn.input('Breakpoint condition: ') + dap.set_breakpoint(cond) + end + + n '' (dap.continue) 'Debugger: continue' + n '' (dap.step_over) 'Debugger: step over' + n '' (dap.step_into) 'Debugger: step into' + n '' (dap.step_out) 'Debugger: step out' + n 'b' (dap.toggle_breakpoint) 'Debugger: toggle berakpoint' + n 'B' (cond_breakpoint) 'Debugger: toggle breakpoint (cond)' end, },