diff options
| author | srdusr <trevorgray@srdusr.com> | 2023-01-31 23:24:39 +0200 |
|---|---|---|
| committer | srdusr <trevorgray@srdusr.com> | 2023-01-31 23:24:39 +0200 |
| commit | 453d0831e4f07ccf16b4994c64a097ffc9b6fb76 (patch) | |
| tree | 6bcbdca540c5846fbf967d27ec439610ed08ee45 /.config/nvim/lua | |
| parent | b05c020b4b7ea6cd1ae81bbcabbf3d123ecba3ed (diff) | |
| parent | 42bee9e81f4051f19e528895f54a50ad14115785 (diff) | |
| download | dotfiles-453d0831e4f07ccf16b4994c64a097ffc9b6fb76.tar.gz dotfiles-453d0831e4f07ccf16b4994c64a097ffc9b6fb76.zip | |
Merge commit 'fad5c87245ecab533ffe6189937fc71c167bfba3'
Diffstat (limited to '.config/nvim/lua')
| -rw-r--r-- | .config/nvim/lua/plugins/lsp.lua | 308 | ||||
| -rw-r--r-- | .config/nvim/lua/plugins/toggleterm.lua | 2 | ||||
| -rw-r--r-- | .config/nvim/lua/user/keys.lua | 784 |
3 files changed, 226 insertions, 868 deletions
diff --git a/.config/nvim/lua/plugins/lsp.lua b/.config/nvim/lua/plugins/lsp.lua index 4c5cf70..900121f 100644 --- a/.config/nvim/lua/plugins/lsp.lua +++ b/.config/nvim/lua/plugins/lsp.lua @@ -71,31 +71,6 @@ function _G.toggle_diagnostics() end end ---map('n', '<Leader>m', ':call v:lua.toggle_diagnostics()<CR>') - ---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\<Esc>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", "<leader>i", ":call v:lua.toggle_diagnostics()<CR>") - - -- Set some key bindings conditional on server capabilities if client.server_capabilities.documentFormattingProvider then map("n", "<space>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! * <buffer> --- autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight() --- autocmd CursorHoldI <buffer> lua vim.lsp.buf.document_highlight() --- autocmd CursorMoved <buffer> 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 <buffer> lua vim.lsp.buf.document_highlight()') --- vim.cmd('autocmd CursorMoved <buffer> 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 <leader>a :autocmd! CursorHold,CursorHoldI <CR>]]) - ---vim.cmd [[ noremap <leader>a :autocmd! CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {focusable = false,})<CR>]] ---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 <CR>]]) --- --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", "<leader>a", toggle_diagnostics) - ---function LspDiagnosticsFocus() --- vim.api.nvim_command('set eventignore=WinLeave') --- vim.api.nvim_command('autocmd CursorMoved <buffer> ++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('', '<Leader>a', '<Cmd>lua LspDiagnosticsFocus()<CR>', {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", "<leader>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 <leader>o :call ToggleDiagnosticsOpenFloat()<CR>\|:echom "vim.diagnostic.open_float disabled . . ."<CR> +nnoremap <leader>to :call ToggleDiagnosticsOpenFloat()<CR>\|:echom "vim.diagnostic.open_float disabled . . ."<CR> ]]) ---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 <buffer> ++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('', '<Leader>a', '<Cmd>lua LspDiagnosticsFocus()<CR>', {silent = true}) - ---local diagnostics_active = true ---map('n', '<leader>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/.config/nvim/lua/plugins/toggleterm.lua b/.config/nvim/lua/plugins/toggleterm.lua index 912729a..0c3c45f 100644 --- a/.config/nvim/lua/plugins/toggleterm.lua +++ b/.config/nvim/lua/plugins/toggleterm.lua @@ -12,7 +12,7 @@ toggleterm.setup({ end end, --size = 20, - open_mapping = [[<leader>to]], + open_mapping = [[<leader>tt]], hide_numbers = true, shade_filetypes = {}, shade_terminals = false, diff --git a/.config/nvim/lua/user/keys.lua b/.config/nvim/lua/user/keys.lua index 712835a..f01a0c5 100644 --- a/.config/nvim/lua/user/keys.lua +++ b/.config/nvim/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", "<esc>") -map("n", "<leader>m", ":messages<CR>") -map("n", "<leader>cd", ":cd %:p:h<CR>:pwd<CR>") --- Print last error message or use these commands | v:errmsgv | :statusmsg | :h execute() | ---nnoremap <silent><leader>x :put =trim(execute(input(':', '', 'command')))<CR> --- Press <leader>x, then enter your command, such as 5mess and press <Enter>. 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<CR>", d("Save buffer")) - ---map("n", "<leader>so", ":luafile %<CR>") - ---vim.cmd([[ ---let $my_vimrc = $localappdata.'/nvim/init.lua' ---nnoremap <leader>so :source $my_vimrc<cr> ---]]) - --- Toggle between folds ---utils.map("n", "<F2>", "&foldlevel ? 'zM' : 'zR'", { expr = true }) - --- Move to the next and previous item in the quickfixlist ---utils.map("n", "]c", "<Cmd>cnext<CR>") ---utils.map("n", "[c", "<Cmd>cprevious<CR>") - --- Use space to toggle fold ---utils.map("n", "<Space>", "za") - --- Hitting ESC when inside a terminal to get into normal mode ---utils.map("t", "<Esc>", [[<C-\><C-N>]]) - --- select last change ---nnoremap gV `[v`] - ---map("n", "<esc>", function() --- notify.dismiss() --- vim.cmd.noh() ---end) - ---"nnore fast [e]dit and [s]ourcing .[v]imrc ---nnoremap <leader>ev :edit $MYVIMRC<CR> ---"fast macro ---nnoremap @ <cmd>set lazyredraw <bar> execute 'noautocmd norm! ' . v:count1 . '@' . getcharstr() <bar> set nolazyredraw<cr> ---xnoremap @ :<C-U>set lazyredraw <bar> execute "noautocmd '<,'>norm! " . v:count1 . "@" . getcharstr()<bar> set nolazyredraw<cr> - ---map("n", "<leader><CR>", ":runtime! /lua/plugins/*.lua<CR> | :runtime! /lua/user/*.lua<CR> | :luafile ~/.config/nvim/init.lua<CR>", print ("Nvim reloaded")) ---map("n", "<leader><CR>", ":lua require('init').unload_lua_namespace()<CR>", print ("Nvim reloaded")) ---map("n", "<leader><CR>", "<cmd>luafile ~/.config/nvim/init.lua<CR>", vim.notify("Nvim configuration reloaded!", vim.log.levels.INFO)) ---map("n", "<leader><CR>", "<cmd>luafile ~/.config/nvim/init.lua<CR> | :lua require("notify")("completion off")") ---map("n", "<leader><CR>", "<cmd>luafile ~/.config/nvim/init.lua<CR>", vim.api.nvim_echo({{'first chunk and ', 'None'}, {'second chunk to echo', 'None'}}, false, {})) ---map("n", "<leader><CR>", "<cmd>luafile ~/.config/nvim/init.lua<CR>", print ("Nvim config loading...")) ---map("n", "<leader><CR>", "<cmd>luafile ~/.config/nvim/init.lua<CR> | :echo ('hello') | <C-l><CR>") +-- Reload nvim config map("n", "<leader><CR>", "<cmd>luafile ~/.config/nvim/init.lua<CR> | :echom ('Nvim config loading...') | :sl! | echo ('')<CR>") -map("n", "<leader>u", ":echo '' | redraw<CR>") --clear messages ---map("n", "<leader><CR>", "<cmd>luafile ~/.config/nvim/init.lua<CR>") ---vim.api.nvim_set_keymap("n", "<leader><CR>", "<cmd>lua ReloadConfig()<CR>", { noremap = true, silent = false }) - -map("n", "<Leader>tc", ":lua require('user.utils').toggle_completion()<CR>") --- vim.notify("Nvim configuration reloaded!", vim.log.levels.INFO) - ---vim.api.nvim_set_keymap('n', '<Leader>qr', '<cmd>:lua require("plugins.telescope").reload()<CR>', { noremap = true, silent = true }) - ----- Terminal ---if is_available "toggleterm.nvim" then --- local toggle_term_cmd = astronvim.toggle_term_cmd -map("n", "<leader>gg", ":LazyGit<CR>") -map("n", "<leader>tt", "<cmd>ToggleTerm<cr>") - ----- Fugitive git bindings -map("n", "<leader>ga", ":Git add %:p<CR><CR>") ---map("n", "<leader>gs", ":Gstatus<CR>") -map("n", "<leader>gc", ":Gcommit -v -q<CR>") -map("n", "<leader>gt", ":Gcommit -v -q %:p<CR>") ---map("n", "<leader>gd", ":Gdiff<CR>") -map("n", "<leader>ge", ":Gedit<CR>") ---map("n", "<leader>gr", ":Gread<Cj>") -map("n", "<leader>gw", ":Gwrite<CR><CR>") -map("n", "<leader>gl", ":silent! Glog<CR>:bot copen<CR>") ---map("n", "<leader>gp", ":Ggrep<Space>") ---map("n", "<Leader>gp", ":Git push<CR>") ---map("n", "<Leader>gb", ":Gblame<CR>") -map("n", "<leader>gm", ":Gmove<Space>") ---map("n", "<leader>gb", ":Git branch<Space>") ---map("n", "<leader>go", ":Git checkout<Space>") ---map("n", "<leader>gps", ":Dispatch! git push<CR>") ---map("n", "<leader>gpl", ":Dispatch! git pull<CR>") - --- maps.n["<C-\\>"] = { "<cmd>ToggleTerm<cr>", desc = "Toggle terminal" } --- maps.n["<leader>gg"] = { function() toggle_term_cmd "lazygit" end, desc = "ToggleTerm lazygit" } --- maps.n["<leader>tn"] = { function() toggle_term_cmd "node" end, desc = "ToggleTerm node" } --- maps.n["<leader>tu"] = { function() toggle_term_cmd "ncdu" end, desc = "ToggleTerm NCDU" } --- maps.n["<leader>tt"] = { function() toggle_term_cmd "htop" end, desc = "ToggleTerm htop" } --- maps.n["<leader>tp"] = { function() toggle_term_cmd "python" end, desc = "ToggleTerm python" } --- maps.n["<leader>tl"] = { function() toggle_term_cmd "lazygit" end, desc = "ToggleTerm lazygit" } --- maps.n["<leader>tf"] = { "<cmd>ToggleTerm direction=float<cr>", desc = "ToggleTerm float" } --- maps.n["<leader>th"] = { "<cmd>ToggleTerm size=10 direction=horizontal<cr>", desc = "ToggleTerm horizontal split" } --- maps.n["<leader>tv"] = { "<cmd>ToggleTerm size=80 direction=vertical<cr>", desc = "ToggleTerm vertical split" } ---end --- ---Easier split navigations, just ctrl-j instead of ctrl-w then j ---map("n", "<C-J>", "<C-W><C-J>") ---map("n", "<C-K>", "<C-W><C-K>") ---map("n", "<C-L>", "<C-W><C-L>") ---map("n", "<C-H>", "<C-W><C-H>") - --- Tmux navigation (aserowy/tmux.nvim) ---map("n", "<C-h>", ":lua require'tmux'.move_left()<cr>") ---map("n", "<C-j>", ":lua require'tmux'.move_bottom()<cr>") ---map("n", "<C-k>", ":lua require'tmux'.move_top()<cr>") ---map("n", "<C-l>", ":lua require'tmux'.move_right()<cr>") -map('n', '<C-h>', '<CMD>NavigatorLeft<CR>') -map('n', '<C-l>', '<CMD>NavigatorRight<CR>') -map('n', '<C-k>', '<CMD>NavigatorUp<CR>') -map('n', '<C-j>', '<CMD>NavigatorDown<CR>') - --- set line wrap -map("n", "<M-z>", 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", "<Leader>b", ":buffers<CR>:buffer<Space>") ---map("n", "<leader>b", ":ls<cr>:b<space>") --- Map buffer next, prev and delete to <leader+(n/p/d)> +-- Buffer confirmation +map("n", "<leader>y", ":BufferPick<CR>") + +-- Map buffer next, prev and delete to <leader>+(n/p/d) respectively map("n", "<leader>n", ":bn<cr>") map("n", "<leader>p", ":bp<cr>") map("n", "<leader>d", ":bd<cr>") --- Disable default completion. -map('i', '<C-n>', '<Nop>') -map('i', '<C-p>', '<Nop>') - --- Set alt + j/k to switch lines of texts or simply move them -map("n", "<A-k>", ':let save_a=@a<Cr><Up>"add"ap<Up>:let @a=save_a<Cr>') -map("n", "<A-j>", ':let save_a=@a<Cr>"add"ap:let @a=save_a<Cr>') +-- List marks +map("n", "<Leader>m", ":marks<CR>") -map("i", "<C-l>", "<Del>") - -map("n", "<leader><C-l>", "<Cmd>!clear<CR>") - -map("n", "<leader>y", ":BufferPick<CR>") - -vim.cmd([[ - inoremap <A-h> <left> - inoremap <A-j> <down> - inoremap <A-k> <up> - inoremap <A-l> <right> -]]) - -vim.cmd([[ - cnoremap <A-h> <left> - cnoremap <A-j> <down> - cnoremap <A-k> <up> - cnoremap <A-l> <right> -]]) - ---vim.cmd([[ --- cnoremap <C-A> <Home> --- cnoremap <C-F> <Right> --- cnoremap <C-B> <Left> --- cnoremap <C-E> <End> ---]]) +-- Toggle set number +map("n", "<leader>$", ":NumbersToggle<CR>") +map("n", "<leader>%", ":NumbersOnOff<CR>") -vim.cmd([[ - snoremap <A-h> <left> - snoremap <A-j> <down> - snoremap <A-k> <up> - snoremap <A-l> <right> -]]) +-- Easier split navigations, just ctrl-j instead of ctrl-w then j +--map("n", "<C-J>", "<C-W><C-J>") +--map("n", "<C-K>", "<C-W><C-K>") +--map("n", "<C-L>", "<C-W><C-L>") +--map("n", "<C-H>", "<C-W><C-H>") --- move block easily -map("n", "<", "<<", term_opts) -map("n", ">", ">>", term_opts) -map("x", "<", "<gv", term_opts) -map("x", ">", ">gv", term_opts) +-- Split window +map("n", "<leader>h", ":split<CR>") +map("n", "<leader>v", ":vsplit<CR>") +map("n", "<leader>c", "<C-w>c") -- Resize Panes map("n", "<Leader>+", ":resize +5<CR>") @@ -226,13 +66,33 @@ map("n", "<Leader><", ":vertical resize +5<CR>") map("n", "<Leader>>", ":vertical resize -5<CR>") map("n", "<Leader>=", "<C-w>=") --- New tab +-- Map Alt+(h/j/k/l) in insert mode to move directional +map("i", "<A-h>", "<left>") +map("i", "<A-j>", "<down>") +map("i", "<A-k>", "<up>") +map("i", "<A-l>", "<right>") + +-- Map Alt+(h/j/k/l) in command mode to move directional +map("c", "<A-h>", "<left>") +map("c", "<A-j>", "<down>") +map("c", "<A-k>", "<up>") +map("c", "<A-l>", "<right>") + +-- Map Alt+(h/j/k/l) in selection mode to move directional +map("s", "<A-h>", "<left>") +map("s", "<A-j>", "<down>") +map("s", "<A-k>", "<up>") +map("s", "<A-l>", "<right>") + +-- Create tab, edit and move between them +map("n", "<C-T>n", ":tabnew<CR>") map("n", "<C-T>e", ":tabedit") +map("n", "<leader>[", ":tabprev<CR>") +map("n", "<leader>]", ":tabnext<CR>") --- create tab like window -map("n", "<C-T>h", ":tabprevious<CR>") -map("n", "<C-T>l", ":tabnext<CR>") -map("n", "<C-T>n", ":tabnew<CR>") +-- "Zoom" a split window into a tab and/or close it +--map("n", "<Leader>,", ":tabnew %<CR>") +--map("n", "<Leader>.", ":tabclose<CR>") -- Vim TABs map("n", "<leader>1", "1gt<CR>") @@ -246,192 +106,85 @@ map("n", "<leader>8", "8gt<CR>") map("n", "<leader>9", "9gt<CR>") map("n", "<leader>0", "10gt<CR>") --- Split window -map("n", "<leader>h", ":split<CR>") -map("n", "<leader>v", ":vsplit<CR>") -map("n", "<leader>c", "<C-w>c") +-- Move to the next and previous item in the quickfixlist +--map("n", "]c", "<Cmd>cnext<CR>") +--map("n", "[c", "<Cmd>cprevious<CR>") --- Toggle set number -map("n", "<leader>$", ":NumbersToggle<CR>") -map("n", "<leader>%", ":NumbersOnOff<CR>") +-- Hitting ESC when inside a terminal to get into normal mode +--map("t", "<Esc>", [[<C-\><C-N>]]) --- Change mode to executable -map("n", "<leader>x", ":!chmod +x %<CR>") +-- Move block (indentation) easily +map("n", "<", "<<", term_opts) +map("n", ">", ">>", term_opts) +map("x", "<", "<gv", 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", "<A-k>", ':let save_a=@a<Cr><Up>"add"ap<Up>:let @a=save_a<Cr>') +map("n", "<A-j>", ':let save_a=@a<Cr>"add"ap:let @a=save_a<Cr>') --- Paste end of line ---map("n", ",", "$p") ---vim.cmd([[ --- nmap , $p ---]]) +-- Search and replace +map("v", "<leader>sr", 'y:%s/<C-r><C-r>"//g<Left><Left>c') --- Select entire buffer ---map("v", "<aa>", "gg<S-v>G") +-- Map delete to Ctrl+l +map("i", "<C-l>", "<Del>") --- Delete without changing the registers ---map('n', 'x', '"_x') +-- Clear screen +map("n", "<leader><C-l>", "<Cmd>!clear<CR>") --- Select all text in current buffer ---map('n', '<leader>a', ':keepjumps normal! ggVG<cr>') +-- Change file to an executable +map("n", "<leader>x", ":!chmod +x %<CR>") + +-- 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", "<C-X>", "<Esc>`.``gvP``P") --- Keep Visual mode selection when indenting text ---utils.map("x", ">", ">gv") ---utils.map("x", "<", "<gv") +-- Clear messages or just refresh/redraw the screen +map("n", "<leader>u", ":echo '' | redraw<CR>") --- 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", "<leader>cd", ":cd %:p:h<CR>:pwd<CR>") --- Whole-word search ---utils.map("n", "<leader>/", ":/\\<\\><Left><Left>", { silent = false }) +-- Open the current file in the default program (on Mac this should just be just `open`) +map('n', '<leader>o', ':!xdg-open %<cr><cr>') --- EasyAlign keybindings --- 'vipga' starts interactive EasyAlign in visual mode --- 'gaip' starts interactive EasyAlign for text/motion object ---utils.map({ "n", "x" }, "ga", "<Plug>(EasyAlign)") ---utils.map({ "n", "x" }, "<leader>ga", "<Plug>(LiveEasyAlign)") +-- Unsets the 'last search pattern' register by hitting return +map("n", "<CR>", "!silent :noh<CR><CR>") --- 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", "<Leader>tc", ":lua require('user.utils').toggle_completion()<CR>") --- Zoom toggle a buffer in a new tab ---utils.map("n", "<leader>z", function() --- require("tt.helper").zoomToggleNewTab() ---end, { desc = "Zoom toggle a buffer in a new tab" }) +-- Disable default completion. +map('i', '<C-n>', '<Nop>') +map('i', '<C-p>', '<Nop>') --- Hitting ESC when inside a terminal to get into normal mode ---utils.map("t", "<Esc>", [[<C-\><C-N>]]) +-- Set line wrap +map("n", "<M-z>", function() + local wrap_status = vim.api.nvim_exec("set wrap ?", true) --- markdown-preview -map("n", "<leader>md", "<Plug>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", "<F2>", "&foldlevel ? 'zM' : 'zR'", { expr = true }) --- Search and replace -map("v", "<leader>sr", 'y:%s/<C-r><C-r>"//g<Left><Left>c') ---vnoremap ; :call Get_visual_selection()<cr> --- ---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 <S-h> :call ToggleHiddenAll()<CR> -]]) +-- Use space to toggle fold +--utils.map("n", "<Space>", "za") +-- Make a copy of current file vim.cmd([[ map <leader>s :up \| saveas! %:p:r-<C-R>=strftime("%y.%m.%d-%H:%M")<CR>-bak.<C-R>=expand("%:e")<CR> \| 3sleep \| e #<CR> ]]) --- Execute this file ---map("n", "<leader><leader>x", ":call scripts#save_and_exec()<CR>", print("save & exec")) -vim.cmd([[ - " Execute this file - nnoremap <leader><leader>x :call scripts#save_and_exec()<CR>\|:echom "save & exec . . ."<CR> - -]]) - --------------- FZF -------------- -map("n", "<leader>fz", "<cmd>lua require('fzf-lua').files()<CR>") - --------------- Telescope -------------- ---Telescope find_files cwd=.. -map("n", "<leader>fc", "<cmd>lua require('telescope.builtin').commands()<cr>") -map("n", "<leader>cf", "<cmd>Telescope changed_files<cr>") -map("n", "<leader>fk", "<cmd>lua require('telescope.builtin').keymaps()<cr>") -map("n", "<leader>fh", "<cmd>lua require('telescope.builtin').help_tags()<cr>") ---map( --- "n", --- "<leader>ft", --- "<cmd>lua require('telescope.builtin').builtin(require('telescope.themes').get_dropdown({}))<cr>") - --- maps.n["<leader>fF"] = { --- function() require("telescope.builtin").find_files { hidden = true, no_ignore = true } end, --- desc = "Search all files", --- <cmd>Telescope find_files hidden=true<cr> ---map("n", "<leader>fh", "<cme>lua require('telecsope.builtin').file_files hidden=true<cr>") -map("n", "<leader>ff", function() require("telescope.builtin").find_files { hidden = true, no_ignore = true } end) ---map("n", "<leader>fe", ":lua require('telescope.builtin').file_browser({cwd = '.'})<CR>") -map("n", "<leader>fg", "<cmd>lua require('telescope.builtin').live_grep()<cr>") -map("n", "<leader>fb", "<cmd>lua require('telescope.builtin').current_buffer_fuzzy_find()<cr>") -map("n", "<leader>fd", "<cmd>lua require('telescope.builtin').diagnostics()<cr>") -map("n", "<leader>fp", "<cmd>Telescope pickers<cr>") - --- find notes -map("n", "<leader>fn", [[<Cmd>lua require'plugins.telescope'.find_notes()<CR>]]) --- search notes -map("n", "<leader>fgn", [[<Cmd>lua require'plugins.telescope'.grep_notes()<CR>]]) --- Find files in config dirs -map("n", "<leader>f.", [[<Cmd>lua require'plugins.telescope'.find_configs()<CR>]]) ---map("n", "<leader>fz", ":FZF<CR>") ---map("t", [[<Esc><Esc>]], [[<C-\><C-N>]]) ---map("n", "ff", ":NvimTreeToggle<CR>", {}) -map("n", "<leader>f", ":NvimTreeToggle<CR>", {}) --- This <Esc><Esc> avoids crashing fzf menu running in TERMINAL MODE (:q if you do) --- Find files in config dirs ---key_map("n", "<leader>e", ":lua require('plugins.telescope').find_configs()<CR>", opts) ---map("n", "<leader>f.", "<cmd>lua require('plugins.telescope').find_configs({})<cr>") ---map("n", "<leader>ft", "<cmd>lua require('plugins.telescope').file_explorer({})<cr>") ---map("n", "<leader>fd", "<cmd>lua require('plugins.telescope').find_notes({})<cr>") -map("n", "<leader>fm", "<cmd>lua require('telescope').extensions.media_files.media_files({})<cr>") --- registers picker -map("n", "<leader>r", "<cmd>lua require('telescope.builtin').registers({})<CR>") --- find files including gitignored ---keymap( --- "n", --- "<leader>fg", --- "<cmd>lua require('telescope.builtin').find_files({find_command={'fd','--no-ignore-vcs'}})<CR>") --- open available commands & run it ---map("n", "<leader>fc", "<cmd>lua require('telescope.builtin').commands({results_title='Commands Results'})<CR>") - --------------- 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", "<leader>ww", ":lua Toggle_autopairs()<CR>", 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", "<leader>z", ":ZoomToggle<CR>") --- "Zoom" a split window into a tab and/or close it ---keymap('n', '<Leader>,', ':tabnew %<CR>') ---keymap('n', '<Leader>.', ':tabclose<CR>') + +-- 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 <S-h> :call ToggleHiddenAll()<CR> +]]) -- Open last closed buffer vim.cmd([[ @@ -492,6 +263,100 @@ vim.cmd([[ ]]) map("n", "<C-t>", ":call OpenLastClosed() <CR>") + +---------------- Plugin Operations ---------------- +-- Packer +map("n", "<leader>pc", "<cmd>PackerCompile<cr>") +map("n", "<leader>pi", "<cmd>PackerInstall<cr>") +map("n", "<leader>ps", "<cmd>PackerSync<cr>") +map("n", "<leader>pS", "<cmd>PackerStatus<cr>") +map("n", "<leader>pu", "<cmd>PackerUpdate<cr>") + +-- Tmux navigation (aserowy/tmux.nvim) +map('n', '<C-h>', '<CMD>NavigatorLeft<CR>') +map('n', '<C-l>', '<CMD>NavigatorRight<CR>') +map('n', '<C-k>', '<CMD>NavigatorUp<CR>') +map('n', '<C-j>', '<CMD>NavigatorDown<CR>') + +-- ToggleTerm +--map("n", "<leader>tt", "<cmd>ToggleTerm<cr>") + +-- LazyGit +map("n", "<leader>gg", ":LazyGit<CR>") + +-- Fugitive git bindings +map("n", "<leader>ga", ":Git add %:p<CR><CR>") +--map("n", "<leader>gs", ":Gstatus<CR>") +map("n", "<leader>gc", ":Gcommit -v -q<CR>") +map("n", "<leader>gt", ":Gcommit -v -q %:p<CR>") +--map("n", "<leader>gd", ":Gdiff<CR>") +map("n", "<leader>ge", ":Gedit<CR>") +--map("n", "<leader>gr", ":Gread<Cj>") +map("n", "<leader>gw", ":Gwrite<CR><CR>") +map("n", "<leader>gl", ":silent! Glog<CR>:bot copen<CR>") +--map("n", "<leader>gp", ":Ggrep<Space>") +--map("n", "<Leader>gp", ":Git push<CR>") +--map("n", "<Leader>gb", ":Gblame<CR>") +map("n", "<leader>gm", ":Gmove<Space>") +--map("n", "<leader>gb", ":Git branch<Space>") +--map("n", "<leader>go", ":Git checkout<Space>") +--map("n", "<leader>gps", ":Dispatch! git push<CR>") +--map("n", "<leader>gpl", ":Dispatch! git pull<CR>") +-- map["<C-\\>"] = { "<cmd>ToggleTerm<cr>", desc = "Toggle terminal" } +-- map["<leader>gg"] = { function() toggle_term_cmd "lazygit" end, desc = "ToggleTerm lazygit" } +-- map["<leader>tn"] = { function() toggle_term_cmd "node" end, desc = "ToggleTerm node" } +-- map["<leader>tu"] = { function() toggle_term_cmd "ncdu" end, desc = "ToggleTerm NCDU" } +-- map["<leader>tt"] = { function() toggle_term_cmd "htop" end, desc = "ToggleTerm htop" } +-- map["<leader>tp"] = { function() toggle_term_cmd "python" end, desc = "ToggleTerm python" } +-- map["<leader>tl"] = { function() toggle_term_cmd "lazygit" end, desc = "ToggleTerm lazygit" } +-- map["<leader>tf"] = { "<cmd>ToggleTerm direction=float<cr>", desc = "ToggleTerm float" } +-- map["<leader>th"] = { "<cmd>ToggleTerm size=10 direction=horizontal<cr>", desc = "ToggleTerm horizontal split" } +-- map["<leader>tv"] = { "<cmd>ToggleTerm size=80 direction=vertical<cr>", desc = "ToggleTerm vertical split" } +--end + +-- Telescope +map("n", "<leader>ff", function() require("telescope.builtin").find_files { hidden = true, no_ignore = true } end) -- find all files +map("n", "<leader>fF", "<cmd>lua require('telescope.builtin').find_files()<cr>") -- find files with hidden option +map("n", "<leader>fb", "<cmd>lua require('telescope.builtin').current_buffer_fuzzy_find()<cr>") +map("n", "<leader>fc", "<cmd>lua require('telescope.builtin').commands()<cr>") +map("n", "<leader>fg", "<cmd>lua require('telescope.builtin').live_grep()<cr>") +map("n", "<leader>fp", "<cmd>Telescope pickers<cr>") +map("n", "<leader>fr", "<cmd>lua require('telescope.builtin').registers({})<CR>") -- registers picker +map("n", "<leader>cf", "<cmd>Telescope changed_files<cr>") +map("n", "<leader>fd", "<cmd>lua require('telescope.builtin').diagnostics()<cr>") +map("n", "<leader>fh", "<cmd>lua require('telescope.builtin').help_tags()<cr>") +map("n", "<leader>fk", "<cmd>lua require('telescope.builtin').keymaps()<cr>") +map("n", "<leader>fn", [[<Cmd>lua require'plugins.telescope'.find_notes()<CR>]]) -- find notes +map("n", "<leader>fgn", [[<Cmd>lua require'plugins.telescope'.grep_notes()<CR>]]) -- search notes +map("n", "<leader>f.", [[<Cmd>lua require'plugins.telescope'.find_configs()<CR>]]) -- find configs +map("n", "<leader>fm", "<cmd>lua require('telescope').extensions.media_files.media_files({})<cr>") -- find media files + +-- FZF +map("n", "<leader>fz", "<cmd>lua require('fzf-lua').files()<CR>") + +-- Nvim-tree +map("n", "<leader>f", ":NvimTreeToggle<CR>", {}) + +-- Markdown-preview +map("n", "<leader>md", "<Plug>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", "<leader>ww", ":lua Toggle_autopairs()<CR>", term_opts) + -- Tabularize vim.cmd([[ vnoremap <expr> <Leader>mm ':Tabularize /^\s*\S.*\zs' . split(&commentstring, '%s')[0] . "<CR>" @@ -500,6 +365,7 @@ vim.cmd([[ "vnoremap <leader>ii mc0f-20i<Space><Esc>`cdt=j ]]) +-- EasyAlign vim.cmd([[ " Start interactive EasyAlign in visual mode (e.g. vipga) xmap ga <Plug>(EasyAlign) @@ -512,209 +378,3 @@ vim.cmd([[ nnoremap <F1> 21A <Esc>d21\| imap <F1> <Esc><F1>a ]]) ---:'<,'>EasyAlign /--/ ---EasyAlign /--/ ---:'<,'>Tabularize /-- - ---map("n", "<leader>,", ":hide<CR>") ---map("n", "<leader>.", ":unhide<CR>") - ---" Clean trailing whitespace ---nnoremap <leader>ww mz:%s/\s\+$//<cr>:let @/=''<cr>`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 <C-c> and <C-v> ---keymap('n', '<expr> p', (v:register =--= '"' && &clipboard =~ 'unnamed' ? '"*p' : '"' . v:register . 'p')'') --- Use command :Vb for Visual Block or <C-q> since <C-v> is used for Copy ---command! Vb normal! <C-v> --- Map <w!!> 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 <leader>p :silent! set paste<CR>"*p:set nopaste<CR> ---" noremap <leader>p mz:r!pbpaste<cr>`z ---vnoremap <leader>y :<c-u>call g:FuckingCopyTheTextPlease()<cr> - ---" Indent/dedent/autoindent what you just pasted. ---nnoremap <lt>> V`]< ---nnoremap ><lt> V`]> ---nnoremap =- V`]= - ---" Keep the cursor in place while joining lines ---nnoremap J mzJ`z - ---" Toggle [i]nvisible characters ---nnoremap <leader>i :set list!<cr> --- ---" Unfuck my screen ---nnoremap U :syntax sync fromstart<cr>:redraw!<cr> - ---" Ranger ---nnoremap <leader>r :silent !ranger %:h<cr>:redraw!<cr> ---nnoremap <leader>R :silent !ranger<cr>:redraw!<cr> --- ---" Insert Mode Completion {{{ --- ---inoremap <c-f> <c-x><c-f> ---inoremap <c-]> <c-x><c-]> ---inoremap <c-l> <c-x><c-l> ----- Open the current file in the default program (on Mac this should just be just `open`) ---keymap('n', '<leader>x', ':!xdg-open %<cr><cr>') - -map("n", "<leader>fF", "<cmd>lua require('telescope.builtin').find_files()<cr>") ---keymap("n", "<leader>ff", "<cmd>lua require('telescope.builtin').find_files cwd=..()<cr>") ---keymap('n', '<leader>k', ':nohlsearch<CR>') --- ---"This unsets the "last search pattern" register by hitting return -vim.cmd([[ - nnoremap <silent> <CR> :noh<CR><CR> -]]) - ---keymap('n', '<leader>Q', ':bufdo bdelete<CR>') --- ----- Allow gf to open non-existent files ---keymap('', 'gf', ':edit <cfile><CR>') --- ----- Reselect visual selection after indenting ---keymap('v', '<', '<gv') ---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", "<C-q>", ":q<cr>") ---keymap("n", "<C-M-q>", ":qa!<cr>") - ---" Sort lines ---nnoremap <leader>s vip:!sort<cr> ---vnoremap <leader>s :!sort<cr> --- ---" Tabs ---nnoremap <leader>( :tabprev<cr> ---nnoremap <leader>) :tabnext<cr> --- ---" Wrap ---nnoremap <leader>W :set wrap!<cr> - ---set foldlevelstart=0 --- ---" Space to toggle folds. ---nnoremap <Space> za ---vnoremap <Space> za ---" Make zO recursively open whatever fold we're in, even if it's partially open. ---nnoremap zO zczO - --- Packer ---maps.n["<leader>pc"] = { "<cmd>PackerCompile<cr>", desc = "Packer Compile" } ---maps.n["<leader>pi"] = { "<cmd>PackerInstall<cr>", desc = "Packer Install" } ---maps.n["<leader>ps"] = { "<cmd>PackerSync<cr>", desc = "Packer Sync" } ---maps.n["<leader>pS"] = { "<cmd>PackerStatus<cr>", desc = "Packer Status" } ---maps.n["<leader>pu"] = { "<cmd>PackerUpdate<cr>", desc = "Packer Update" } --- NeoTree ---if is_available "neo-tree.nvim" then --- keymaps.n["<leader>e"] = { "<cmd>Neotree toggle<cr>", desc = "Toggle Explorer" } --- keymaps.n["<leader>o"] = { "<cmd>Neotree focus<cr>", desc = "Focus Explorer" } ---end --- Alpha ---if is_available "alpha-nvim" then maps.n["<leader>d"] = { "<cmd>Alpha<cr>", desc = "Alpha Dashboard" } end - --- Package Manager --- TODO: v2 rework these key bindings to be more general ---if is_available "mason.nvim" then maps.n["<leader>lI"] = { "<cmd>Mason<cr>", desc = "LSP installer" } end --- Telescope ---if is_available "telescope.nvim" then --- maps.n["<leader>fw"] = { function() require("telescope.builtin").live_grep() end, desc = "Search words" } --- maps.n["<leader>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["<leader>gt"] = { function() require("telescope.builtin").git_status() end, desc = "Git status" } --- maps.n["<leader>gb"] = { function() require("telescope.builtin").git_branches() end, desc = "Git branches" } --- maps.n["<leader>gc"] = { function() require("telescope.builtin").git_commits() end, desc = "Git commits" } --- maps.n["<leader>ff"] = { function() require("telescope.builtin").find_files() end, desc = "Search files" } --- maps.n["<leader>fF"] = { --- function() require("telescope.builtin").find_files { hidden = true, no_ignore = true } end, --- desc = "Search all files", --- } --- maps.n["<leader>fb"] = { function() require("telescope.builtin").buffers() end, desc = "Search buffers" } --- maps.n["<leader>fh"] = { function() require("telescope.builtin").help_tags() end, desc = "Search help" } --- maps.n["<leader>fm"] = { function() require("telescope.builtin").marks() end, desc = "Search marks" } --- maps.n["<leader>fo"] = { function() require("telescope.builtin").oldfiles() end, desc = "Search history" } --- maps.n["<leader>fc"] = --- { function() require("telescope.builtin").grep_string() end, desc = "Search for word under cursor" } --- maps.n["<leader>sb"] = { function() require("telescope.builtin").git_branches() end, desc = "Git branches" } --- maps.n["<leader>sh"] = { function() require("telescope.builtin").help_tags() end, desc = "Search help" } --- maps.n["<leader>sm"] = { function() require("telescope.builtin").man_pages() end, desc = "Search man" } --- maps.n["<leader>sn"] = --- { function() require("telescope").extensions.notify.notify() end, desc = "Search notifications" } --- maps.n["<leader>sr"] = { function() require("telescope.builtin").registers() end, desc = "Search registers" } --- maps.n["<leader>sk"] = { function() require("telescope.builtin").keymaps() end, desc = "Search keymaps" } --- maps.n["<leader>sc"] = { function() require("telescope.builtin").commands() end, desc = "Search commands" } --- maps.n["<leader>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["<leader>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.<leader>gg :LazyGit<CR> --- maps.n["<C-\\>"] = { "<cmd>ToggleTerm<cr>", desc = "Toggle terminal" } --- maps.n["<leader>gg"] = { function() toggle_term_cmd "lazygit" end, desc = "ToggleTerm lazygit" } --- maps.n["<leader>tn"] = { function() toggle_term_cmd "node" end, desc = "ToggleTerm node" } --- maps.n["<leader>tu"] = { function() toggle_term_cmd "ncdu" end, desc = "ToggleTerm NCDU" } --- maps.n["<leader>tt"] = { function() toggle_term_cmd "htop" end, desc = "ToggleTerm htop" } --- maps.n["<leader>tp"] = { function() toggle_term_cmd "python" end, desc = "ToggleTerm python" } --- maps.n["<leader>tl"] = { function() toggle_term_cmd "lazygit" end, desc = "ToggleTerm lazygit" } --- maps.n["<leader>tf"] = { "<cmd>ToggleTerm direction=float<cr>", desc = "ToggleTerm float" } --- maps.n["<leader>th"] = { "<cmd>ToggleTerm size=10 direction=horizontal<cr>", desc = "ToggleTerm horizontal split" } --- maps.n["<leader>tv"] = { "<cmd>ToggleTerm size=80 direction=vertical<cr>", desc = "ToggleTerm vertical split" } ---end --- ----- Stay in indent mode ---maps.v["<"] = { "<gv", desc = "unindent line" } ---maps.v[">"] = { ">gv", desc = "indent line" } --- ----- Improved Terminal Mappings ---maps.t["<esc>"] = { "<C-\\><C-n>", desc = "Terminal normal mode" } ---maps.t["jk"] = { "<C-\\><C-n>", desc = "Terminal normal mode" } ---maps.t["<C-h>"] = { "<c-\\><c-n><c-w>h", desc = "Terminal left window navigation" } ---maps.t["<C-j>"] = { "<c-\\><c-n><c-w>j", desc = "Terminal down window navigation" } ---maps.t["<C-k>"] = { "<c-\\><c-n><c-w>k", desc = "Terminal up window navigation" } ---maps.t["<C-l>"] = { "<c-\\><c-n><c-w>l", desc = "Terminal right window naviation" } --- LSP Installer ---if is_available "mason-lspconfig.nvim" then maps.n["<leader>li"] = { "<cmd>LspInfo<cr>", desc = "LSP information" } end - --- ALE: toggle _ALE activity ---keymap('n', '<leader>a',[[:ALEToggle<CR>]]) - ---keymap('n', '<Leader>cd', ':call fzf#run({'source': 'fd -t d -H . ~', 'sink': 'cd'})<CR>') --- ":lua require('neogen').generate()<CR>") ---keymap("n", "<leader>ww", ":set wrap!<CR>") --- |
