nvim: better tabs

This commit is contained in:
Maciej Jur 2024-06-14 22:49:23 +02:00
parent 9657585534
commit fe0166970e
Signed by: kamov
GPG key ID: 191CBFF5F72ECAFD
2 changed files with 16 additions and 7 deletions

View file

@ -1,9 +1,10 @@
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'}
local map = require 'config.helpers.keymap'
local n = map 'n'
local i = map 'i'
local v = map 'v'
local t = map 't'
local nv = map { 'n', 'v' }
@ -21,13 +22,12 @@ n '<C-j>' '<C-w>j' 'Window: move down'
n '<C-k>' '<C-w>k' 'Window: move up'
n '<C-l>' '<C-w>l' 'Window: move right'
-- Indentation
i '<Tab>' (indent.smart_tab) { 'Indent', expr = true }
v '>' '>gv' 'Indent right'
v '<' '<gv' 'Indent left'
v '|' (indent.normalize) 'Indent normalize'
-- Diagnostics
n '<leader>e' (vim.diagnostic.open_float) 'Open error diagnostics'
n '[d' (vim.diagnostic.goto_prev) 'Previous diagnostic message'

View file

@ -2,6 +2,15 @@ local get_visual = require 'config.helpers.visual'
local M = {}
function M.smarttab()
local col = vim.fn.col '.'
if col == 1 or vim.fn.getline('.'):sub(1, col - 1):match '^%s*$' then
return '\t'
else
return string.rep(' ', vim.bo.tabstop or 2)
end
end
function M.normalize()
local c = vim.fn.getpos '.'
local s = get_visual()