-- We use which-key in mappings, which is loaded before plugins, so set up here local which_key = require("which-key") which_key.setup({ plugins = { marks = true, -- shows a list of your marks on ' and ` registers = true, -- shows your registers on " in NORMAL or in INSERT mode spelling = { enabled = true, -- enabling this will show WhichKey when pressing z= to select spelling suggestions suggestions = 20 -- how many suggestions should be shown in the list? }, -- the presets plugin, adds help for a bunch of default keybindings in Neovim -- No actual key bindings are created presets = { operators = true, -- adds help for operators like d, y, ... and registers them for motion / text object completion motions = false, -- adds help for motions text_objects = true, -- help for text objects triggered after entering an operator windows = true, -- default bindings on nav = true, -- misc bindings to work with windows z = true, -- bindings for folds, spelling and others prefixed with z g = true -- bindings for prefixed with g } }, icons = { breadcrumb = "»", -- symbol used in the command line area that shows your active key combo separator = "➜", -- symbol used between a key and it's label group = "+" -- symbol prepended to a group }, popup_mappings = { scroll_down = "", -- binding to scroll down inside the popup scroll_up = "" -- binding to scroll up inside the popup }, window = { border = "rounded", -- none, single, double, shadow position = "bottom", -- bottom, top margin = { 1, 0, 1, 0 }, -- extra window margin [top, right, bottom, left] padding = { 2, 2, 2, 2 }, -- extra window padding [top, right, bottom, left] winblend = 0 }, layout = { height = { min = 4, max = 25 }, -- min and max height of the columns width = { min = 20, max = 50 }, -- min and max width of the columns spacing = 3, -- spacing between columns align = "left" -- align columns left, center or right }, ignore_missing = true, -- enable this to hide mappings for which you didn't specify a label hidden = { "", "", "", "", "", "", "call", "lua", "^:", "^ " }, -- hide mapping boilerplate show_help = true, -- show help message on the command line when the popup is visible triggers = "auto" -- automatically setup triggers -- triggers = {""} -- or specify a list manually }) -- This file is for mappings that will work regardless of filetype. Always available. local options = { noremap = true, silent = true } -- Make F1 act like escape for accidental hits vim.api.nvim_set_keymap('', '#1', '', options) vim.api.nvim_set_keymap('!', '#1', '', options) -- TODO: try using the WinNew and WinClosed autocmd events with CHADtree filetype -- to remap #2 to either open or close commands. Or BufDelete, BufAdd, BufWinLeave, BufWinEnter -- Make F2 bring up a file browser vim.api.nvim_set_keymap('', '#2', 'NvimTreeToggle', options) vim.api.nvim_set_keymap('!', '#2', 'NvimTreeToggle', options) vim.api.nvim_set_keymap('', '-', 'NvimTreeFindFile', options) -- Make ctrl-p open a file finder -- When using ctrl-p, screen out media files that we probably don't want -- to open in vim. And if we really want, then we can use ,ff vim.api .nvim_set_keymap('', '', ':silent Telescope find_files', options) vim.api.nvim_set_keymap('!', '', ':silent Telescope find_files', options) -- Make F4 toggle showing invisible characters vim.api .nvim_set_keymap('', '_z', ':set list:map #4 _Z', { silent = true }) vim.api.nvim_set_keymap('', '_Z', ':set nolist:map #4 _z', { silent = true }) vim.api.nvim_set_keymap('', '#4', '_Z', {}) -- Enter the date on F8 vim.api.nvim_set_keymap('', '#8', '"=strftime("%Y-%m-%d")P', options) vim.api.nvim_set_keymap('!', '#8', '=strftime("%Y-%m-%d")', options) -- Make F9 toggle distraction-free writing setup vim.api.nvim_set_keymap('', '#9', ':TZAtaraxis', options) vim.api.nvim_set_keymap('!', '#9', ':TZAtaraxis', options) -- Make F10 quicklook. Not sure how to do this best in linux so mac only for now vim.api.nvim_set_keymap('', '', ':silent !qlmanage -p "%"', options) vim.api.nvim_set_keymap('!', '', ':silent !qlmanage -p "%"', options) -- Make F12 restart highlighting vim.api.nvim_set_keymap('', '', ':syntax sync fromstart', options) vim.api .nvim_set_keymap('!', '', ':syntax sync fromstart', options) -- Have ctrl-l continue to do what it did, but also temp clear search match highlighting vim.api.nvim_set_keymap('', '', ':nohlsearch', { silent = true }) -- Yank to end of line using more familiar method vim.api.nvim_set_keymap('', 'Y', 'y$', options) -- Center screen vertically when navigating by half screens vim.keymap.set("n", "", "zz") vim.keymap.set("n", "", "zz") -- Center search hits vertically on screen vim.keymap.set("n", "n", "nzzzv") vim.keymap.set("n", "N", "Nzzzv") -- Move visually selected lines up and down vim.keymap.set("v", "J", ":m '>+1gv=gv") vim.keymap.set("v", "K", ":m '<-2gv=gv") local global_leader_opts = { mode = "n", -- NORMAL mode prefix = "", buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings silent = true, -- use `silent` when creating keymaps noremap = true, -- use `noremap` when creating keymaps nowait = true -- use `nowait` when creating keymaps } local global_leader_opts_visual = { mode = "v", -- VISUAL mode prefix = "", buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings silent = true, -- use `silent` when creating keymaps noremap = true, -- use `noremap` when creating keymaps nowait = true -- use `nowait` when creating keymaps } local leader_mappings = { ["e"] = { "NvimTreeToggle", "Explorer" }, ["/"] = { "nohlsearch", "No Highlight" }, ["x"] = { "Bdelete!", "Close Buffer" }, ["q"] = { [["".(get(getqflist({"winid": 1}), "winid") != 0? "cclose" : "botright copen").""]], "Toggle Quicklist" }, f = { name = "Find", f = { "lua require('telescope.builtin').find_files()", "Files" }, g = { "lua require('telescope.builtin').live_grep()", "Grep" }, b = { "lua require('telescope.builtin').buffers(require('telescope.themes').get_dropdown{previewer = false})", "Buffers" }, h = { "lua require('telescope.builtin').oldfiles()", "History" }, q = { "lua require('telescope.builtin').quickfix()", "Quickfix" }, l = { "lua require('telescope.builtin').loclist()", "Loclist" }, p = { "Telescope projects", "Projects" }, k = { "Telescope keymaps", "Keymaps" }, t = { "lua require('telescope.builtin').grep_string{search = \"^\\\\s*[*-] \\\\[ \\\\]\", previewer = false, glob_pattern = \"*.md\", use_regex = true, disable_coordinates=true}", "Todos" }, n = { "ZkNotes { match = {vim.fn.input('Search: ')} }", "Find" }, }, -- Quickly change indent defaults in a file i = { name = "Indent", ["1"] = { "lua require('pwnvim.options').tabindent()", "Tab" }, ["2"] = { "lua require('pwnvim.options').twospaceindent()", "Two Space" }, ["4"] = { "lua require('pwnvim.options').fourspaceindent()", "Four Space" }, r = { "%retab!", "Change existing indent to current with retab" } }, g = { name = "Git", s = { "lua require('telescope.builtin').git_status()", "Status" }, b = { "lua require('telescope.builtin').git_branches()", "Branches" }, c = { "lua require('telescope.builtin').git_commits()", "Commits" }, h = { "lua require 'gitsigns'.toggle_current_line_blame", "Toggle Blame" }, ["-"] = { "lua require 'gitsigns'.reset_hunk()", "Reset Hunk" }, ["+"] = { "lua require 'gitsigns'.stage_hunk()", "Stage Hunk" } }, n = { name = "Notes", d = { "ZkNew { dir = vim.env.ZK_NOTEBOOK_DIR .. '/Calendar', title = os.date('%Y%m%d') }", "New diary" }, e = { "!mv \"\" \"=expand('%:p:h')/\"", "Embed file moving to current file's folder" }, f = { "ZkNotes { match = {vim.fn.input('Search: ') }}", "Find" }, g = { "lua require('pwnvim.plugins').grammar_check()", "Check Grammar" }, h = { "edit ~/Notes/Notes/HotSheet.md", "Open HotSheet" }, i = { c = { "r!/opt/homebrew/bin/icalBuddy --bullet '* ' --timeFormat '\\%H:\\%M' --dateFormat '' --noPropNames --noCalendarNames --excludeAllDayEvents --includeCals 'IC - Work' --includeEventProps datetime,title,attendees,location --propertyOrder datetime,title,attendees,location --propertySeparators '| |\\n * |\\n * | |' eventsToday", "Insert today's calendar" }, o = { "r!gtm-okr goals", "Insert OKRs" }, j = { "r!( (curl -s https://icanhazdadjoke.com/ | grep '\\\"subtitle\\\"') || curl -s https://icanhazdadjoke.com/ ) | sed 's/<[^>]*>//g' | sed -z 's/\\n/ /'", "Insert joke" }, }, m = { "lua require('zk.commands').get('ZkNew')({ dir = vim.fn.input({prompt='Folder: ',default=vim.env.ZK_NOTEBOOK_DIR .. '/Notes/meetings',completion='dir'}), title = vim.fn.input('Title: ') })", "New meeting" }, n = { "ZkNew { dir = vim.fn.input({prompt='Folder: ',default=vim.env.ZK_NOTEBOOK_DIR .. '/Notes',completion='dir'}), title = vim.fn.input('Title: ') }", "New" }, o = { "ZkNotes", "Open" }, t = { "ZkTags", "Open by tag" }, -- in open note (defined in plugins.lua as local-only shortcuts): -- p: new peer note -- l: show outbound links -- r: show outbound links -- i: info preview }, t = { name = "Tasks", --d = { "lua require('pwnvim.tasks').completeTask()", "Done" }, d = { function() require('pwnvim.tasks').completeTaskDirect() end, "Done" }, c = { function() require('pwnvim.tasks').createTaskDirect() end, "Create" }, s = { function() require('pwnvim.tasks').scheduleTaskPrompt() end, "Schedule" }, t = { function() require('pwnvim.tasks').scheduleTaskTodayDirect() end, "Today" }, } } local leader_visual_mappings = { t = { name = "Tasks", a = { ':grep "^\\s*[*-] \\[ \\] ":Trouble quickfix', "All tasks quickfix" }, --d = { function() require("pwnvim.tasks").eachSelectedLine(require("pwnvim.tasks").completeTask) end, "Done" }, d = { ":luado return require('pwnvim.tasks').completeTask(line)", "Done" }, s = { require("pwnvim.tasks").scheduleTaskBulk, "Schedule" }, -- s needs a way to call the prompt then reuse the value --t = { function() require("pwnvim.tasks").eachSelectedLine(require("pwnvim.tasks").scheduleTaskToday) end, "Today" }, t = { ":luado return require('pwnvim.tasks').scheduleTaskToday(line)", "Today" }, }, n = { e = { "\"0y:!mv \"0\" \"=expand('%:p:h')/\"", "Embed file moving to current file's folder" }, f = { ":'<,'>ZkMatch", "Find Selected" } }, i = leader_mappings.i, f = leader_mappings.f, e = leader_mappings.e, q = leader_mappings.q, x = leader_mappings.x } which_key.register(leader_mappings, global_leader_opts) which_key.register(leader_visual_mappings, global_leader_opts_visual) vim.api.nvim_set_keymap('', 'fd', ':silent Telescope lsp_document_symbols', options) -- Set cwd to current file's dir vim.api.nvim_set_keymap('', 'cd', ':cd %:h', options) vim.api.nvim_set_keymap('', 'lcd', ':lcd %:h', options) -- Debug syntax files vim.api.nvim_set_keymap('', 'sd', [[:echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')]], options) -- """"""""" Global Shortcuts """"""""""""" vim.api.nvim_set_keymap('', '', 'gj', options) vim.api.nvim_set_keymap('', '', 'g$', options) vim.api.nvim_set_keymap('', '', 'g^', options) vim.api.nvim_set_keymap('', '', 'g^', options) -- Bubble lines up and down using the unimpaired plugin vim.api.nvim_set_keymap('n', '', '[e', options) vim.api.nvim_set_keymap('n', '', ']e', options) vim.api.nvim_set_keymap('v', '', '[egv', options) vim.api.nvim_set_keymap('v', '', ']egv', options) -- Visually select the text that was last edited/pasted -- Similar to gv but works after paste vim.api.nvim_set_keymap('', 'gV', '`[v`]', options) -- What do these do? -- inoremap u -- nnoremap & :&& -- xnoremap & :&& -- Indent/outdent shortcuts vim.api.nvim_set_keymap('n', '', '<<', options) vim.api.nvim_set_keymap('v', '', '', '<<', options) vim.api.nvim_set_keymap('n', '', '>>', options) vim.api.nvim_set_keymap('v', '', '>gv', options) vim.api.nvim_set_keymap('!', '', '>>', options) -- keep visual block so you can move things repeatedly vim.api.nvim_set_keymap('v', "<", "", ">gv", options) -- TODO: this should be in programming setup -- nmap :make -- imap :make -- easy expansion of the active directory with %% on cmd local options_nosilent = { noremap = true, silent = false } vim.api.nvim_set_keymap('c', '%%', "=expand('%:p:h')/", options_nosilent) -- gx is a built-in to open URLs under the cursor, but when -- not using netrw, it doesn't work right. Or maybe it's just me -- but anyway this command works great. -- /Users/pwalsh/Documents/md2rtf-style.html -- ../README.md -- ~/Desktop/Screen Shot 2018-04-06 at 5.19.32 PM.png -- [abc](https://github.com/adsr/mle/commit/e4dc4314b02a324701d9ae9873461d34cce041e5.patch) vim.api.nvim_set_keymap('', 'gx', ":silent !open \"\" || xdg-open \"\"", options) vim.api.nvim_set_keymap('v', 'gx', "\"0y:silent !open \"0\" || xdg-open \"0\"gv", options) vim.api.nvim_set_keymap('', '', ":silent !open \"\" || xdg-open \"\"", options) vim.api.nvim_set_keymap('v', '', "\"0y:silent !open \"0\" || xdg-open \"0\"gv", options) -- open/close folds with space bar vim.api.nvim_set_keymap('', '', [[@=(foldlevel('.')?'za':"\")]], options) -- Make nvim terminal more sane vim.api.nvim_set_keymap('t', '', [[]], options) vim.api.nvim_set_keymap('t', '', "", options) vim.api.nvim_set_keymap('t', '', "", options) -- gui nvim stuff -- Adjust font sizes vim.api.nvim_set_keymap('', '', [[:silent! let &guifont = substitute( \ &guifont, \ ':h\zs\d\+', \ '\=eval(submatch(0)+1)', \ '')]], options) vim.api.nvim_set_keymap('', '', [[:silent! let &guifont = substitute( \ &guifont, \ ':h\zs\d\+', \ '\=eval(submatch(0)+1)', \ '')]], options) vim.api.nvim_set_keymap('', '', [[:silent! let &guifont = substitute( \ &guifont, \ ':h\zs\d\+', \ '\=eval(submatch(0)-1)', \ '')]], options) vim.api.nvim_set_keymap('', '', [[:silent! let &guifont = substitute( \ &guifont, \ ':h\zs\d\+', \ '\=eval(submatch(0)-1)', \ '')]], options) -- Need to map cmd-c and cmd-v to get natural copy/paste behavior vim.api.nvim_set_keymap('n', '', '"*p', options) vim.api.nvim_set_keymap('v', '', '"*p', options) vim.api.nvim_set_keymap('!', '', '*', options) vim.api.nvim_set_keymap('c', '', '*', options) vim.api.nvim_set_keymap('v', '', '"*y', options) -- When pasting over selected text, keep original register value vim.api.nvim_set_keymap('v', 'p', '"_dP', options) -- cmd-w to close the current buffer vim.api.nvim_set_keymap('', '', ':bd', options) vim.api.nvim_set_keymap('!', '', ':bd', options) -- cmd-t or cmd-n to open a new buffer vim.api.nvim_set_keymap('', '', ':enew', options) vim.api.nvim_set_keymap('!', '', ':enew', options) vim.api.nvim_set_keymap('', '', ':tabnew', options) vim.api.nvim_set_keymap('!', '', ':tabnew', options) -- cmd-s to save vim.api.nvim_set_keymap('', '', ':w', options) vim.api.nvim_set_keymap('!', '', ':w', options) -- cmd-q to quit vim.api.nvim_set_keymap('', '', ':q', options) vim.api.nvim_set_keymap('!', '', ':q', options) -- cmd-o to open vim.api.nvim_set_keymap('', '', ':Telescope file_browser cmd=%:h', options) vim.api.nvim_set_keymap('!', '', ':Telescope file_browser cmd=%:h', options) -- emacs bindings to jump around in lines vim.api.nvim_set_keymap("i", "", "A", options) vim.api.nvim_set_keymap("i", "", "I", options) -- TODO: -- Use ctrl-x, ctrl-u to complete :emoji: symbols, then use -- ,e to turn it into a symbol if desired -- vim.api.nvim_set_keymap('!', 'e', -- [[:%s/:\([^:]\+\):/\=emoji#for(submatch(1), submatch(0))/g]], -- options) -- Setup tpope unimpaired-like forward/backward shortcuts which_key.register({ ["[a"] = "Prev file arg", ["]a"] = "Next file arg", ["[b"] = { 'BufferLineCyclePrev', "Prev buffer" }, ["]b"] = { 'BufferLineCycleNext', "Next buffer" }, ["[c"] = "Prev git hunk", ["]c"] = "Next git hunk", ["[l"] = "Prev loclist item", ["]l"] = "Next loclist item", ["[q"] = "Prev quicklist item", ["]q"] = "Next quicklist item", ["[t"] = { 'tabprevious', "Prev tab" }, ["[T"] = { 'tabprevious', "First tab" }, ["]t"] = { 'tabnext', "Next tab" }, ["]T"] = { 'tablast', "Last tab" }, ["[n"] = "Prev conflict", ["]n"] = "Next conflict", ["[ "] = "Add blank line before", ["] "] = "Add blank line after", ["[e"] = "Swap line with previous", ["]e"] = "Swap line with next", ["[x"] = "XML encode", ["]x"] = "XML decode", ["[u"] = "URL encode", ["]u"] = "URL decode", ["[y"] = "C escape", ["]y"] = "C unescape", ["[d"] = { "lua vim.diagnostic.goto_prev()", "Prev diagnostic" }, ["]d"] = { "lua vim.diagnostic.goto_next()", "Next diagnostic" }, ["[1"] = { ':BufferLineGoToBuffer 1', "Go to buffer 1" }, ["]1"] = { ':BufferLineGoToBuffer 1', "Go to buffer 1" }, ["[2"] = { ':BufferLineGoToBuffer 2', "Go to buffer 2" }, ["]2"] = { ':BufferLineGoToBuffer 2', "Go to buffer 2" }, ["[3"] = { ':BufferLineGoToBuffer 3', "Go to buffer 3" }, ["]3"] = { ':BufferLineGoToBuffer 3', "Go to buffer 3" }, ["[4"] = { ':BufferLineGoToBuffer 4', "Go to buffer 4" }, ["]4"] = { ':BufferLineGoToBuffer 4', "Go to buffer 4" }, ["[5"] = { ':BufferLineGoToBuffer 5', "Go to buffer 5" }, ["]5"] = { ':BufferLineGoToBuffer 5', "Go to buffer 5" }, ["[6"] = { ':BufferLineGoToBuffer 6', "Go to buffer 6" }, ["]6"] = { ':BufferLineGoToBuffer 6', "Go to buffer 6" }, ["[7"] = { ':BufferLineGoToBuffer 7', "Go to buffer 7" }, ["]7"] = { ':BufferLineGoToBuffer 7', "Go to buffer 7" }, ["[8"] = { ':BufferLineGoToBuffer 8', "Go to buffer 8" }, ["]8"] = { ':BufferLineGoToBuffer 8', "Go to buffer 8" }, ["[9"] = { ':BufferLineGoToBuffer 9', "Go to buffer 9" }, ["]9"] = { ':BufferLineGoToBuffer 9', "Go to buffer 9" }, [""] = { ':BufferLineCyclePrev', "Go to next buffer" }, [""] = { ':BufferLineCycleNext', "Go to prev buffer" }, }, { mode = 'n', silent = true }) -- Close buffer vim.api.nvim_set_keymap('', '', ':Bdelete', options) vim.api.nvim_set_keymap('!', '', ':Bdelete', options) vim.api.nvim_set_keymap('', '', ':Bdelete', options) vim.api.nvim_set_keymap('!', '', ':Bdelete', options) vim.api.nvim_set_keymap('', '', ':Bdelete', options) vim.api.nvim_set_keymap('!', '', ':Bdelete', options) -- Magic buffer-picking mode vim.api.nvim_set_keymap('', '', ':BufferPick', options) vim.api.nvim_set_keymap('!', '', ':BufferPick', options) vim.api.nvim_set_keymap('', '[0', ':BufferPick', options) vim.api.nvim_set_keymap('', ']0', ':BufferPick', options) vim.api.nvim_set_keymap('', '[\\', ':BufferPick', options) vim.api.nvim_set_keymap('', ']\\', ':BufferPick', options) -- Pane navigation integrated with tmux vim.api.nvim_set_keymap('', '', ':TmuxNavigateLeft', { silent = true }) vim.api.nvim_set_keymap('', '', ':TmuxNavigateDown', { silent = true }) vim.api.nvim_set_keymap('', '', ':TmuxNavigateUp', { silent = true }) vim.api.nvim_set_keymap('', '', ':TmuxNavigateRight', { silent = true }) -- add mapping for :TmuxNavigatePrevious ? c-\, the default, used by toggleterm