my dotfiles for arch
at main 108 lines 3.6 kB view raw
1local map = function(keys, func, desc, mode) 2 mode = mode or "n" 3 vim.keymap.set(mode, keys, func, { desc = desc }) 4end 5 6-- Project view (mini.files) 7map("<leader>pv", function() 8 MiniFiles.open(vim.api.nvim_buf_get_name(0)) 9end, "Open file explorer") 10 11-- Move lines around 12map("J", ":m '>+1<CR>gv=gv", "Move line down", "v") 13map("<S-Down>", ":m '>+1<CR>gv=gv", "Move line down", "v") 14map("K", ":m '<-2<CR>gv=gv", "Move line up", "v") 15map("<S-Up>", ":m '<-2<CR>gv=gv", "Move line up", "v") 16 17-- Keep cursor in center throughout operations 18map("J", "mzJ`z", "Join lines and keep cursor") 19map("<C-d>", "<C-d>zz", "Scroll down and center") 20map("<C-u>", "<C-u>zz", "Scroll up and center") 21map("n", "nzzzv", "Next search result and center") 22map("N", "Nzzzv", "Previous search result and center") 23 24-- Clipboard operations 25map("<leader>p", '"_dP', "Paste without updating register", "x") 26map("<leader>pc", '"+p', "Paste from system clipboard") 27map("<leader>y", '"+y', "Yank to system clipboard") 28map("<leader>y", '"+y', "Yank to system clipboard", "v") 29map("<leader>Y", '"+Y', "Yank line to system clipboard") 30map("<C-v>", '<Esc>"+pa', "Paste from system clipboard", "i") 31 32-- Delete without register 33map("<leader>d", '"_d', "Delete without updating register") 34map("<leader>d", '"_d', "Delete without updating register", "v") 35 36-- Disable Q 37map("Q", "<nop>", "Disable Q") 38 39-- Formatting 40map("<leader>fo", function() 41 vim.cmd("Format") 42 vim.notify("Formatted file", vim.log.levels.INFO, { title = "Formatting" }) 43end, "Format file") 44map("<leader>fe", function() 45 vim.cmd("FormatEnable") 46 vim.notify("Enabled auto-format", vim.log.levels.INFO, { title = "Formatting" }) 47end, "Enable auto-format") 48map("<leader>fd", function() 49 vim.cmd("FormatDisable") 50 vim.notify("Disabled auto-format", vim.log.levels.INFO, { title = "Formatting" }) 51end, "Disable auto-format") 52 53-- Organize Imports 54map("<leader>oi", function() 55 vim.lsp.buf.code_action({ 56 context = { 57 only = { "source.organizeImports" }, 58 diagnostics = vim.diagnostic.get(0), 59 }, 60 apply = true, 61 }) 62end, "Organize Imports") 63 64-- map("<leader>l", function() 65-- local lint = require("lint") 66-- lint.try_lint() 67-- end, "Lint file") 68 69map("<leader>esf", function() 70 vim.cmd("EslintFixAll") 71end, "Fix ESLint issues") 72 73-- Window management 74map("<leader>ws", "<C-w>s", "Split window horizontally") 75map("<leader>wv", "<C-w>v", "Split window vertically") 76map("<leader>wh", "<C-w>h", "Move to left window") 77map("<leader>w<Left>", "<C-w>h", "Move to left window") 78map("<leader>wj", "<C-w>j", "Move to bottom window") 79map("<leader>w<Down>", "<C-w>j", "Move to bottom window") 80map("<leader>wk", "<C-w>k", "Move to top window") 81map("<leader>w<Up>", "<C-w>k", "Move to top window") 82map("<leader>wl", "<C-w>l", "Move to right window") 83map("<leader>w<Right>", "<C-w>l", "Move to right window") 84map("<leader>wq", "<C-w>q", "Close window") 85map("<leader>wf", "<C-w>f <C-w>L", "Open file under cursor in new window") 86 87-- Buffer operations 88map("<leader>rf", ":e<CR>", "Refresh buffer") 89map("<leader>sf", ":w<CR>", "Save file") 90 91-- Terminal 92map("<Esc>", [[<C-\><C-n>]], "Exit terminal insert mode", "t") 93 94-- Close quickfix menu after selecting choice 95vim.api.nvim_create_autocmd("FileType", { 96 pattern = { "qf" }, 97 command = [[nnoremap <buffer> <CR> <CR>:cclose<CR>]], 98}) 99 100vim.api.nvim_create_user_command("Cppath", function() 101 local path = vim.fn.expand("%:p") 102 vim.fn.setreg("+", path) 103 vim.notify('Copied "' .. path .. '" to the clipboard!') 104end, {}) 105 106-- Kickstart keymaps 107 108vim.keymap.set("n", "<leader>q", vim.diagnostic.setloclist, { desc = "Open diagnostic [Q]uickfix list" })