local map = function(mode, lhs, rhs, desc) vim.keymap.set(mode, lhs, rhs, { desc = desc }) end local nmap = function(lhs, rhs, desc) map("n", lhs, rhs, desc) end local mapleader = function(mode, suffix, rhs, desc) map(mode, "" .. suffix, rhs, desc) end local nmapleader = function(suffix, rhs, desc) mapleader("n", suffix, rhs, desc) end map({ "n", "x" }, "gy", '"+y', "copy selection to clipboard") nmap("gY", '"+Y', "copy to clipboard till end of line") nmap("-", "Oil", "Explore") nmap("", "w", "switch to next window") nmap("", "W", "switch to prev window") nmap("", [[nohlsearchdiffupdate]], "nohlsearch and diffupdate") nmap("", [[nohlsearchdiffupdatenormal! ]], "default neovim ") nmapleader("cd", "lcd %:h", "lcd to the directory of current file") vim.keymap.set({ "n", "x" }, "j", [[v:count == 0 ? 'gj' : 'j']], { expr = true, buffer = 0 }) vim.keymap.set({ "n", "x" }, "k", [[v:count == 0 ? 'gk' : 'k']], { expr = true, buffer = 0 }) nmap("gK", "K", "use the keywordprg instead of hover") map('t', '', [[]], "go to normal mode from terminal mode") map('t', '', '', "map to literal ESC in terminal mode") -- lua exec nmapleader("x", function() local line = "lua " .. vim.api.nvim_get_current_line() vim.api.nvim_command(line) vim.api.nvim_input("") end, "execute lua line and go to next line") mapleader("x", "x", ":lua") nmap("x", "luafile %") -- lsp and format nmapleader("e", "lua vim.diagnostic.open_float()") nmap("gd", "lua vim.lsp.buf.definition()") nmap("", "lua require'conform'.format{async=true}") -- fzf nmap("", "FzfLua files", "fzf: find files") nmap("", "FzfLua resume", "fzf: resume") nmap("", "FzfLua buffers", "fzf: buffers") nmap("", "FzfLua oldfiles", "fzf: oldfiles") nmapleader("fg", "FzfLua live_grep_native", "fzf: grep") nmapleader("fc", 'FzfLua files prompt="Nvim Config>\\ " cwd=~/.config/nvim', "fzf: search config") nmapleader("fp", 'lua FzfLua.files({cwd=vim.fn.stdpath("data").."/site/pack/core/opt/"})', "fzf: search plugins") nmapleader("fh", "FzfLua helptags", "fzf: help tags") nmapleader("fk", "FzfLua keymaps", "fzf: keymaps") map("n", "z=", "FzfLua spell_suggest", "fzf: suggest spelling") -- git nmapleader("gs", "Git", "git status") -- qf nmapleader("q", function() require("quicker").toggle() end, "Toggle quickfix list")