-- Map leader "Global Key" to space, so you can use it optionally like spacemacs etc. vim.g.mapleader = " " vim.g.maplocalleader = " " -- Beautifully cursed, let's rebind C-x to the leader key and other respective emacs keybindings vim.cmd("map ") vim.cmd("map ") vim.cmd("imap ") vim.cmd("map ") -- Lazy plugin manager require("config.lazy") -- Enable line numbers vim.cmd("set number") -- Turn off highlighting after search completion vim.cmd("set nohlsearch") -- Colourscheme vim.o.background = "light" -- or "dark" for dark mode vim.cmd("colorscheme gruvbox") -- Telescope setup (Like emacs ivy-mode) require('telescope').setup{ defaults = { -- ... }, pickers = { find_files = { theme = "ivy", } }, extensions = { -- ... } } -- Custom statusline (modeline) require('mini.statusline').setup() -- LSP Configuration require('lsp-zero') require('lspconfig').lua_ls.setup({}) require('lspconfig').bashls.setup({}) require('lspconfig').clangd.setup({}) require('lspconfig').tsserver.setup({}) require('lspconfig').jedi_language_server.setup({}) -- DAP Configuration local dap = require("dap") local dapwidgets = require("dap.ui.widgets") local dapwidgetscope = dapwidgets.sidebar(dapwidgets.scopes) local daprunning = false -- Functions to initialise Dap, open UI widgets and set helper keybindings local function dapInit() dap.repl.open() dapwidgetscope.open() daprunning = true -- Can't get these working! -- vim.keymap.del({"n", "v", "o"}, "") -- vim.keymap.set({"n", "v", "o"}, "", "ln") -- vim.keymap.set({"n", "v", "o"}, "", "ln") -- vim.keymap.set({"n", "v", "o"}, "", "ln") -- vim.keymap.set({"n", "v", "o"}, "", "ln") vim.cmd("unmap ") vim.cmd("map ln") vim.cmd("map li") vim.cmd("map lr") vim.cmd("map ls") print("Initialised debugger successfully") end local function dapCleanup() dap.repl.close() dapwidgetscope.close() daprunning = false vim.cmd("unmap ") vim.cmd("unmap ") vim.cmd("unmap ") vim.cmd("unmap ") vim.keymap.set({"n", "v", "o"}, '', 'Telescope live_grep') -- vim.keymap.del({"n", "v", "o"}, "") -- vim.keymap.del({"n", "v", "o"}, "") -- vim.keymap.del({"n", "v", "o"}, "") -- vim.keymap.del({"n", "v", "o"}, "") -- vim.keymap.set({"n", "v", "o"}, '', 'Telescope live_grep') print("Cleaned up debugger successfully") end -- DAP Server configurations -- C DAP Configuration dap.adapters.gdb = { type = "executable", command = "gdb", args = { "-i", "dap" } } dap.configurations.c = { { name = "Launch", type = "gdb", request = "launch", program = function() return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') end, cwd = "${workspaceFolder}", stopAtBeginningOfMainSubprogram = false, }, } -- Remake of emacs which-key mode, I'll add all custom keybinds here -- TODO: The DAP related functions should be moved into their own respective file/modularised better! require("which-key").add ({ { "", "Telescope live_grep" , desc = "Swiper", mode = "n" }, -- This does not allow you to make a new file only search existing, but good enough for now. { "", "Telescope find_files" , desc = "Find File", mode = "n" }, -- To properly remake the Emacs ivy buffer command, we should figure out how to combine Telescope buffers and Telescope oldfiles -- This is good enough for now { "b", "Telescope oldfiles" , desc = "Recently opened files", mode = "n" }, { "", "Telescope buffers" , desc = "Buffers", mode = "n" }, { "k", "bp|bd#" , desc = "Close current buffer", mode = "n" }, { "0", "close", desc = "Close focused window" }, { "2", "split", desc = "Split window horizontally" }, { "3", "vs", desc = "Split window vertically" }, { "o", "wincmd w", desc = "Switch to next window" }, { -- Nested mappings are allowed and can be added in any order -- Most attributes can be inherited or overridden on any level -- There's no limit to the depth of nesting mode = { "n", "v" }, -- NORMAL and VISUAL mode { "", "qa", desc = "Quit" }, { "", "w", desc = "Write" }, }, -- LSP/DAP Options { mode = { "n", "v" }, -- NORMAL and VISUAL mode { "lb", function() dap.toggle_breakpoint() end, desc = "Debugger: Toggle breakpoint" }, { "ld", function() if daprunning == false then if pcall(function() dap.continue() end) then dapInit() else print("Debugger failed to start!") daprunning = false end else print("Debugger already running!") end end, desc = "Debugger: Run" }, { "lD", function() if daprunning == false then if pcall(function() dap.run_last() end) then dapInit() print("Started debugger from previous configuration successfully") else print("Debugger failed to start!") daprunning = false end else print("Debugger already running!") end end, desc = "Debugger: Run last configuration again" }, { "ls", function() if daprunning == true then if pcall(function() dap.terminate() end) then dapCleanup() print("Stopped debugger successfully") else daprunning = true end else print("Debugger is not running!") end end, desc = "Debugger: Stop" }, { "lr", function() if daprunning == true then if not pcall(function() dap.continue() end) then dapCleanup() end else print("Debugger is not running! Please run debugger first") end end, desc = "Debugger: Resume execution" }, { "ln", function() if daprunning == true then if not pcall(function() dap.step_over() end) then dapCleanup() end else print("Debugger is not running! Please run debugger first") end end, desc = "Debugger: Step over" }, { "li", function() if daprunning == true then if not pcall(function() dap.step_into() end) then dapCleanup() print("Debugger failed to continue!") end else print("Debugger is not running! Please run debugger first") end end, desc = "Debugger: Step into" }, } })