From 42bee9e81f4051f19e528895f54a50ad14115785 Mon Sep 17 00:00:00 2001 From: srdusr Date: Tue, 31 Jan 2023 23:24:39 +0200 Subject: Squashed '.config/nvim/' changes from 5fad252..23457da 23457da Clean config | TODO: Clean config more d6e1a6e Change open_mapping to tt 082b92b Change ToggleDiagnosticsOpenFloat() mapping to to 5e61b34 Clean config git-subtree-dir: .config/nvim git-subtree-split: 23457da7c6d6a0bfc0a044b56c0e891fe862f8c0 --- lua/plugins/lsp.lua | 308 +----------------- lua/plugins/toggleterm.lua | 2 +- lua/user/keys.lua | 784 +++++++++++++-------------------------------- 3 files changed, 226 insertions(+), 868 deletions(-) diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index 4c5cf70..900121f 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -71,31 +71,6 @@ function _G.toggle_diagnostics() end end ---map('n', 'm', ':call v:lua.toggle_diagnostics()') - ---vim.g.diagnostics_active = true ---function _G.toggle_diagnostics() --- if vim.g.diagnostics_active then --- vim.g.diagnostics_active = false --- vim.lsp.diagnostic.clear(0) --- vim.cmd([[exe "normal ii\x"]]) --- vim.lsp.handlers["textDocument/publishDiagnostics"] = function() end --- else --- vim.g.diagnostics_active = true --- vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( --- vim.lsp.diagnostic.on_publish_diagnostics, { --- virtual_text = true, --- signs = true, --- underline = true, --- update_in_insert = false, --- } --- ) --- end ---end --- ---map("n", "i", ":call v:lua.toggle_diagnostics()") - - -- Set some key bindings conditional on server capabilities if client.server_capabilities.documentFormattingProvider then map("n", "f", vim.lsp.buf.format, { desc = "format code" }) @@ -136,73 +111,6 @@ if client.server_capabilities.document_highlight then }) end ---For diagnostics for specific cursor position ---vim.api.nvim_create_autocmd("CursorHold", { --- buffer = bufnr, --- callback = function() --- local opts = { --- focusable = false, --- close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" }, --- border = 'rounded', --- source = 'always', --- prefix = ' ', --- scope = 'cursor', --- } --- vim.diagnostic.open_float(nil, opts) --- end ---}) - -- Diagnostic position --- vim.api.nvim_create_autocmd("CursorHold", { --- buffer = bufnr, --- callback = function() --- local float_opts = { --- focusable = false, --- close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" }, --- border = "rounded", --- source = "always", -- show source in diagnostic popup window --- prefix = " ", --- } --- --- if not vim.b.diagnostics_pos then --- vim.b.diagnostics_pos = { nil, nil } --- end --- --- local cursor_pos = vim.api.nvim_win_get_cursor(0) --- if --- (cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2]) --- and #vim.diagnostic.get() > 0 --- then --- vim.diagnostic.open_float(nil, float_opts) --- end --- --- vim.b.diagnostics_pos = cursor_pos --- end, --- }) - - -- The below command will highlight the current variable and its usages in the buffer. --- if client.server_capabilities.documentHighlightProvider then --- vim.cmd([[ --- hi! link LspReferenceRead Visual --- hi! link LspReferenceText Visual --- hi! link LspReferenceWrite Visual --- augroup lsp_document_highlight --- autocmd! * --- autocmd CursorHold lua vim.lsp.buf.document_highlight() --- autocmd CursorHoldI lua vim.lsp.buf.document_highlight() --- autocmd CursorMoved lua vim.lsp.buf.clear_references() --- augroup END --- ]]) --- end --- - -- Only highlight if compatible with the language --- if client.resolved_capabilities.document_highlight then --- vim.cmd('augroup LspHighlight') --- vim.cmd('autocmd!') --- vim.cmd('autocmd CursorHold lua vim.lsp.buf.document_highlight()') --- vim.cmd('autocmd CursorMoved lua vim.lsp.buf.clear_references()') --- vim.cmd('augroup END') --- end - if vim.g.logging_level == "debug" then local msg = string.format("Language server %s started!", client.name) vim.notify(msg, vim.log.levels.DEBUG, { title = "Server?" }) @@ -348,59 +256,6 @@ vim.diagnostic.config({ update_in_insert = false, -- default to false severity_sort = false, -- default to false }) --- Show line diagnostics automatically in hover window ---vim.o.updatetime = 250 ---vim.cmd [[autocmd CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {focusable = false,})]] ---vim.cmd ([[ noremap a :autocmd! CursorHold,CursorHoldI ]]) - ---vim.cmd [[ noremap a :autocmd! CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {focusable = false,})]] ---local diagnostics_active = true ---local toggle_diagnostics = function() --- diagnostics_active = not diagnostics_active --- if diagnostics_active then --- vim.o.updatetime = 250 --- vim.cmd ([[autocmd! CursorHold,CursorHoldI ]]) --- --vim.diagnostic.open_float(nil, {focus=false}) --- else --- vim.o.updatetime = 250 --- vim.cmd [[autocmd CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {focus=false})]] --- --vim.diagnostic.hide() --- --vim.diagnostic.disable() --- end ---end ---vim.keymap.set("n", "a", toggle_diagnostics) - ---function LspDiagnosticsFocus() --- vim.api.nvim_command('set eventignore=WinLeave') --- vim.api.nvim_command('autocmd CursorMoved ++once set eventignore=""') --- vim.diagnostic.open_float(nil, {focusable = false, scope = 'line', close_events = {"CursorMoved", "CursorMovedI", "BufHidden", "InsertCharPre", "WinLeave"}}) ---end ---vim.api.nvim_set_keymap('', 'a', 'lua LspDiagnosticsFocus()', {silent = true}) - --vim.o.updatetime = 250 - --- vim.o.updatetime = 250 -----vim.o.updatetime = 250 -----vim.cmd [[autocmd CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {focusable = false,})]] -----local diagnostics_active = true ---local toggle_diagnostics = function() --- --diagnostics_active = not diagnostics_active --- --if diagnostics_active then --- --if vim.diagnostic.open_float() == true then --- if vim.api.nvim_exec([[autocmd CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {focus=false})]] ---, true) then --- vim.api.nvim_exec([[autocmd! CursorHold,CursorHoldI ]] ---, true) --- else --- vim.o.updatetime = 250 --- vim.api.nvim_exec([[autocmd CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {focus=false})]], true) --- end ---end ---vim.keymap.set("n", "a", toggle_diagnostics) --- ---vim.api.nvim_create_autocmd('CursorHold', { --- vim.diagnostic.open_float(nil, {focus=false}) --- ---}) vim.o.updatetime = 250 vim.cmd[[ @@ -426,52 +281,9 @@ function! ToggleDiagnosticsOpenFloat() augroup END endif endfunction -nnoremap o :call ToggleDiagnosticsOpenFloat()\|:echom "vim.diagnostic.open_float disabled . . ." +nnoremap to :call ToggleDiagnosticsOpenFloat()\|:echom "vim.diagnostic.open_float disabled . . ." ]]) ---vim.lsp.handlers["textDocument/hover"] = vim.lsp.with( --- vim.lsp.handlers.hover, { --- signs = true, --- underline = false, --- virtual_text = false, --- show_diagnostic_autocmds = {'InsertLeave', 'TextChanged'}, --- diagnostic_delay = 500 --- }) ---vim.cmd [[autocmd CursorHold * lua vim.diagnostic.open_float(0, {scope="cursor", close_events = {"CursorMoved", "CursorMovedI", "BufHidden", "InsertCharPre", "WinLeave"}})]] - ---function LspDiagnosticsFocus() --- vim.api.nvim_command('set eventignore=WinLeave') --- vim.api.nvim_command('autocmd CursorMoved ++once set eventignore=""') --- vim.diagnostic.open_float(nil, {focusable = false, scope = 'line', close_events = {"CursorMoved", "CursorMovedI", "BufHidden", "InsertCharPre", "WinLeave"}}) ---end ---vim.api.nvim_set_keymap('', 'a', 'lua LspDiagnosticsFocus()', {silent = true}) - ---local diagnostics_active = true ---map('n', 'a', function() --- diagnostics_active = not diagnostics_active --- if diagnostics_active then --- vim.diagnostic.show() --- else --- vim.diagnostic.hide() --- end ---end) - --- Global config for diagnostic ---vim.diagnostic.config({ --- underline = false, --- virtual_text = false, --- signs = true, --- severity_sort = true, --- float = { --- focusable = true, -- --- style = "minimal", -- --- --border = "rounded", --- border = "shadow", --- source = "always", --- header = "", --- prefix = "", --- }, ---}) vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { underline = true, @@ -487,125 +299,11 @@ vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = "rounded" }) ---local signs = { Error = " ", Warn = " ", Info = "􀅴 ", Hint = " " } ---local signs = { Error = "✘", Warn = "▲", Info = "🛈 ", Hint = "⚑" } -local signs = { Error = "✘", Warn = "▲", Info = "􀅳", Hint = "⚑" } +--local signs = { Error = "✘", Warn = "▲", Info = "􀅳", Hint = "⚑" } +local signs = { Error = " ", Warn = "▲", Info = "􀅳", Hint = "⚑" } for type, icon in pairs(signs) do local hl = "DiagnosticSign" .. type vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) end ----- Location information about the last message printed. The format is ----- `(did print, buffer number, line number)`. ---local last_echo = { false, -1, -1 } --- ----- The timer used for displaying a diagnostic in the commandline. ---local echo_timer = nil --- ----- The timer after which to display a diagnostic in the commandline. ---local echo_timeout = 250 --- ----- The highlight group to use for warning messages. ---local warning_hlgroup = 'WarningMsg' --- ----- The highlight group to use for error messages. ---local error_hlgroup = 'ErrorMsg' --- ----- If the first diagnostic line has fewer than this many characters, also add ----- the second line to it. ---local short_line_limit = 20 --- ----- Shows the current line's diagnostics in a floating window. ---function show_line_diagnostics() --- vim --- .lsp --- .diagnostic --- .show_line_diagnostics({ severity_limit = 'Warning' }, vim.fn.bufnr('')) ---end --- ----- Prints the first diagnostic for the current line. ---function echo_diagnostic() --- if echo_timer then --- echo_timer:stop() --- end --- --- echo_timer = vim.defer_fn( --- function() --- local line = vim.fn.line('.') - 1 --- local bufnr = vim.api.nvim_win_get_buf(0) --- --- if last_echo[1] and last_echo[2] == bufnr and last_echo[3] == line then --- return --- end --- --- local diags = vim --- .lsp --- .diagnostic --- .get_line_diagnostics(bufnr, line, { severity_limit = 'Warning' }) --- --- if #diags == 0 then --- -- If we previously echo'd a message, clear it out by echoing an empty --- -- message. --- if last_echo[1] then --- last_echo = { false, -1, -1 } --- --- vim.api.nvim_command('echo ""') --- end --- --- return --- end --- --- last_echo = { true, bufnr, line } --- --- local diag = diags[1] --- local width = vim.api.nvim_get_option('columns') - 15 --- local lines = vim.split(diag.message, "\n") --- local message = lines[1] --- local trimmed = false --- --- if #lines > 1 and #message <= short_line_limit then --- message = message .. ' ' .. lines[2] --- end --- --- if width > 0 and #message >= width then --- message = message:sub(1, width) .. '...' --- end --- --- local kind = 'warning' --- local hlgroup = warning_hlgroup --- --- if diag.severity == vim.lsp.protocol.DiagnosticSeverity.Error then --- kind = 'error' --- hlgroup = error_hlgroup --- end --- --- local chunks = { --- { kind .. ': ', hlgroup }, --- { message } --- } --- --- vim.api.nvim_echo(chunks, false, {}) --- end, --- echo_timeout --- ) ---end ---vim.cmd([[ --- autocmd CursorMoved * :lua echo_diagnostic() ---]]) --- Highlight line number instead of having icons in sign column - --- See the properties of the signs with sign list. - ---vim.cmd [[ --- highlight! DiagnosticLineNrError guibg=#51202A guifg=#FF0000 gui=bold --- highlight! DiagnosticLineNrWarn guibg=#51412A guifg=#FFA500 gui=bold --- highlight! DiagnosticLineNrInfo guibg=#1E535D guifg=#00FFFF gui=bold --- highlight! DiagnosticLineNrHint guibg=#1E205D guifg=#0000FF gui=bold --- --- sign define DiagnosticSignError text= texthl=DiagnosticSignError linehl= numhl=DiagnosticLineNrError --- sign define DiagnosticSignWarn text= texthl=DiagnosticSignWarn linehl= numhl=DiagnosticLineNrWarn --- sign define DiagnosticSignInfo text= texthl=DiagnosticSignInfo linehl= numhl=DiagnosticLineNrInfo --- sign define DiagnosticSignHint text= texthl=DiagnosticSignHint linehl= numhl=DiagnosticLineNrHint ---]] - diff --git a/lua/plugins/toggleterm.lua b/lua/plugins/toggleterm.lua index 912729a..0c3c45f 100644 --- a/lua/plugins/toggleterm.lua +++ b/lua/plugins/toggleterm.lua @@ -12,7 +12,7 @@ toggleterm.setup({ end end, --size = 20, - open_mapping = [[to]], + open_mapping = [[tt]], hide_numbers = true, shade_filetypes = {}, shade_terminals = false, diff --git a/lua/user/keys.lua b/lua/user/keys.lua index 712835a..f01a0c5 100644 --- a/lua/user/keys.lua +++ b/lua/user/keys.lua @@ -1,27 +1,18 @@ --[[ key.lua ]] --- Shorten function name ---local keymap = vim.api.nvim_set_keymap -local keymap = vim.keymap - ---local function new_desc(d) --- return { desc = d } ---end --- ---local d = new_desc ---local opts = { noremap = true, silent = true } +------------- Shorten Function Names -------------- +local keymap = vim.keymap +local map = function(mode, l, r, opts) + opts = opts or {} + opts.silent = true + opts.noremap = true + keymap.set(mode, l, r, opts) +end local term_opts = { noremap = true, silent = false } - local map = function(mode, l, r, opts) - opts = opts or {} - opts.silent = true - opts.noremap = true - keymap.set(mode, l, r, opts) - end --------------- Standard Operations --------------- - -- Semi-colon as leader key vim.g.mapleader = ";" @@ -34,190 +25,39 @@ vim.g.mapleader = ";" -- "jj" to exit insert-mode map("i", "jj", "") -map("n", "m", ":messages") -map("n", "cd", ":cd %:p:h:pwd") --- Print last error message or use these commands | v:errmsgv | :statusmsg | :h execute() | ---nnoremap x :put =trim(execute(input(':', '', 'command'))) --- Press x, then enter your command, such as 5mess and press . The last five message lines will be added to the current buffer. --- useful to copy error message when vim start - --- save quickly ---map("n", ";w", ":w", d("Save buffer")) - ---map("n", "so", ":luafile %") - ---vim.cmd([[ ---let $my_vimrc = $localappdata.'/nvim/init.lua' ---nnoremap so :source $my_vimrc ---]]) - --- Toggle between folds ---utils.map("n", "", "&foldlevel ? 'zM' : 'zR'", { expr = true }) - --- Move to the next and previous item in the quickfixlist ---utils.map("n", "]c", "cnext") ---utils.map("n", "[c", "cprevious") - --- Use space to toggle fold ---utils.map("n", "", "za") - --- Hitting ESC when inside a terminal to get into normal mode ---utils.map("t", "", [[]]) - --- select last change ---nnoremap gV `[v`] - ---map("n", "", function() --- notify.dismiss() --- vim.cmd.noh() ---end) - ---"nnore fast [e]dit and [s]ourcing .[v]imrc ---nnoremap ev :edit $MYVIMRC ---"fast macro ---nnoremap @ set lazyredraw execute 'noautocmd norm! ' . v:count1 . '@' . getcharstr() set nolazyredraw ---xnoremap @ :set lazyredraw execute "noautocmd '<,'>norm! " . v:count1 . "@" . getcharstr() set nolazyredraw - ---map("n", "", ":runtime! /lua/plugins/*.lua | :runtime! /lua/user/*.lua | :luafile ~/.config/nvim/init.lua", print ("Nvim reloaded")) ---map("n", "", ":lua require('init').unload_lua_namespace()", print ("Nvim reloaded")) ---map("n", "", "luafile ~/.config/nvim/init.lua", vim.notify("Nvim configuration reloaded!", vim.log.levels.INFO)) ---map("n", "", "luafile ~/.config/nvim/init.lua | :lua require("notify")("completion off")") ---map("n", "", "luafile ~/.config/nvim/init.lua", vim.api.nvim_echo({{'first chunk and ', 'None'}, {'second chunk to echo', 'None'}}, false, {})) ---map("n", "", "luafile ~/.config/nvim/init.lua", print ("Nvim config loading...")) ---map("n", "", "luafile ~/.config/nvim/init.lua | :echo ('hello') | ") +-- Reload nvim config map("n", "", "luafile ~/.config/nvim/init.lua | :echom ('Nvim config loading...') | :sl! | echo ('')") -map("n", "u", ":echo '' | redraw") --clear messages ---map("n", "", "luafile ~/.config/nvim/init.lua") ---vim.api.nvim_set_keymap("n", "", "lua ReloadConfig()", { noremap = true, silent = false }) - -map("n", "tc", ":lua require('user.utils').toggle_completion()") --- vim.notify("Nvim configuration reloaded!", vim.log.levels.INFO) - ---vim.api.nvim_set_keymap('n', 'qr', ':lua require("plugins.telescope").reload()', { noremap = true, silent = true }) - ----- Terminal ---if is_available "toggleterm.nvim" then --- local toggle_term_cmd = astronvim.toggle_term_cmd -map("n", "gg", ":LazyGit") -map("n", "tt", "ToggleTerm") - ----- Fugitive git bindings -map("n", "ga", ":Git add %:p") ---map("n", "gs", ":Gstatus") -map("n", "gc", ":Gcommit -v -q") -map("n", "gt", ":Gcommit -v -q %:p") ---map("n", "gd", ":Gdiff") -map("n", "ge", ":Gedit") ---map("n", "gr", ":Gread") -map("n", "gw", ":Gwrite") -map("n", "gl", ":silent! Glog:bot copen") ---map("n", "gp", ":Ggrep") ---map("n", "gp", ":Git push") ---map("n", "gb", ":Gblame") -map("n", "gm", ":Gmove") ---map("n", "gb", ":Git branch") ---map("n", "go", ":Git checkout") ---map("n", "gps", ":Dispatch! git push") ---map("n", "gpl", ":Dispatch! git pull") - --- maps.n[""] = { "ToggleTerm", desc = "Toggle terminal" } --- maps.n["gg"] = { function() toggle_term_cmd "lazygit" end, desc = "ToggleTerm lazygit" } --- maps.n["tn"] = { function() toggle_term_cmd "node" end, desc = "ToggleTerm node" } --- maps.n["tu"] = { function() toggle_term_cmd "ncdu" end, desc = "ToggleTerm NCDU" } --- maps.n["tt"] = { function() toggle_term_cmd "htop" end, desc = "ToggleTerm htop" } --- maps.n["tp"] = { function() toggle_term_cmd "python" end, desc = "ToggleTerm python" } --- maps.n["tl"] = { function() toggle_term_cmd "lazygit" end, desc = "ToggleTerm lazygit" } --- maps.n["tf"] = { "ToggleTerm direction=float", desc = "ToggleTerm float" } --- maps.n["th"] = { "ToggleTerm size=10 direction=horizontal", desc = "ToggleTerm horizontal split" } --- maps.n["tv"] = { "ToggleTerm size=80 direction=vertical", desc = "ToggleTerm vertical split" } ---end --- ---Easier split navigations, just ctrl-j instead of ctrl-w then j ---map("n", "", "") ---map("n", "", "") ---map("n", "", "") ---map("n", "", "") - --- Tmux navigation (aserowy/tmux.nvim) ---map("n", "", ":lua require'tmux'.move_left()") ---map("n", "", ":lua require'tmux'.move_bottom()") ---map("n", "", ":lua require'tmux'.move_top()") ---map("n", "", ":lua require'tmux'.move_right()") -map('n', '', 'NavigatorLeft') -map('n', '', 'NavigatorRight') -map('n', '', 'NavigatorUp') -map('n', '', 'NavigatorDown') - --- set line wrap -map("n", "", function() - local wrap_status = vim.api.nvim_exec("set wrap ?", true) - - if wrap_status == "nowrap" then - vim.api.nvim_command("set wrap linebreak") - print("Wrap enabled") - else - vim.api.nvim_command("set wrap nowrap") - print("Wrap disabled") - end -end, { silent = true }) +--------------- Extended Operations --------------- -- Combine buffers list with buffer name map("n", "b", ":buffers:buffer") ---map("n", "b", ":ls:b") --- Map buffer next, prev and delete to +-- Buffer confirmation +map("n", "y", ":BufferPick") + +-- Map buffer next, prev and delete to +(n/p/d) respectively map("n", "n", ":bn") map("n", "p", ":bp") map("n", "d", ":bd") --- Disable default completion. -map('i', '', '') -map('i', '', '') - --- Set alt + j/k to switch lines of texts or simply move them -map("n", "", ':let save_a=@a"add"ap:let @a=save_a') -map("n", "", ':let save_a=@a"add"ap:let @a=save_a') +-- List marks +map("n", "m", ":marks") -map("i", "", "") - -map("n", "", "!clear") - -map("n", "y", ":BufferPick") - -vim.cmd([[ - inoremap - inoremap - inoremap - inoremap -]]) - -vim.cmd([[ - cnoremap - cnoremap - cnoremap - cnoremap -]]) - ---vim.cmd([[ --- cnoremap --- cnoremap --- cnoremap --- cnoremap ---]]) +-- Toggle set number +map("n", "$", ":NumbersToggle") +map("n", "%", ":NumbersOnOff") -vim.cmd([[ - snoremap - snoremap - snoremap - snoremap -]]) +-- Easier split navigations, just ctrl-j instead of ctrl-w then j +--map("n", "", "") +--map("n", "", "") +--map("n", "", "") +--map("n", "", "") --- move block easily -map("n", "<", "<<", term_opts) -map("n", ">", ">>", term_opts) -map("x", "<", "", ">gv", term_opts) +-- Split window +map("n", "h", ":split") +map("n", "v", ":vsplit") +map("n", "c", "c") -- Resize Panes map("n", "+", ":resize +5") @@ -226,13 +66,33 @@ map("n", "<", ":vertical resize +5") map("n", ">", ":vertical resize -5") map("n", "=", "=") --- New tab +-- Map Alt+(h/j/k/l) in insert mode to move directional +map("i", "", "") +map("i", "", "") +map("i", "", "") +map("i", "", "") + +-- Map Alt+(h/j/k/l) in command mode to move directional +map("c", "", "") +map("c", "", "") +map("c", "", "") +map("c", "", "") + +-- Map Alt+(h/j/k/l) in selection mode to move directional +map("s", "", "") +map("s", "", "") +map("s", "", "") +map("s", "", "") + +-- Create tab, edit and move between them +map("n", "n", ":tabnew") map("n", "e", ":tabedit") +map("n", "[", ":tabprev") +map("n", "]", ":tabnext") --- create tab like window -map("n", "h", ":tabprevious") -map("n", "l", ":tabnext") -map("n", "n", ":tabnew") +-- "Zoom" a split window into a tab and/or close it +--map("n", ",", ":tabnew %") +--map("n", ".", ":tabclose") -- Vim TABs map("n", "1", "1gt") @@ -246,192 +106,85 @@ map("n", "8", "8gt") map("n", "9", "9gt") map("n", "0", "10gt") --- Split window -map("n", "h", ":split") -map("n", "v", ":vsplit") -map("n", "c", "c") +-- Move to the next and previous item in the quickfixlist +--map("n", "]c", "cnext") +--map("n", "[c", "cprevious") --- Toggle set number -map("n", "$", ":NumbersToggle") -map("n", "%", ":NumbersOnOff") +-- Hitting ESC when inside a terminal to get into normal mode +--map("t", "", [[]]) --- Change mode to executable -map("n", "x", ":!chmod +x %") +-- Move block (indentation) easily +map("n", "<", "<<", term_opts) +map("n", ">", ">>", term_opts) +map("x", "<", "", ">gv", term_opts) --- Paste without replace clipboard -map("v", "p", '"_dP') +-- Set alt+(j/k) to switch lines of texts or simply move them +map("n", "", ':let save_a=@a"add"ap:let @a=save_a') +map("n", "", ':let save_a=@a"add"ap:let @a=save_a') --- Paste end of line ---map("n", ",", "$p") ---vim.cmd([[ --- nmap , $p ---]]) +-- Search and replace +map("v", "sr", 'y:%s/"//gc') --- Select entire buffer ---map("v", "", "ggG") +-- Map delete to Ctrl+l +map("i", "", "") --- Delete without changing the registers ---map('n', 'x', '"_x') +-- Clear screen +map("n", "", "!clear") --- Select all text in current buffer ---map('n', 'a', ':keepjumps normal! ggVG') +-- Change file to an executable +map("n", "x", ":!chmod +x %") + +-- Paste without replace clipboard +map("v", "p", '"_dP') -- Swap two pieces of text, use x to cut in visual mode, then use Ctrl-x in -- visual mode to select text to swap with map("v", "", "`.``gvP``P") --- Keep Visual mode selection when indenting text ---utils.map("x", ">", ">gv") ---utils.map("x", "<", "u", ":echo '' | redraw") --- Make visual pasting a word to not update the unnamed register --- Thus, allowing us to repeatedly paste the word. {"_ : black-hole register} ---utils.map("v", "p", [["_dP]]) +-- Change Working Directory to current project +map("n", "cd", ":cd %:p:h:pwd") --- Whole-word search ---utils.map("n", "/", ":/\\<\\>", { silent = false }) +-- Open the current file in the default program (on Mac this should just be just `open`) +map('n', 'o', ':!xdg-open %') --- EasyAlign keybindings --- 'vipga' starts interactive EasyAlign in visual mode --- 'gaip' starts interactive EasyAlign for text/motion object ---utils.map({ "n", "x" }, "ga", "(EasyAlign)") ---utils.map({ "n", "x" }, "ga", "(LiveEasyAlign)") +-- Unsets the 'last search pattern' register by hitting return +map("n", "", "!silent :noh") --- Set a mark when moving more than 5 lines upwards/downards --- this will populate the jumplist enabling us to jump back with Ctrl-O ---utils.map("n", "k", [[(v:count > 5 ? "m'" . v:count : "") . 'k']], { expr = true }) ---utils.map("n", "j", [[(v:count > 5 ? "m'" . v:count : "") . 'j']], { expr = true }) +-- Toggle completion +map("n", "tc", ":lua require('user.utils').toggle_completion()") --- Zoom toggle a buffer in a new tab ---utils.map("n", "z", function() --- require("tt.helper").zoomToggleNewTab() ---end, { desc = "Zoom toggle a buffer in a new tab" }) +-- Disable default completion. +map('i', '', '') +map('i', '', '') --- Hitting ESC when inside a terminal to get into normal mode ---utils.map("t", "", [[]]) +-- Set line wrap +map("n", "", function() + local wrap_status = vim.api.nvim_exec("set wrap ?", true) --- markdown-preview -map("n", "md", "MarkdownPreviewToggle") + if wrap_status == "nowrap" then + vim.api.nvim_command("set wrap linebreak") + print("Wrap enabled") + else + vim.api.nvim_command("set wrap nowrap") + print("Wrap disabled") + end +end, { silent = true }) +-- Toggle between folds +--utils.map("n", "", "&foldlevel ? 'zM' : 'zR'", { expr = true }) --- Search and replace -map("v", "sr", 'y:%s/"//gc') ---vnoremap ; :call Get_visual_selection() --- ---function! Get_visual_selection() --- " Why is this not a built-in Vim script function?! --- let [lnum1, col1] = getpos("'<")[1:2] --- let [lnum2, col2] = getpos("'>")[1:2] --- let lines = getline(lnum1, lnum2) --- let lines[-1] = lines[-1][: col2 - (&selection == 'inclusive' ? 1 : 2)] --- let lines[0] = lines[0][col1 - 1:] --- let selection = join(lines,'\n') --- let change = input('Change the selection with: ') --- execute ":%s/".selection."/".change."/g" ---endfunction -vim.cmd([[ -let s:hidden_all = 0 -function! ToggleHiddenAll() - if s:hidden_all == 0 - let s:hidden_all = 1 - set noshowmode - set noruler - set laststatus=0 - set noshowcmd - else - let s:hidden_all = 0 - set showmode - set ruler - set laststatus=2 - set showcmd - endif -endfunction -nnoremap :call ToggleHiddenAll() -]]) +-- Use space to toggle fold +--utils.map("n", "", "za") +-- Make a copy of current file vim.cmd([[ map s :up \| saveas! %:p:r-=strftime("%y.%m.%d-%H:%M")-bak.=expand("%:e") \| 3sleep \| e # ]]) --- Execute this file ---map("n", "x", ":call scripts#save_and_exec()", print("save & exec")) -vim.cmd([[ - " Execute this file - nnoremap x :call scripts#save_and_exec()\|:echom "save & exec . . ." - -]]) - --------------- FZF -------------- -map("n", "fz", "lua require('fzf-lua').files()") - --------------- Telescope -------------- ---Telescope find_files cwd=.. -map("n", "fc", "lua require('telescope.builtin').commands()") -map("n", "cf", "Telescope changed_files") -map("n", "fk", "lua require('telescope.builtin').keymaps()") -map("n", "fh", "lua require('telescope.builtin').help_tags()") ---map( --- "n", --- "ft", --- "lua require('telescope.builtin').builtin(require('telescope.themes').get_dropdown({}))") - --- maps.n["fF"] = { --- function() require("telescope.builtin").find_files { hidden = true, no_ignore = true } end, --- desc = "Search all files", --- Telescope find_files hidden=true ---map("n", "fh", "lua require('telecsope.builtin').file_files hidden=true") -map("n", "ff", function() require("telescope.builtin").find_files { hidden = true, no_ignore = true } end) ---map("n", "fe", ":lua require('telescope.builtin').file_browser({cwd = '.'})") -map("n", "fg", "lua require('telescope.builtin').live_grep()") -map("n", "fb", "lua require('telescope.builtin').current_buffer_fuzzy_find()") -map("n", "fd", "lua require('telescope.builtin').diagnostics()") -map("n", "fp", "Telescope pickers") - --- find notes -map("n", "fn", [[lua require'plugins.telescope'.find_notes()]]) --- search notes -map("n", "fgn", [[lua require'plugins.telescope'.grep_notes()]]) --- Find files in config dirs -map("n", "f.", [[lua require'plugins.telescope'.find_configs()]]) ---map("n", "fz", ":FZF") ---map("t", [[]], [[]]) ---map("n", "ff", ":NvimTreeToggle", {}) -map("n", "f", ":NvimTreeToggle", {}) --- This avoids crashing fzf menu running in TERMINAL MODE (:q if you do) --- Find files in config dirs ---key_map("n", "e", ":lua require('plugins.telescope').find_configs()", opts) ---map("n", "f.", "lua require('plugins.telescope').find_configs({})") ---map("n", "ft", "lua require('plugins.telescope').file_explorer({})") ---map("n", "fd", "lua require('plugins.telescope').find_notes({})") -map("n", "fm", "lua require('telescope').extensions.media_files.media_files({})") --- registers picker -map("n", "r", "lua require('telescope.builtin').registers({})") --- find files including gitignored ---keymap( --- "n", --- "fg", --- "lua require('telescope.builtin').find_files({find_command={'fd','--no-ignore-vcs'}})") --- open available commands & run it ---map("n", "fc", "lua require('telescope.builtin').commands({results_title='Commands Results'})") - --------------- Autopairs -------------- -Toggle_autopairs = function() - local ok, autopairs = pcall(require, "nvim-autopairs") - if ok then - if autopairs.state.disabled then - autopairs.enable() - print("autopairs on") - else - autopairs.disable() - print("autopairs off") - end - else - print("autopairs not available") - end -end -map("n", "ww", ":lua Toggle_autopairs()", term_opts) - --------------- Functions -------------- -- Toggle transparency vim.cmd([[ let t:is_transparent = 0 @@ -464,9 +217,27 @@ vim.cmd([[ command! ZoomToggle call s:ZoomToggle() ]]) map("n", "z", ":ZoomToggle") --- "Zoom" a split window into a tab and/or close it ---keymap('n', ',', ':tabnew %') ---keymap('n', '.', ':tabclose') + +-- Toggle statusline +vim.cmd([[ +let s:hidden_all = 0 +function! ToggleHiddenAll() + if s:hidden_all == 0 + let s:hidden_all = 1 + set noshowmode + set noruler + set laststatus=0 + set noshowcmd + else + let s:hidden_all = 0 + set showmode + set ruler + set laststatus=2 + set showcmd + endif +endfunction +nnoremap :call ToggleHiddenAll() +]]) -- Open last closed buffer vim.cmd([[ @@ -492,6 +263,100 @@ vim.cmd([[ ]]) map("n", "", ":call OpenLastClosed() ") + +---------------- Plugin Operations ---------------- +-- Packer +map("n", "pc", "PackerCompile") +map("n", "pi", "PackerInstall") +map("n", "ps", "PackerSync") +map("n", "pS", "PackerStatus") +map("n", "pu", "PackerUpdate") + +-- Tmux navigation (aserowy/tmux.nvim) +map('n', '', 'NavigatorLeft') +map('n', '', 'NavigatorRight') +map('n', '', 'NavigatorUp') +map('n', '', 'NavigatorDown') + +-- ToggleTerm +--map("n", "tt", "ToggleTerm") + +-- LazyGit +map("n", "gg", ":LazyGit") + +-- Fugitive git bindings +map("n", "ga", ":Git add %:p") +--map("n", "gs", ":Gstatus") +map("n", "gc", ":Gcommit -v -q") +map("n", "gt", ":Gcommit -v -q %:p") +--map("n", "gd", ":Gdiff") +map("n", "ge", ":Gedit") +--map("n", "gr", ":Gread") +map("n", "gw", ":Gwrite") +map("n", "gl", ":silent! Glog:bot copen") +--map("n", "gp", ":Ggrep") +--map("n", "gp", ":Git push") +--map("n", "gb", ":Gblame") +map("n", "gm", ":Gmove") +--map("n", "gb", ":Git branch") +--map("n", "go", ":Git checkout") +--map("n", "gps", ":Dispatch! git push") +--map("n", "gpl", ":Dispatch! git pull") +-- map[""] = { "ToggleTerm", desc = "Toggle terminal" } +-- map["gg"] = { function() toggle_term_cmd "lazygit" end, desc = "ToggleTerm lazygit" } +-- map["tn"] = { function() toggle_term_cmd "node" end, desc = "ToggleTerm node" } +-- map["tu"] = { function() toggle_term_cmd "ncdu" end, desc = "ToggleTerm NCDU" } +-- map["tt"] = { function() toggle_term_cmd "htop" end, desc = "ToggleTerm htop" } +-- map["tp"] = { function() toggle_term_cmd "python" end, desc = "ToggleTerm python" } +-- map["tl"] = { function() toggle_term_cmd "lazygit" end, desc = "ToggleTerm lazygit" } +-- map["tf"] = { "ToggleTerm direction=float", desc = "ToggleTerm float" } +-- map["th"] = { "ToggleTerm size=10 direction=horizontal", desc = "ToggleTerm horizontal split" } +-- map["tv"] = { "ToggleTerm size=80 direction=vertical", desc = "ToggleTerm vertical split" } +--end + +-- Telescope +map("n", "ff", function() require("telescope.builtin").find_files { hidden = true, no_ignore = true } end) -- find all files +map("n", "fF", "lua require('telescope.builtin').find_files()") -- find files with hidden option +map("n", "fb", "lua require('telescope.builtin').current_buffer_fuzzy_find()") +map("n", "fc", "lua require('telescope.builtin').commands()") +map("n", "fg", "lua require('telescope.builtin').live_grep()") +map("n", "fp", "Telescope pickers") +map("n", "fr", "lua require('telescope.builtin').registers({})") -- registers picker +map("n", "cf", "Telescope changed_files") +map("n", "fd", "lua require('telescope.builtin').diagnostics()") +map("n", "fh", "lua require('telescope.builtin').help_tags()") +map("n", "fk", "lua require('telescope.builtin').keymaps()") +map("n", "fn", [[lua require'plugins.telescope'.find_notes()]]) -- find notes +map("n", "fgn", [[lua require'plugins.telescope'.grep_notes()]]) -- search notes +map("n", "f.", [[lua require'plugins.telescope'.find_configs()]]) -- find configs +map("n", "fm", "lua require('telescope').extensions.media_files.media_files({})") -- find media files + +-- FZF +map("n", "fz", "lua require('fzf-lua').files()") + +-- Nvim-tree +map("n", "f", ":NvimTreeToggle", {}) + +-- Markdown-preview +map("n", "md", "MarkdownPreviewToggle") + +-- Autopairs +Toggle_autopairs = function() + local ok, autopairs = pcall(require, "nvim-autopairs") + if ok then + if autopairs.state.disabled then + autopairs.enable() + print("autopairs on") + else + autopairs.disable() + print("autopairs off") + end + else + print("autopairs not available") + end +end +map("n", "ww", ":lua Toggle_autopairs()", term_opts) + -- Tabularize vim.cmd([[ vnoremap mm ':Tabularize /^\s*\S.*\zs' . split(&commentstring, '%s')[0] . "" @@ -500,6 +365,7 @@ vim.cmd([[ "vnoremap ii mc0f-20i`cdt=j ]]) +-- EasyAlign vim.cmd([[ " Start interactive EasyAlign in visual mode (e.g. vipga) xmap ga (EasyAlign) @@ -512,209 +378,3 @@ vim.cmd([[ nnoremap 21A d21\| imap a ]]) ---:'<,'>EasyAlign /--/ ---EasyAlign /--/ ---:'<,'>Tabularize /-- - ---map("n", ",", ":hide") ---map("n", ".", ":unhide") - ---" Clean trailing whitespace ---nnoremap ww mz:%s/\s\+$//:let @/=''`z - --- Save with root permission (not working for now) ---vim.api.nvim_create_user_command('W', 'w !sudo tee > /dev/null %', {}) - --- Copy and Paste with and ---keymap('n', ' p', (v:register =--= '"' && &clipboard =~ 'unnamed' ? '"*p' : '"' . v:register . 'p')'') --- Use command :Vb for Visual Block or since is used for Copy ---command! Vb normal! --- Map to save/edit a root permission/read-only file, only works in --- traditional vim and not neovim ---keymap('c', 'w!! %!sudo tee > /dev/null') ---" Copying text to the system clipboard. ---" ---" For some reason Vim no longer wants to talk to the OS X pasteboard through "*. ---" Computers are bullshit. ---function! g:FuckingCopyTheTextPlease() --- let old_z = @z --- normal! gv"zy --- call system('pbcopy', @z) --- let @z = old_z ---endfunction ---noremap p :silent! set paste"*p:set nopaste ---" noremap p mz:r!pbpaste`z ---vnoremap y :call g:FuckingCopyTheTextPlease() - ---" Indent/dedent/autoindent what you just pasted. ---nnoremap > V`]< ---nnoremap > V`]> ---nnoremap =- V`]= - ---" Keep the cursor in place while joining lines ---nnoremap J mzJ`z - ---" Toggle [i]nvisible characters ---nnoremap i :set list! --- ---" Unfuck my screen ---nnoremap U :syntax sync fromstart:redraw! - ---" Ranger ---nnoremap r :silent !ranger %:h:redraw! ---nnoremap R :silent !ranger:redraw! --- ---" Insert Mode Completion {{{ --- ---inoremap ---inoremap ---inoremap ----- Open the current file in the default program (on Mac this should just be just `open`) ---keymap('n', 'x', ':!xdg-open %') - -map("n", "fF", "lua require('telescope.builtin').find_files()") ---keymap("n", "ff", "lua require('telescope.builtin').find_files cwd=..()") ---keymap('n', 'k', ':nohlsearch') --- ---"This unsets the "last search pattern" register by hitting return -vim.cmd([[ - nnoremap :noh -]]) - ---keymap('n', 'Q', ':bufdo bdelete') --- ----- Allow gf to open non-existent files ---keymap('', 'gf', ':edit ') --- ----- Reselect visual selection after indenting ---keymap('v', '<', '', '>gv') --- ----- Maintain the cursor position when yanking a visual selection ----- http://ddrscott.github.io/blog/2016/yank-without-jank/ ---keymap('v', 'y', 'myy`y') ---keymap('v', 'Y', 'myY`y') ---keymap("n", "", ":q") ---keymap("n", "", ":qa!") - ---" Sort lines ---nnoremap s vip:!sort ---vnoremap s :!sort --- ---" Tabs ---nnoremap ( :tabprev ---nnoremap ) :tabnext --- ---" Wrap ---nnoremap W :set wrap! - ---set foldlevelstart=0 --- ---" Space to toggle folds. ---nnoremap za ---vnoremap za ---" Make zO recursively open whatever fold we're in, even if it's partially open. ---nnoremap zO zczO - --- Packer ---maps.n["pc"] = { "PackerCompile", desc = "Packer Compile" } ---maps.n["pi"] = { "PackerInstall", desc = "Packer Install" } ---maps.n["ps"] = { "PackerSync", desc = "Packer Sync" } ---maps.n["pS"] = { "PackerStatus", desc = "Packer Status" } ---maps.n["pu"] = { "PackerUpdate", desc = "Packer Update" } --- NeoTree ---if is_available "neo-tree.nvim" then --- keymaps.n["e"] = { "Neotree toggle", desc = "Toggle Explorer" } --- keymaps.n["o"] = { "Neotree focus", desc = "Focus Explorer" } ---end --- Alpha ---if is_available "alpha-nvim" then maps.n["d"] = { "Alpha", desc = "Alpha Dashboard" } end - --- Package Manager --- TODO: v2 rework these key bindings to be more general ---if is_available "mason.nvim" then maps.n["lI"] = { "Mason", desc = "LSP installer" } end --- Telescope ---if is_available "telescope.nvim" then --- maps.n["fw"] = { function() require("telescope.builtin").live_grep() end, desc = "Search words" } --- maps.n["fW"] = { --- function() --- require("telescope.builtin").live_grep { --- additional_args = function(args) return vim.list_extend(args, { "--hidden", "--no-ignore" }) end, --- } --- end, --- desc = "Search words in all files", --- } --- maps.n["gt"] = { function() require("telescope.builtin").git_status() end, desc = "Git status" } --- maps.n["gb"] = { function() require("telescope.builtin").git_branches() end, desc = "Git branches" } --- maps.n["gc"] = { function() require("telescope.builtin").git_commits() end, desc = "Git commits" } --- maps.n["ff"] = { function() require("telescope.builtin").find_files() end, desc = "Search files" } --- maps.n["fF"] = { --- function() require("telescope.builtin").find_files { hidden = true, no_ignore = true } end, --- desc = "Search all files", --- } --- maps.n["fb"] = { function() require("telescope.builtin").buffers() end, desc = "Search buffers" } --- maps.n["fh"] = { function() require("telescope.builtin").help_tags() end, desc = "Search help" } --- maps.n["fm"] = { function() require("telescope.builtin").marks() end, desc = "Search marks" } --- maps.n["fo"] = { function() require("telescope.builtin").oldfiles() end, desc = "Search history" } --- maps.n["fc"] = --- { function() require("telescope.builtin").grep_string() end, desc = "Search for word under cursor" } --- maps.n["sb"] = { function() require("telescope.builtin").git_branches() end, desc = "Git branches" } --- maps.n["sh"] = { function() require("telescope.builtin").help_tags() end, desc = "Search help" } --- maps.n["sm"] = { function() require("telescope.builtin").man_pages() end, desc = "Search man" } --- maps.n["sn"] = --- { function() require("telescope").extensions.notify.notify() end, desc = "Search notifications" } --- maps.n["sr"] = { function() require("telescope.builtin").registers() end, desc = "Search registers" } --- maps.n["sk"] = { function() require("telescope.builtin").keymaps() end, desc = "Search keymaps" } --- maps.n["sc"] = { function() require("telescope.builtin").commands() end, desc = "Search commands" } --- maps.n["ls"] = { --- function() --- local aerial_avail, _ = pcall(require, "aerial") --- if aerial_avail then --- require("telescope").extensions.aerial.aerial() --- else --- require("telescope.builtin").lsp_document_symbols() --- end --- end, --- desc = "Search symbols", --- } --- maps.n["lR"] = { function() require("telescope.builtin").lsp_references() end, desc = "Search references" } ---end --- ----- Terminal ---if is_available "toggleterm.nvim" then --- local toggle_term_cmd = astronvim.toggle_term_cmd ---" setup mapping to call :LazyGit ---map.gg :LazyGit --- maps.n[""] = { "ToggleTerm", desc = "Toggle terminal" } --- maps.n["gg"] = { function() toggle_term_cmd "lazygit" end, desc = "ToggleTerm lazygit" } --- maps.n["tn"] = { function() toggle_term_cmd "node" end, desc = "ToggleTerm node" } --- maps.n["tu"] = { function() toggle_term_cmd "ncdu" end, desc = "ToggleTerm NCDU" } --- maps.n["tt"] = { function() toggle_term_cmd "htop" end, desc = "ToggleTerm htop" } --- maps.n["tp"] = { function() toggle_term_cmd "python" end, desc = "ToggleTerm python" } --- maps.n["tl"] = { function() toggle_term_cmd "lazygit" end, desc = "ToggleTerm lazygit" } --- maps.n["tf"] = { "ToggleTerm direction=float", desc = "ToggleTerm float" } --- maps.n["th"] = { "ToggleTerm size=10 direction=horizontal", desc = "ToggleTerm horizontal split" } --- maps.n["tv"] = { "ToggleTerm size=80 direction=vertical", desc = "ToggleTerm vertical split" } ---end --- ----- Stay in indent mode ---maps.v["<"] = { ""] = { ">gv", desc = "indent line" } --- ----- Improved Terminal Mappings ---maps.t[""] = { "", desc = "Terminal normal mode" } ---maps.t["jk"] = { "", desc = "Terminal normal mode" } ---maps.t[""] = { "h", desc = "Terminal left window navigation" } ---maps.t[""] = { "j", desc = "Terminal down window navigation" } ---maps.t[""] = { "k", desc = "Terminal up window navigation" } ---maps.t[""] = { "l", desc = "Terminal right window naviation" } --- LSP Installer ---if is_available "mason-lspconfig.nvim" then maps.n["li"] = { "LspInfo", desc = "LSP information" } end - --- ALE: toggle _ALE activity ---keymap('n', 'a',[[:ALEToggle]]) - ---keymap('n', 'cd', ':call fzf#run({'source': 'fd -t d -H . ~', 'sink': 'cd'})') --- ":lua require('neogen').generate()") ---keymap("n", "ww", ":set wrap!") --- -- cgit v1.2.3