local opts = require("utils").opts local keymap = vim.keymap -- write to file (sudo if readonly) if vim.g.vscode then keymap.set("n", "W", ":Write", opts("write file (vscode)")) else keymap.set("n", "W", ":w!", opts("write file")) keymap.set("n", "W", ":lua require('utils').sudo_write()", opts("sudo write file")) end -- Handy VSCode Shortcuts -- Move lines up and down vim.api.nvim_set_keymap('n', '', ':m .-2==', { noremap = true, silent = true }) vim.api.nvim_set_keymap('n', '', ':m .+1==', { noremap = true, silent = true }) vim.api.nvim_set_keymap('n', '', ':m .-2', { noremap = true, silent = true }) vim.api.nvim_set_keymap('n', '', ':m .+1', { noremap = true, silent = true }) -- Move lines in insert mode vim.api.nvim_set_keymap('i', '', ':m .-2i', { noremap = true, silent = true }) vim.api.nvim_set_keymap('i', '', ':m .+1i', { noremap = true, silent = true }) vim.api.nvim_set_keymap('i', '', ':m .-2i', { noremap = true, silent = true }) vim.api.nvim_set_keymap('i', '', ':m .+1i', { noremap = true, silent = true }) -- Copy lines up and down in normal mode vim.api.nvim_set_keymap('n', '', ':t .-1', { noremap = true, silent = true }) vim.api.nvim_set_keymap('n', '', ':t .-1', { noremap = true, silent = true }) vim.api.nvim_set_keymap('n', '', ':t .-1', { noremap = true, silent = true }) vim.api.nvim_set_keymap('n', '', ':t .', { noremap = true, silent = true }) -- Copy lines up and down in insert mode vim.api.nvim_set_keymap('i', '', ':t.-1i', { noremap = true, silent = true }) vim.api.nvim_set_keymap('i', '', ':t.i', { noremap = true, silent = true }) vim.api.nvim_set_keymap('i', '', ':t.-1i', { noremap = true, silent = true }) vim.api.nvim_set_keymap('i', '', ':t.i', { noremap = true, silent = true }) -- Keep selection in visual mode when indenting vim.api.nvim_set_keymap('v', '<', '', '>gv', { noremap = true, silent = true }) -- Save shortcut keymap.set("i", "", ":wa", opts("Save file (shortcut)")) keymap.set("n", "", ":w", opts("Save file (shortcut)")) -- Save and quit (sudo and no sudo) keymap.set("n", "E", ":wq!", opts("write and quit file")) keymap.set("n", "E", ":lua require('utils').sudo_write():q!", opts("sudo write and quit file")) -- Quite file keymap.set("n", "Q", ":q!", opts("quit file")) -- Duplicate line keymap.set("n", "dd", ":t.", opts("Duplicate line")) -- Editor focus keymap.set("n", "", ":wincmd p", opts("Cycle focus")) -- Key Mappings for LaTeX workflow keymap.set('n', 'lc', ':VimtexCompile', opts("Compile latex document")) -- Compile LaTeX file keymap.set('n', 'lv', ':VimtexView', opts("View compiled latex pdf")) -- View compiled PDF keymap.set('n', 'lq', ':VimtexStop', opts("Stop Compiling document")) -- Stop compilation -- Markdown-Preview keymap.set('n', 'm', ':MarkdownPreview', opts("Preview Markdown document in browser")) -- Stop compilation -- window navigation keymap.set("n", "", "h", opts()) keymap.set("n", "", "j", opts()) keymap.set("n", "", "k", opts()) keymap.set("n", "", "l", opts()) -- window resize keymap.set("n", "", ":vertical resize -2", opts()) keymap.set("n", "", ":resize -2", opts()) keymap.set("n", "", ":resize +2", opts()) keymap.set("n", "", ":vertical resize +2", opts()) -- nohlsearch keymap.set("n", "h", ":nohlsearch", opts("remove search highlighting")) -- run file keymap.set("n", "r", ":!%:p", opts("run current file")) keymap.set("n", "r", ":!%:p", opts("run current file with arguments")) -- chmod +x keymap.set("n", "m", ":!chmod +x %:p", opts("make current file executable")) -- script setup keymap.set("n", "#", ":set syntax=sh:w:!chmod +x %:p:LspStart bashlsi#!/bin/sh", opts("setup sh script")) keymap.set("n", "#", ":set syntax=python:w:!chmod +x %:p:LspStart pyrighti#!/usr/bin/env python3", opts("setup python script")) -- CTRL + Backspace keymap.set("i", "", "", opts()) -- select all keymap.set("n", "a", "ggVG", opts("select all")) -- move cursor in insert mode keymap.set("i", "", "", opts()) keymap.set("i", "", "", opts()) keymap.set("i", "", "", opts()) keymap.set("i", "", "", opts()) keymap.set("i", "", "", opts("Jump back by word")) keymap.set("i", "", "", opts("Jump back by word")) keymap.set("i", "", "", opts("Jump to EOL")) keymap.set("i", "", "", opts("Jump to beginning of line")) -- open in neovide -- keymap.set("n", "n", ":!neovide --no-fork %:p", opts("open in neovide (wip)")) -- deleting doesn't yank except when used with keymap.set({ "n", "v" }, "d", '"_d', opts()) keymap.set({ "n", "v" }, "D", '"_D', opts()) keymap.set({ "n", "v" }, "x", '"_x', opts()) keymap.set({ "n", "v" }, "X", '"_X', opts()) keymap.set({ "n", "v" }, "c", '"_c', opts()) keymap.set({ "n", "v" }, "C", '"_C', opts()) keymap.set({ "n", "v" }, "d", "d", opts("yank and delete")) keymap.set({ "n", "v" }, "D", "D", opts("YANK and DELETE to end")) -- + yank/paste/delete uses system clipboard keymap.set({ "n", "v" }, "y", '"+y', opts("yank to system clipboard")) keymap.set({ "n", "v" }, "Y", '"+y$', opts("YANK to system clipboard")) keymap.set({ "n", "v" }, "p", '"+p', opts("paste from system clipboard")) keymap.set({ "n", "v" }, "P", '"+P', opts("PASTE from system clipboard")) keymap.set({ "n", "v" }, "d", '"+d', opts("yank to system clipboard and delete")) keymap.set({ "n", "v" }, "D", '"+D', opts("YANK to system clipboard and DELETE")) keymap.set("n", "wk", ":WhichKey", opts("Toggle WhichKey"))