From 6371e90cc598e52b1d057d4b6d9a7b75d60e2fd0 Mon Sep 17 00:00:00 2001 From: srdusr Date: Fri, 16 Dec 2022 23:42:26 +0200 Subject: Removed config/nvim --- config/nvim/lua/user/keys.lua | 651 ------------------------------------------ 1 file changed, 651 deletions(-) delete mode 100644 config/nvim/lua/user/keys.lua (limited to 'config/nvim/lua/user/keys.lua') diff --git a/config/nvim/lua/user/keys.lua b/config/nvim/lua/user/keys.lua deleted file mode 100644 index dd48b76..0000000 --- a/config/nvim/lua/user/keys.lua +++ /dev/null @@ -1,651 +0,0 @@ ---[[ 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 } -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 = ";" ---vim.g.maplocalleader = ";" - --- "jj" to exit insert-mode -map("i", "jk", "") - -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') | ") -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 }) - ---Easier split navigations, just ctrl-j instead of ctrl-w then j -map("n", "", "") -map("n", "", "") -map("n", "", "") -map("n", "", "") - --- Combine buffers list with buffer name -map("n", "b", ":buffers:buffer") ---map("n", "b", ":ls:b") - --- Map buffer next, prev and delete to -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') - -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 ---]]) - -vim.cmd([[ - snoremap - snoremap - snoremap - snoremap -]]) - --- move block easily -map("n", "<", "<<", term_opts) -map("n", ">", ">>", term_opts) -map("x", "<", "", ">gv", term_opts) - --- Resize Panes -map("n", "+", ":resize +5") -map("n", "-", ":resize -5") -map("n", "<", ":vertical resize +5") -map("n", ">", ":vertical resize -5") -map("n", "=", "=") - --- New tab -map("n", "e", ":tabedit") - --- create tab like window -map("n", "h", ":tabprevious") -map("n", "l", ":tabnext") -map("n", "n", ":tabnew") - --- Vim TABs -map("n", "1", "1gt") -map("n", "2", "2gt") -map("n", "3", "3gt") -map("n", "4", "4gt") -map("n", "5", "5gt") -map("n", "6", "6gt") -map("n", "7", "7gt") -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") - --- Toggle set number -map("n", "$", ":NumbersToggle") -map("n", "%", ":NumbersOnOff") - --- Change mode to executable -map("n", "x", ":!chmod +x %") - --- Paste without replace clipboard -map("v", "p", '"_dP') - --- Paste end of line ---map("n", ",", "$p") ---vim.cmd([[ --- nmap , $p ---]]) - --- Select entire buffer ---map("v", "", "ggG") - --- Delete without changing the registers ---map('n', 'x', '"_x') - --- Select all text in current buffer ---map('n', 'a', ':keepjumps normal! ggVG') - --- 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", "<", "/", ":/\\<\\>", { silent = false }) - --- 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)") - --- 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 }) - --- 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" }) - --- Hitting ESC when inside a terminal to get into normal mode ---utils.map("t", "", [[]]) - --- markdown-preview -map("n", "md", "MarkdownPreviewToggle") - - --- 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() -]]) - -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 - function! Toggle_transparent_background() - if t:is_transparent == 0 - hi Normal guibg=#111111 ctermbg=black - let t:is_transparent = 1 - else - hi Normal guibg=NONE ctermbg=NONE - let t:is_transparent = 0 - endif - endfunction - nnoremap tb :call Toggle_transparent_background() -]]) ---keymap('n', 'tb', ':Toggle_transparent_background') - --- Toggle zoom -vim.cmd([[ - function! s:ZoomToggle() abort - if exists('t:zoomed') && t:zoomed - execute t:zoom_winrestcmd - let t:zoomed = 0 - else - let t:zoom_winrestcmd = winrestcmd() - resize - vertical resize - let t:zoomed = 1 - endif - endfunction - 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') - --- Open last closed buffer -vim.cmd([[ - function! OpenLastClosed() - let last_buf = bufname('#') - if empty(last_buf) - echo "No recently closed buffer found" - return - endif - let result = input("Open ". last_buf . " in (n)ormal (v)split, (t)ab or (s)plit ? (n/v/t/s) : ") - if empty(result) || (result !=# 'v' && result !=# 't' && result !=# 's' && result !=# 'n') - return - endif - if result ==# 't' - execute 'tabnew' - elseif result ==# 'v' - execute "vsplit" - elseif result ==# 's' - execute "split" - endif - execute 'b ' . last_buf - endfunction - ]]) -map("n", "", ":call OpenLastClosed() ") - --- Tabularize -vim.cmd([[ - vnoremap mm ':Tabularize /^\s*\S.*\zs' . split(&commentstring, '%s')[0] . "" - nnoremap mm ':Tabularize /^\s*\S.*\zs' . split(&commentstring, '%s')[0] . "" - "nnoremap i mc40A 080lDgelD`cP - "vnoremap ii mc0f-20i`cdt=j -]]) - -vim.cmd([[ - " Start interactive EasyAlign in visual mode (e.g. vipga) - xmap ga (EasyAlign) - " Start interactive EasyAlign for a motion/text object (e.g. gaip) - nmap ga (EasyAlign) - if !exists('g:easy_align_delimiters') - let g:easy_align_delimiters = {} - endif - let g:easy_align_delimiters['--'] = { 'pattern': '--', 'ignore_groups': ['String'] } - 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 --- 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