local km = vim.keymap.set --remaps vim.g.mapleader = " " vim.g.maplocalleader = "," -- oil vim.keymap.set('n', "-", "Oil --float", { desc ="Enter file explorer (Oil)" }) vim.keymap.set('n', "w", "w", { desc = "Save" } ) vim.keymap.set('n', "w", "w", { desc = "Save" } ) vim.keymap.set('n', "q", "q", { desc = "Quit without saving" } ) vim.keymap.set('n', "q", "q", { desc = "Quit without saving" } ) vim.keymap.set('n', "wq", "wq", { desc = "Save and quit" } ) vim.keymap.set('n', "qq", "q!", { desc = "Force to quit without saving" } ) -- switch between windows vim.keymap.set("n", "j", "j") vim.keymap.set("n", "h", "h") vim.keymap.set("n", "k", "k") vim.keymap.set("n", "l", "l") -- TERMINAL -- exit t mode km("t", "", "", { desc = "Exit terminal mode"}) km("n", "t" , function() print("open terminal") -- function OpenTerminal() local dir = vim.fn.expand('%:p:h') -- if in a file if vim.startswith(dir, 'oil://') then -- if in an Oil buffer dir = string.sub(dir, 7) -- Strip 'oil://' prefix if vim.api.nvim_buf_get_option(0, "buftype") == "nofile" then -- is in a float vim.cmd.q() end end vim.cmd('lcd ' .. dir) vim.cmd('terminal') end , { desc = "Create a terminal in the current 'context'" } ) -- todo: this is not robust... add autocompletion and verify that file exists vim.keymap.set("n", "e", function() local file_name = vim.fn.input("Open file: ") if file_name ~= "" then vim.cmd(":edit " .. file_name) end end, { desc = "edit a file"}) -- BUFFERS navigation and manipulation vim.keymap.set("n","ls", "ls", { desc = "list buffers" }) vim.keymap.set("n","f", "bnext", { desc = "goto next buffers" }) vim.keymap.set("n","d", "bprevious", { desc = "goto previous buffers" }) vim.keymap.set("n","c", "bd", { desc = "close buffers" }) -- CUSTOM HELP FILES vim.keymap.set("n", "h", function() local config_path = vim.fn.stdpath('config') local readme_path = config_path .. '/CHEATSHEET.md' local buf = vim.fn.bufadd(readme_path) vim.fn.bufload(buf) local win = vim.api.nvim_open_win(buf, true, { relative = 'editor', width = 80, height = 20, col = (vim.o.columns - 80) / 2, row = (vim.o.lines - 100) / 2, style = 'minimal' }) vim.api.nvim_win_set_option(win, 'number', false) end, { desc = "Open CHEATSHEET.md"}) vim.keymap.set("n", "hr", function() local config_path = vim.fn.stdpath('config') local readme_path = config_path .. '/README.md' local buf = vim.fn.bufadd(readme_path) vim.fn.bufload(buf) local win = vim.api.nvim_open_win(buf, true, { relative = 'editor', width = 80, height = 20, col = (vim.o.columns - 80) / 2, row = (vim.o.lines - 100) / 2, style = 'minimal' }) vim.api.nvim_win_set_option(win, 'number', false) end, { desc = "Open CHEATSHEET.md"})