diff --git a/nvim/lua/mappings.lua b/nvim/lua/mappings.lua index c2940bd..d5f2b4a 100644 --- a/nvim/lua/mappings.lua +++ b/nvim/lua/mappings.lua @@ -1,57 +1,120 @@ local map = vim.keymap.set +local opts = { -- default options + noremap = true, -- non-recursive, i.e. ignore other mappings; true per default + silent = true, -- prevents command from being echoed in the command line +} -- ==================================================================== -- basic -- ==================================================================== --- disable U (scary behvaior) -map("n", "U", "", { noremap = true, silent = true }) --- centered cursor when scrolling -map("n", "", "zz", { noremap = true, silent = true }) -map("n", "", "zz", { noremap = true, silent = true }) --- ctrl+s saves in both normal and insert modes; insert returns to insert -map("n", "", ":w", { noremap = true, silent = true }) -map("i", "", ":wa", { noremap = true, silent = true }) --- preserve paste register when pasting over selection -map("x", "p", "\"_dP", { noremap = true, silent = true }) --- show dashboard -map("n", "d", ":Dashboard", { silent = true }) +map("n", "d", ":Dashboard", opts) -- show dashboard +map("n", "U", "", opts) -- disable U (scary behvaior) +-- Scroling and finding +map("n", "", "zz", opts) -- centered cursor when scrolling down +map("n", "", "zz", opts) -- centered cursor when scrolling up +map('n', 'n', 'nzzzv') -- Next search result stays centered +map('n', 'N', 'Nzzzv') -- Previous search result stays centered +-- Saving and quitting +map("n", "", ":w", opts) -- ctrl+s saves in normal ... +map("i", "", ":wa", opts) -- ... and in insert mode returns to insert +map('n', 'w', ':w') -- Save with space+w +map('n', 'q', ':q') -- Quit with space+q +map("x", "p", "\"_dP", opts) -- preserve paste register when pasting over selection +-- Directory Navigation +map('n', 'cd', ':cd %:p:h:pwd') -- cd to dir of current file and show it +map('n', 'cdww', ':lcd %:p:h:pwd', opts) -- window-local cd to dir of current file and show it +map('n', 'cdr', function() -- cd to git root of current file (if in git repo) + local handle = io.popen('git rev-parse --is-inside-work-tree 2>/dev/null') + if handle then + local result = handle:read("*a") + handle:close() + if result ~= "" then -- If in git repo + vim.cmd('cd ' .. vim.fn.system('git rev-parse --show-toplevel'):gsub('\n', '')) + vim.cmd('pwd') + else + vim.notify("Not in a git repository", vim.log.levels.WARN) + end + end +end, opts) +map('n', 'cdwr', function() -- window-local cd to git root of current file (if in git repo) + local handle = io.popen('git rev-parse --is-inside-work-tree 2>/dev/null') + if handle then + local result = handle:read("*a") + handle:close() + if result ~= "" then -- If in git repo + vim.cmd('lcd ' .. vim.fn.system('git rev-parse --show-toplevel'):gsub('\n', '')) + vim.cmd('pwd') + else + vim.notify("Not in a git repository", vim.log.levels.WARN) + end + end +end, opts) + + +-- terminal stuff +map('n', 'tt', ':lcd %:p:h:terminal', opts) -- open terminal in dir of current file +map('n', 'T', ':terminal', opts) -- open terminal in working directory +map('t', '', '', opts) -- all other mappings didn't work +-- vim.keymap.set('t', 'jk', '', { noremap = true }) +map('n', 'tr', function() -- terminal in git root (if in git repo) + local handle = io.popen('git rev-parse --is-inside-work-tree 2>/dev/null') + if handle then + local result = handle:read("*a") + handle:close() + if result ~= "" then + vim.cmd('lcd ' .. vim.fn.system('git rev-parse --show-toplevel'):gsub('\n', '')) + vim.cmd('terminal') + else + vim.notify("Not in a git repository", vim.log.levels.WARN) + end + end +end, opts) -- ==================================================================== -- lsp -- ==================================================================== -map("n", "gD", vim.lsp.buf.declaration, { silent = true }) -map("n", "gd", vim.lsp.buf.definition, { silent = true }) -map("n", "gi", vim.lsp.buf.implementation, { silent = true }) -map("n", "gs", vim.lsp.buf.signature_help, { silent = true }) +map("n", "gD", vim.lsp.buf.declaration, opts) +map("n", "gd", vim.lsp.buf.definition, opts) +map("n", "gi", vim.lsp.buf.implementation, opts) +map("n", "gs", vim.lsp.buf.signature_help, opts) -- TODO see :help vim.lsp.buf +-- ==================================================================== +-- lspsaga https://nvimdev.github.io/lspsaga/ +-- ==================================================================== + +map("n", "rn", ":Lspsaga rename ", opts) +map("n", "rN", ":Lspsaga rename ++project", opts) +-- map("n", "RN", ":Lspsaga project_replace ", d_opts) +map("n", "a", ":Lspsaga code_action", opts) + -- ==================================================================== -- diagnostic -- ==================================================================== -map("n", "[d", vim.diagnostic.goto_prev, { silent = true }) -map("n", "]d", vim.diagnostic.goto_next, { silent = true }) -map("n", "gef", vim.diagnostic.open_float, { silent = true }) -map("n", "geq", vim.diagnostic.setqflist, { silent = true }) +map("n", "[d", vim.diagnostic.goto_prev, opts) +map("n", "]d", vim.diagnostic.goto_next, opts) +map("n", "gef", vim.diagnostic.open_float, opts) +map("n", "geq", vim.diagnostic.setqflist, opts) -- ==================================================================== -- oil -- ==================================================================== -map("n", "-", "Oil", { silent = true }) +map("n", "-", "Oil", opts) -- ==================================================================== -- telescope -- ==================================================================== -map("n", "ff", ":Telescope find_files", { silent = true }) -map("n", "fw", ":Telescope live_grep", { silent = true }) -map("n", "fb", ":Telescope buffers", { silent = true }) -map("n", "gi", ":Telescope lsp_implementations", { silent = true }) -map("n", "gd", ":Telescope lsp_definitions", { silent = true }) -map("n", "gr", ":Telescope lsp_references", { silent = true }) -map("n", "gl", ":Telescope diagnostics", { silent = true }) +map("n", "ff", ":Telescope find_files", opts) +map("n", "fw", ":Telescope live_grep", opts) +map("n", "fb", ":Telescope buffers", opts) +map("n", "gi", ":Telescope lsp_implementations", opts) +map("n", "gd", ":Telescope lsp_definitions", opts) +map("n", "gr", ":Telescope lsp_references", opts) +map("n", "gl", ":Telescope diagnostics", opts) -- https://github.com/lukasl-dev/nixos/blob/master/dots/nvim/lua/mappings.lua diff --git a/nvim/lua/options.lua b/nvim/lua/options.lua index 7f95fba..5846df9 100644 --- a/nvim/lua/options.lua +++ b/nvim/lua/options.lua @@ -1,7 +1,10 @@ +-- https://vimhelp.org/options.txt.html +--------------------------------------- + local o = vim.opt -o.colorcolumn = "80" -o.showmode = false +o.colorcolumn = "120" +o.showmode = true o.number = true o.relativenumber = true @@ -23,4 +26,3 @@ o.undofile = true o.clipboard = "unnamedplus" o.cursorline = true o.cursorlineopt = "number" -