Totally revamped Config files
This commit is contained in:
@@ -1,134 +1,157 @@
|
||||
-- # vim:fileencoding=utf-8:foldmethod=marker
|
||||
|
||||
local set = vim.opt
|
||||
local opt = { noremap = true }
|
||||
local opts = { noremap = true, silent = true }
|
||||
local term_opts = { silent = true }
|
||||
|
||||
-- shorten function name
|
||||
local keymap = vim.api.nvim_set_keymap
|
||||
|
||||
-- Modes
|
||||
-- normal_mode = 'n',
|
||||
-- insert_mode = 'i', visual_mode = 'v', visual_block_mode = 'x',
|
||||
-- term_mode = 't',
|
||||
-- command_mode = 'c',
|
||||
-- {{{ Leader Key (moved to init.lua)
|
||||
-- vim.g.mapleader = " " -- set <Space> as leader key
|
||||
-- vim.g.maplocalleader = " " -- set <Space> as local leader key
|
||||
-- }}}
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- set space as leader key
|
||||
vim.g.mapleader = " " -- Set space as the leader key
|
||||
vim.g.maplocalleader = " " -- Optional: set local leader key to space as well
|
||||
-- switch colon to semicolon
|
||||
keymap("n", ";", ":", opt)
|
||||
keymap("n", ":", ";", opt)
|
||||
-- {{{ Basic Mappings
|
||||
keymap("n", ";", ":", opt) -- remap ; to :
|
||||
keymap("n", ":", ";", opt) -- remap : to ;
|
||||
|
||||
-- no arrows, move the vim way
|
||||
-- keymap("n", "<up>", "<nop>", opts)
|
||||
-- keymap("n", "<down>", "<nop>", opts)
|
||||
-- keymap("n", "<left>", "<nop>", opts)
|
||||
-- keymap("n", "<right>", "<nop>", opts)
|
||||
-- keymap("i", "<up>", "<nop>", opts)
|
||||
-- keymap("i", "<down>", "<nop>", opts)
|
||||
-- keymap("i", "<left>", "<nop>", opts)
|
||||
-- keymap("i", "<right>", "<nop>", opts)
|
||||
keymap("n", "<leader>w", ":w<cr>", opts) -- save
|
||||
keymap("n", "<leader>q", ":q<cr>", opts) -- quit
|
||||
keymap("n", "<leader>wq", ":wq<cr>", opts) -- save and quit
|
||||
keymap("n", "<leader>W", ":w!<cr>", opts) -- force save
|
||||
keymap("n", "<leader>Q", ":q!<cr>", opts) -- force quit
|
||||
keymap("n", "<leader>WQ", ":wq!<cr>", opts) -- force save and quit
|
||||
-- }}}
|
||||
|
||||
-- lazy write / quit
|
||||
keymap("n", "<leader>w", ":w<cr>", opts)
|
||||
keymap("n", "<leader>q", ":q<cr>", opts)
|
||||
keymap("n", "<leader>wq", ":wq<cr>", opts)
|
||||
keymap("n", "<leader>W", ":w!<cr>", opts)
|
||||
keymap("n", "<leader>Q", ":q!<cr>", opts)
|
||||
keymap("n", "<leader>WQ", ":wq!<cr>", opts)
|
||||
-- {{{ Navigation
|
||||
keymap("n", "j", "gj", opts) -- move visually down wrapped lines
|
||||
keymap("n", "k", "gk", opts) -- move visually up wrapped lines
|
||||
|
||||
-- navigate properly when lines are wrapped
|
||||
keymap("n", "j", "gj", opts)
|
||||
keymap("n", "k", "gk", opts)
|
||||
-- Keep arrow key navigation (non-standard but you requested it)
|
||||
keymap("n", "<Left>", "<C-w>h", opts) -- move to left window
|
||||
keymap("n", "<Right>", "<C-w>l", opts) -- move to right window
|
||||
keymap("n", "<Up>", "<C-w>k", opts) -- move to upper window
|
||||
keymap("n", "<Down>", "<C-w>j", opts) -- move to lower window
|
||||
|
||||
-- toggle linenumber
|
||||
vim.keymap.set("n", "<leader>n", function()
|
||||
if vim.wo.number and vim.wo.relativenumber then
|
||||
vim.wo.number = false
|
||||
vim.wo.relativenumber = false
|
||||
elseif vim.wo.number then
|
||||
vim.wo.relativenumber = true
|
||||
else
|
||||
vim.wo.number = true
|
||||
end
|
||||
keymap("n", "<s-l>", ":bnext<cr>", opts) -- next buffer
|
||||
keymap("n", "<s-h>", ":bprevious<cr>", opts) -- previous buffer
|
||||
-- }}}
|
||||
|
||||
-- {{{ Window Splitting
|
||||
keymap("n", "<leader>sv", ":vsplit<cr>", opts) -- split vertically
|
||||
keymap("n", "<leader>sh", ":split<cr>", opts) -- split horizontally
|
||||
keymap("n", "<leader>sc", ":close<cr>", opts) -- close current split
|
||||
keymap("n", "<leader>so", ":only<cr>", opts) -- close all other splits
|
||||
-- }}}
|
||||
|
||||
-- {{{ Window Resizing
|
||||
keymap("n", "<leader>+", ":resize +5<cr>", opts) -- increase window height
|
||||
keymap("n", "<leader>-", ":resize -5<cr>", opts) -- decrease window height
|
||||
keymap("n", "<leader><", ":vertical resize -5<cr>", opts) -- decrease window width
|
||||
keymap("n", "<leader>>", ":vertical resize +5<cr>", opts) -- increase window width
|
||||
keymap("n", "<leader>=", "<C-w>=", opts) -- equalize window sizes
|
||||
-- }}}
|
||||
|
||||
-- {{{ Visual Mode / Text, Clipboard
|
||||
keymap("v", ">", ">gv", opts) -- indent right, stay in visual mode
|
||||
keymap("v", "<", "<gv", opts) -- indent left, stay in visual mode
|
||||
|
||||
keymap("x", "<s-j>", ":move '>+1<CR>gv-gv", opts) -- move selected block down
|
||||
keymap("x", "<s-k>", ":move '<-2<CR>gv-gv", opts) -- move selected block up
|
||||
|
||||
keymap("n", "Q", "gq", opts) -- format paragraph
|
||||
keymap("x", "Q", "gq", opts) -- format selection
|
||||
|
||||
keymap("x", "Y", '"+y', opt) -- yank to system clipboard
|
||||
|
||||
keymap("n", "<space><space>", [[:%s/\<<c-r>=expand("<cword>")<cr>\>/]], opt) -- replace word under cursor
|
||||
-- }}}
|
||||
|
||||
-- {{{ Editing / Behavior
|
||||
keymap("n", "q", "<nop>", opts) -- disable q (record macro)
|
||||
keymap("n", "qq", "q", opts) -- if you really want to record macro use qq
|
||||
|
||||
keymap("n", "c", '"_c', opts) -- change without yanking to default register
|
||||
keymap("n", "C", '"_C', opts) -- change line without yanking to default register
|
||||
|
||||
vim.keymap.set("n", "<leader>n", function() -- toggle line numbers
|
||||
if vim.wo.number and vim.wo.relativenumber then
|
||||
vim.wo.number = false
|
||||
vim.wo.relativenumber = false
|
||||
elseif vim.wo.number then
|
||||
vim.wo.relativenumber = true
|
||||
else
|
||||
vim.wo.number = true
|
||||
end
|
||||
end, { desc = "Toggle line number modes" })
|
||||
|
||||
-- maintaining visual mode after shifting > and <
|
||||
keymap("v", ">", ">gv", opts)
|
||||
keymap("v", "<", "<gv", opts)
|
||||
keymap("n", "<leader>c", ":set cursorcolumn! cursorline! <cr>", opts) -- toggle cursor column and line
|
||||
|
||||
-- -- move text up and down in visual block mode
|
||||
keymap("x", "<s-j>", ":move '>+1<CR>gv-gv", opts)
|
||||
keymap("x", "<s-k>", ":move '<-2<CR>gv-gv", opts)
|
||||
keymap("n", "<esc>", ":nohlsearch<cr><esc>", opts) -- clear search highlight
|
||||
-- }}}
|
||||
|
||||
-- navigate buffers
|
||||
keymap("n", "<s-l>", ":bnext<cr>", opts)
|
||||
keymap("n", "<s-h>", ":bprevious<cr>", opts)
|
||||
-- {{{ Spellcheck
|
||||
keymap("n", "<leader>se", ":setlocal spell! spelllang=en_us<cr>", opts) -- toggle English spell check
|
||||
keymap("n", "<leader>sd", ":setlocal spell! spelllang=de_at<cr>", opts) -- toggle Austrian German spell check
|
||||
keymap("n", "<leader>ss", ":setlocal spell! spelllang=es<cr>", opts) -- toggle Spanish spell check
|
||||
-- }}}
|
||||
|
||||
-- scrolling command-line history
|
||||
keymap("c", "<c-j>", "<c-n>", opts)
|
||||
keymap("c", "<c-k>", "<c-p>", opts)
|
||||
-- {{{ Timestamp / Date
|
||||
keymap("n", "<leader>dt", [[i<c-r>=strftime("%d.%m.%Y")<cr><space>]], opts) -- insert current date
|
||||
keymap("n", "<leader>tt", [[i<c-r>=strftime("%H:%M")<cr><space>]], opts) -- insert current time
|
||||
-- }}}
|
||||
|
||||
-- open the current file in the default program
|
||||
keymap("n", "<leader>x", [[:!xdg-open %<cr><cr>]], opts)
|
||||
-- {{{ External / System
|
||||
keymap("n", "<leader>x", [[:!open %<cr><cr>]], opts) -- open current file with system default app
|
||||
|
||||
-- -- no ex mode for me - Q reformats long lines (auto-wrap)
|
||||
keymap("n", "Q", "gq", opts)
|
||||
keymap("x", "Q", "gq", opts)
|
||||
keymap("c", "w!!", [[w !sudo tee %]], opt) -- save file with sudo
|
||||
-- }}}
|
||||
|
||||
-- prevent accidentally record functionality
|
||||
keymap("n", "q", "<nop>", opts)
|
||||
keymap("n", "qq", "q", opts)
|
||||
-- {{{ Diff / Git
|
||||
keymap("n", "<leader>gd", ":Gvdiffsplit<cr>", opts) -- git diff split (requires fugitive)
|
||||
keymap("n", "<leader>gs", ":Git<cr>", opts) -- open git status tree (requires fugitive)
|
||||
keymap("n", "<leader>gr", ":terminal git log --graph --oneline --decorate --all<CR>i", opts) -- show git log graph in terminal
|
||||
|
||||
-- redirect change operations to blackhole avoid spoiling 'y' register content
|
||||
keymap("n", "c", '"_c', opts)
|
||||
keymap("n", "C", '"_C', opts)
|
||||
-- GitSigns toggles
|
||||
vim.keymap.set('n', '<leader>gt', function() require('gitsigns').toggle_signs() end, { desc = 'Toggle git signs' })
|
||||
vim.keymap.set('n', '<leader>gb', function() require('gitsigns').toggle_current_line_blame() end, { desc = 'Toggle git blame' })
|
||||
vim.keymap.set('n', '<leader>gx', function() require('gitsigns').toggle_deleted() end, { desc = 'Toggle git deleted' })
|
||||
vim.keymap.set('n', '<leader>gn', function() require('gitsigns').toggle_numhl() end, { desc = 'Toggle git number highlights' })
|
||||
vim.keymap.set('n', '<leader>gc', function() require('gitsigns').toggle_linehl() end, { desc = 'Toggle git line colors' })
|
||||
|
||||
-- toggle cursorcolumn
|
||||
keymap("n", "<leader>c", ":set cursorcolumn! cursorline! <cr>", opts)
|
||||
-- LSP diagnostic toggle
|
||||
vim.keymap.set('n', '<leader>ld', function()
|
||||
local config = vim.diagnostic.config()
|
||||
vim.diagnostic.config({
|
||||
virtual_text = not config.virtual_text,
|
||||
signs = not config.signs,
|
||||
underline = not config.underline,
|
||||
})
|
||||
end, { desc = 'Toggle LSP diagnostics' })
|
||||
|
||||
-- clear highlighting from the search
|
||||
keymap("n", "<esc>", ":nohlsearch<cr><esc>", opts)
|
||||
-- Toggle fold column
|
||||
vim.keymap.set("n", "<leader>un", function()
|
||||
vim.wo.foldcolumn = vim.wo.foldcolumn == "0" and "1" or "0"
|
||||
end, { desc = "Toggle fold column" })
|
||||
|
||||
-- toggle spell checking
|
||||
keymap("n", "<leader>se", ":setlocal spell! spelllang=en_us,nl<cr>", opts)
|
||||
keymap("n", "<leader>sd", ":setlocal spell! spelllang=de_at,nl<cr>", opts)
|
||||
keymap("n", "<leader>si", ":source $MYVIMRC<CR>", opts) -- source init.lua ($MYVIMRC is auto path to your init.lua)
|
||||
-- }}}
|
||||
|
||||
-- date time stamp
|
||||
keymap("n", "<leader>dt", [[i<c-r>=strftime("%d.%m.%Y")<cr><space>]], opts)
|
||||
keymap("n", "<leader>tt", [[i<c-r>=strftime("%H:%M")<cr><space>]], opts)
|
||||
-- {{{ Plugins
|
||||
-- Yazi (keeping this here since it's a simple command keymap)
|
||||
keymap("n", "<leader>y", ":Yazi<cr>", opt) -- open Yazi file manager
|
||||
|
||||
-- double space over word to find and replace
|
||||
keymap("n", "<space><space>", [[:%s/\<<c-r>=expand("<cword>")<cr>\>/]], opt)
|
||||
-- mkdx checkbox toggle (disable default space key, use leader+t instead)
|
||||
vim.g["mkdx#settings"] = {
|
||||
checkbox = {
|
||||
toggles = {' ', 'x', '-'},
|
||||
toggle_key = ''
|
||||
}
|
||||
}
|
||||
keymap("n", "<leader>t", "<Plug>(mkdx-checkbox-next-n)", opt) -- toggle markdown checkbox
|
||||
-- }}}
|
||||
|
||||
-- write file if you forgot to give it sudo permission
|
||||
keymap("c", "w!!", [[w !sudo tee %]], opt)
|
||||
|
||||
-- diff since last save
|
||||
keymap("n", "<leader>df", [[:w !diff % -<cr>]], opt)
|
||||
keymap("x", "<leader>df", [[:w !diff % -<cr>]], opt)
|
||||
|
||||
-- Yank to System Clipbpard
|
||||
keymap("x", "Y", '"+y', opt)
|
||||
keymap("n", "<leader>y", ':Yazi<cr>', opt)
|
||||
|
||||
local hop = require('hop')
|
||||
local directions = require('hop.hint').HintDirection
|
||||
vim.keymap.set('', 'f', function()
|
||||
hop.hint_char1({ direction = directions.AFTER_CURSOR, })
|
||||
end, {remap=true})
|
||||
vim.keymap.set('', 'F', function()
|
||||
hop.hint_char1({ direction = directions.BEFORE_CURSOR, })
|
||||
end, {remap=true})
|
||||
vim.keymap.set('', 't', function()
|
||||
hop.hint_char1({ direction = directions.AFTER_CURSOR, hint_offset = -1 })
|
||||
end, {remap=true})
|
||||
vim.keymap.set('', 'T', function()
|
||||
hop.hint_char1({ direction = directions.BEFORE_CURSOR, hint_offset = 1 })
|
||||
end, {remap=true})
|
||||
|
||||
vim.keymap.set('n', '<Left>', '<C-w>h', { noremap = true })
|
||||
vim.keymap.set('n', '<Right>', '<C-w>l', { noremap = true })
|
||||
vim.keymap.set('n', '<Up>', '<C-w>k', { noremap = true })
|
||||
vim.keymap.set('n', '<Down>', '<C-w>j', { noremap = true })
|
||||
-- {{{ Whole Document Select
|
||||
keymap("n", "<leader>a", "ggVG", opt) -- select entire document
|
||||
-- }}}
|
||||
|
||||
Reference in New Issue
Block a user