require("plugins") local opts = { noremap = true, silent = true } vim.g.mapleader = ' ' vim.opt.background = "dark" vim.opt.clipboard = "unnamedplus" -- Use system clipboard -- vim.opt.list = true -- Show spaces, tabs, etc. vim.opt.number = true vim.opt.relativenumber = true vim.opt.shortmess:append("I") -- Disable intro message vim.opt.wrap = false vim.cmd.colorscheme("duskfox") -- Tree vim.g.netrw_banner = 0 -- Hide top banner vim.g.netrw_liststyle = 3 -- Tree-style listing vim.g.netrw_browse_split = 4 -- Open in previous window vim.g.netrw_altv = 1 -- Put vertical splits to the right vim.g.netrw_winsize = 25 -- Width of netrw window vim.g.netrw_keepdir = 0 -- Don't keep cwd synced with netrw vim.opt.fillchars = { vert = "|", fold = " ", eob = " ", diff = "/", msgsep = "-", foldopen = "▾", foldsep = "|", foldclose = ">", } -- Open Vexplore if the first argument is a directory if vim.fn.argc() == 1 and vim.fn.isdirectory(vim.fn.argv(0)) == 1 then -- Delete the default empty buffer vim.cmd("enew") -- create a new empty buffer vim.cmd("bdelete #") -- delete the previous buffer (the auto Ex buffer) -- Open vertical explorer for the directory vim.cmd("Vexplore " .. vim.fn.fnameescape(vim.fn.argv(0))) end -- Function to toggle vertical netrw explorer local function toggle_vexplore() -- Check if a netrw buffer already exists for _, buf in ipairs(vim.api.nvim_list_bufs()) do if vim.api.nvim_buf_is_loaded(buf) then local ft = vim.api.nvim_buf_get_option(buf, "filetype") if ft == "netrw" then -- If found, close the window for _, win in ipairs(vim.api.nvim_list_wins()) do if vim.api.nvim_win_get_buf(win) == buf then vim.api.nvim_win_close(win, true) return end end end end end -- If no netrw buffer found, open vertical explorer vim.cmd("Vexplore") end -- Map 'l' and 'l' to open file/dir in netrw buffers vim.api.nvim_create_autocmd("FileType", { pattern = "netrw", callback = function() vim.api.nvim_buf_set_keymap(0, "n", "l", "", { silent = true }) vim.api.nvim_buf_set_keymap(0, "n", "h", "", { silent = true }) end, }) -- Remove trailing whitespace on all lines before saving, excluding markdown files vim.api.nvim_create_autocmd("BufWritePre", { pattern = "*", callback = function() if vim.bo.filetype == "markdown" then return end vim.cmd([[%s/\s\+$//e]]) end, }) -- Disable auto-comment vim.api.nvim_create_autocmd("FileType", { pattern = "*", callback = function() vim.opt_local.formatoptions:remove({ "c", "r", "o" }) end, }) -- Enable spellcheck for certain file types vim.api.nvim_create_autocmd("FileType", { pattern = { "gitcommit", "markdown", "text", "rst", "asciidoc", "org", "norg", "latex", "tex", "mail", "pandoc" }, callback = function() vim.opt_local.spell = true end, }) -- NOTE: On some terminal emulators, the keybinds -- and don't work either in normal or insert mode. -- Macros vim.fn.setreg('p', "i# %% py\027o##\027O") -- Insert python cell -- Tabs vim.keymap.set('n', '', 'tabnew', opts) vim.keymap.set('n', 'J' , 'tabn' , opts) vim.keymap.set('n', 'K' , 'tabp' , opts) -- Windows vim.keymap.set('n', '' , 'split' , opts) vim.keymap.set('n', '', 'vsplit', opts) vim.keymap.set('n', '' , 'h' , { noremap = true }) vim.keymap.set('n', '' , 'j' , { noremap = true }) vim.keymap.set('n', '' , 'k' , { noremap = true }) vim.keymap.set('n', '' , 'l' , { noremap = true }) -- Imitate normal mode in insert mode vim.keymap.set('i', '' , '' , { noremap = true }) vim.keymap.set('i', '' , '', { noremap = true }) vim.keymap.set('i', '' , '' , { noremap = true }) vim.keymap.set('i', '' , '' , { noremap = true }) vim.keymap.set('i', '', '' , { noremap = true }) -- Plugins vim.keymap.set('n', 'w', 'MdEval' , opts) vim.keymap.set('n', 'c', 'MdEvalClean', opts) -- Other vim.keymap.set('n', '', 'w!' , opts) vim.keymap.set('n', 'q' , 'wq!', opts) vim.keymap.set("n", "e", toggle_vexplore , opts)