-- Keymaps are automatically loaded on the VeryLazy event -- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua -- Add any additional keymaps here local map = vim.keymap.set local Util = require("lazyvim.util") -- ╭───────────────────────────────────────────────────────────╮ -- │ Credit: June Gunn ?/! | Google it / Feeling lucky │ -- ╰───────────────────────────────────────────────────────────╯ vim.g.open_command = vim.g.open_command or "xdg-open" ---@param pat string ---@param lucky boolean local function google(pat, lucky) local query = '"' .. vim.fn.substitute(pat, '["\n]', " ", "g") .. '"' query = vim.fn.substitute(query, "[[:punct:] ]", [[\=printf("%%%02X", char2nr(submatch(0)))]], "g") vim.fn.system( vim.fn.printf(vim.g.open_command .. ' "https://www.google.com/search?%sq=%s"', lucky and "btnI&" or "", query) ) end map("n", "?", function() google(vim.fn.expand(""), false) end, { desc = "Google" }) map("x", "?", function() google(vim.fn.getreg("g"), false) end, { desc = "Google" }) map("n", "uB", function() Util.toggle("background", false, { "light", "dark" }) end, { desc = "Toggle Background" }) map("n", "fT", "") -- Center the screen automatically map("n", "", "zz") map("n", "", "zz") map("n", "n", "nzzzv") map("n", "N", "Nzzzv") map("n", "uS", function() if vim.opt.laststatus:get() == 0 then vim.opt.laststatus = 3 else vim.opt.laststatus = 0 end end, { desc = "Toggle Statusline" }) map("n", "cif", "LazyFormatInfo", { desc = "Formatting" }) map("n", "cir", "LazyRoot", { desc = "Root" }) map("n", "cie", "LazyExtras", { desc = "Extras" }) map("n", "", "_", { desc = "First character of Line" }) map("n", "", "$", { desc = "Last character of Line" }) -- Copy whole text to clipboard map("n", "", ":%y+", { desc = "Copy whole text to clipboard", silent = true }) -- Select all text map("n", "", "ggG", { desc = "Select all text", silent = true, noremap = true }) -- Better paste -- remap "p" in visual mode to delete the highlighted text without overwriting your yanked/copied text, and then paste the content from the unnamed register. map("v", "p", '"_dP') map("n", "dd", function() local is_empty_line = vim.api.nvim_get_current_line():match("^%s*$") if is_empty_line then return '"_dd' else return "dd" end end, { noremap = true, expr = true, desc = "Don't yank empty line to clipboard" }) map("n", "gV", '"`[" . strpart(getregtype(), 0, 1) . "`]"', { expr = true, desc = "Visually select changed text" }) -- Search inside visually highlighted text. Use `silent = false` for it to -- make effect immediately. map("x", "g/", "/\\%V", { silent = false, desc = "Search inside visual selection" }) -- Search visually selected text (slightly better than builtins in Neovim>=0.8) map("x", "*", [[y/\V=escape(@", '/\')]]) map("x", "#", [[y?\V=escape(@", '?\')]]) if package.loaded["cinnamon"] then -- DEFAULT_KEYMAPS: -- Half-window movements: map({ "n", "x" }, "", "lua Scroll('', 1, 1)") map({ "n", "x" }, "", "lua Scroll('', 1, 1)") -- Page movements: map({ "n", "x" }, "", "lua Scroll('', 1, 1)") map({ "n", "x" }, "", "lua Scroll('', 1, 1)") map({ "n", "x" }, "", "lua Scroll('', 1, 1)") map({ "n", "x" }, "", "lua Scroll('', 1, 1)") -- EXTRA_KEYMAPS: -- Start/end of file and line number movements: map({ "n", "x" }, "gg", "lua Scroll('gg')") map({ "n", "x" }, "G", "lua Scroll('G', 0, 1)") -- Start/end of line: map({ "n", "x" }, "0", "lua Scroll('0')") map({ "n", "x" }, "^", "lua Scroll('^')") map({ "n", "x" }, "$", "lua Scroll('$', 0, 1)") -- Paragraph movements: map({ "n", "x" }, "{", "lua Scroll('{')") map({ "n", "x" }, "}", "lua Scroll('}')") -- Previous/next search result: map("n", "n", "lua Scroll('n', 1)") map("n", "N", "lua Scroll('N', 1)") map("n", "*", "lua Scroll('*', 1)") map("n", "#", "lua Scroll('#', 1)") map("n", "g*", "lua Scroll('g*', 1)") map("n", "g#", "lua Scroll('g#', 1)") -- Previous/next cursor location: map("n", "", "lua Scroll('', 1)") map("n", "", "lua Scroll('1', 1)") -- Screen scrolling: map("n", "zz", "lua Scroll('zz', 0, 1)") map("n", "zt", "lua Scroll('zt', 0, 1)") map("n", "zb", "lua Scroll('zb', 0, 1)") map("n", "z.", "lua Scroll('z.', 0, 1)") map("n", "z", "lua Scroll('zt^', 0, 1)") map("n", "z-", "lua Scroll('z-', 0, 1)") map("n", "z^", "lua Scroll('z^', 0, 1)") map("n", "z+", "lua Scroll('z+', 0, 1)") map("n", "", "lua Scroll('', 0, 1)") map("n", "", "lua Scroll('', 0, 1)") -- Horizontal screen scrolling: map("n", "zH", "lua Scroll('zH')") map("n", "zL", "lua Scroll('zL')") map("n", "zs", "lua Scroll('zs')") map("n", "ze", "lua Scroll('ze')") map("n", "zh", "lua Scroll('zh', 0, 1)") map("n", "zl", "lua Scroll('zl', 0, 1)") -- EXTENDED_KEYMAPS: -- Up/down movements: map({ "n", "x" }, "k", "lua Scroll('k', 0, 1)") map({ "n", "x" }, "j", "lua Scroll('j', 0, 1)") map({ "n", "x" }, "", "lua Scroll('k', 0, 1)") map({ "n", "x" }, "", "lua Scroll('j', 0, 1)") -- Left/right movements: map({ "n", "x" }, "h", "lua Scroll('h', 0, 1)") map({ "n", "x" }, "l", "lua Scroll('l', 0, 1)") map({ "n", "x" }, "", "lua Scroll('h', 0, 1)") map({ "n", "x" }, "", "lua Scroll('l', 0, 1)") -- LSP_KEYMAPS: -- LSP go-to-definition: map("n", "gd", "lua Scroll('definition')") -- LSP go-to-declaration: map("n", "gD", "lua Scroll('declaration')") end