nvim: indentation keymaps
This commit is contained in:
parent
ca90017b85
commit
404837e2a0
|
@ -1,3 +1,4 @@
|
||||||
return {
|
return {
|
||||||
keymap = require 'config.helpers.keymap',
|
keymap = require 'config.helpers.keymap',
|
||||||
|
visual = require 'config.helpers.visual',
|
||||||
}
|
}
|
||||||
|
|
19
nvim/lua/config/helpers/visual.lua
Normal file
19
nvim/lua/config/helpers/visual.lua
Normal file
|
@ -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
|
|
@ -1,11 +1,11 @@
|
||||||
|
local indent = require 'config.keymaps.indent'
|
||||||
local map = require 'config.helpers.keymap'
|
local map = require 'config.helpers.keymap'
|
||||||
local n = map 'n'
|
local n = map 'n'
|
||||||
|
local v = map 'v'
|
||||||
local t = map 't'
|
local t = map 't'
|
||||||
local nv = map {'n', 'v'}
|
local nv = map {'n', 'v'}
|
||||||
|
|
||||||
|
|
||||||
n '<Leader>ex' ':Explore<CR>' 'Netrw: open'
|
|
||||||
n '<Leader>hl' ':nohl<CR>' 'Hide highlights'
|
|
||||||
|
|
||||||
n 'j' 'gj' 'Move: down by line'
|
n 'j' 'gj' 'Move: down by line'
|
||||||
n 'k' 'gk' 'Move: up by line'
|
n 'k' 'gk' 'Move: up by line'
|
||||||
|
@ -22,26 +22,29 @@ n '<C-k>' '<C-w>k' 'Window: move up'
|
||||||
n '<C-l>' '<C-w>l' 'Window: move right'
|
n '<C-l>' '<C-w>l' 'Window: move right'
|
||||||
|
|
||||||
|
|
||||||
-- Diagnostics
|
-- Indentation
|
||||||
|
v '>' '>gv' 'Indent right'
|
||||||
|
v '<' '<gv' 'Indent left'
|
||||||
|
v '|' (indent.normalize) 'Indent normalize'
|
||||||
|
|
||||||
n '<leader>e' (vim.diagnostic.open_float) 'Open error diagnostics'
|
|
||||||
n '[d' (vim.diagnostic.goto_prev) 'Previous diagnostic message'
|
-- Diagnostics
|
||||||
n ']d' (vim.diagnostic.goto_next) 'Next diagnostic message'
|
n '<leader>e' (vim.diagnostic.open_float) 'Open error diagnostics'
|
||||||
n '<leader>dl' (vim.diagnostic.setloclist) 'Diagnostic: list messages'
|
n '[d' (vim.diagnostic.goto_prev) 'Previous diagnostic message'
|
||||||
|
n ']d' (vim.diagnostic.goto_next) 'Next diagnostic message'
|
||||||
|
n '<leader>dl' (vim.diagnostic.setloclist) 'Diagnostic: list messages'
|
||||||
|
|
||||||
|
|
||||||
-- Meta
|
-- Meta
|
||||||
|
|
||||||
local function open_config()
|
local function open_config()
|
||||||
vim.fn.chdir '~/.config/nvim'
|
vim.fn.chdir '~/.config/nvim'
|
||||||
vim.cmd [[:Explore]]
|
vim.cmd 'Explore'
|
||||||
end
|
end
|
||||||
|
|
||||||
n '<leader>mn' (open_config) 'Meta: neovim config'
|
n '<leader>mn' (open_config) 'Meta: neovim config'
|
||||||
|
|
||||||
|
|
||||||
-- LSP
|
-- LSP
|
||||||
|
|
||||||
do
|
do
|
||||||
local group = vim.api.nvim_create_augroup('UserLspConfig', {})
|
local group = vim.api.nvim_create_augroup('UserLspConfig', {})
|
||||||
|
|
||||||
|
|
29
nvim/lua/config/keymaps/indent.lua
Normal file
29
nvim/lua/config/keymaps/indent.lua
Normal file
|
@ -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
|
|
@ -274,7 +274,17 @@ return {
|
||||||
config = function()
|
config = function()
|
||||||
local dap = require 'dap'
|
local dap = require 'dap'
|
||||||
|
|
||||||
n '<leader>b' (dap.toggle_breakpoint) 'DAP: Toggle breakpoint'
|
local function cond_breakpoint()
|
||||||
|
local cond = vim.fn.input('Breakpoint condition: ')
|
||||||
|
dap.set_breakpoint(cond)
|
||||||
|
end
|
||||||
|
|
||||||
|
n '<F5>' (dap.continue) 'Debugger: continue'
|
||||||
|
n '<F10>' (dap.step_over) 'Debugger: step over'
|
||||||
|
n '<F11>' (dap.step_into) 'Debugger: step into'
|
||||||
|
n '<F12>' (dap.step_out) 'Debugger: step out'
|
||||||
|
n '<leader>b' (dap.toggle_breakpoint) 'Debugger: toggle berakpoint'
|
||||||
|
n '<leader>B' (cond_breakpoint) 'Debugger: toggle breakpoint (cond)'
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue