Init repo

This commit is contained in:
Curt Spark 2024-07-18 05:14:46 +01:00
commit afafebd2ad
16 changed files with 319 additions and 0 deletions

22
README.org Normal file
View File

@ -0,0 +1,22 @@
* My Neovim Configuration
A cursed cozy retreat for Emacs Evil users, hence called Neovim livE edition.
My Neovim configuration, basically a functional port of my personal emacs configuration.
Your classic emacs keybindings in neovim are found here, C-x C-s, C-x C-f, C-x 0 and onwards alongside all the benefits of fully fledged vim modal editing and way more minimal footprint.
Additionally technically the Space key is the leader key, so you could easily modify this for a more Spacemacs/Doom Emacs type experience.
I haven't gotten around to eloquent abstractions such as Doom Emacs or other configuration frameworks are doing, but I'm sure you can find your way in the init.lua file!
** Why?
Emacs, as much as I love it, is quite a cumbersome bloated beast in comparison to vim/neovim. Such is the cost of basically being an operating system/lisp machine. Vim is too inflexible to implement a system like this. On the other hand, Neovim you might as well call a Lua machine and there are ports of which-key and the like to accomplish this for Neovim.
Also nowadays it seems like terminal only Emacs compatibility for plugins is considered a second class citizen.
I've configured this system to the point that it functionally operates the same as my Emacs configuration. My emacs configuration has an approx 1.5s average startup, on the other hand this setup averages around a 50ms startup!
Emacs is still a lot more flexible, the mode, buffer and window system is superior but Neovims is good enough. I believe Neovim and Emacs can work together in harmony with Neovim being good enough 95% of the time and Emacs being for everything else (Unique features such as Org mode for example). Additionally you can use this configuration in remote server settings to have a cozy very well featured environment! Best of both worlds, no need for an Editor War.
[[./which-key-preview.png]]

207
init.lua Normal file
View File

@ -0,0 +1,207 @@
-- 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 <C-x> <Space>")
vim.cmd("map <C-g> <Esc>")
vim.cmd("imap <C-g> <Esc>")
vim.cmd("map <C-c> <Nop>")
-- 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"}, "<C-s>")
-- vim.keymap.set({"n", "v", "o"}, "<C-n>", "<C-c>ln")
-- vim.keymap.set({"n", "v", "o"}, "<C-i>", "<C-c>ln")
-- vim.keymap.set({"n", "v", "o"}, "<C-r>", "<C-c>ln")
-- vim.keymap.set({"n", "v", "o"}, "<C-s>", "<C-c>ln")
vim.cmd("unmap <C-s>")
vim.cmd("map <C-n> <C-c>ln")
vim.cmd("map <C-i> <C-c>li")
vim.cmd("map <C-r> <C-c>lr")
vim.cmd("map <C-s> <C-c>ls")
print("Initialised debugger successfully")
end
local function dapCleanup()
dap.repl.close()
dapwidgetscope.close()
daprunning = false
vim.cmd("unmap <C-n>")
vim.cmd("unmap <C-i>")
vim.cmd("unmap <C-r>")
vim.cmd("unmap <C-s>")
vim.keymap.set({"n", "v", "o"}, '<C-s>', '<cmd>Telescope live_grep<cr>')
-- vim.keymap.del({"n", "v", "o"}, "<C-n>")
-- vim.keymap.del({"n", "v", "o"}, "<C-i>")
-- vim.keymap.del({"n", "v", "o"}, "<C-r>")
-- vim.keymap.del({"n", "v", "o"}, "<C-s>")
-- vim.keymap.set({"n", "v", "o"}, '<C-s>', '<cmd>Telescope live_grep<cr>')
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 ({
{ "<C-s>", "<cmd>Telescope live_grep<cr>" , desc = "Swiper", mode = "n" },
-- This does not allow you to make a new file only search existing, but good enough for now.
{ "<leader><C-f>", "<cmd>Telescope find_files<cr>" , 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
{ "<leader>b", "<cmd>Telescope oldfiles<cr>" , desc = "Recently opened files", mode = "n" },
{ "<leader><C-b>", "<cmd>Telescope buffers<cr>" , desc = "Buffers", mode = "n" },
{ "<leader>k", "<cmd>bp|bd#<cr>" , desc = "Close current buffer", mode = "n" },
{ "<leader>0", "<cmd>close<cr>", desc = "Close focused window" },
{ "<leader>2", "<cmd>split<cr>", desc = "Split window horizontally" },
{ "<leader>3", "<cmd>vs<cr>", desc = "Split window vertically" },
{ "<leader>o", "<cmd>wincmd w<cr>", 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
{ "<leader><C-c>", "<cmd>qa<cr>", desc = "Quit" },
{ "<leader><C-s>", "<cmd>w<cr>", desc = "Write" },
},
-- LSP/DAP Options
{
mode = { "n", "v" }, -- NORMAL and VISUAL mode
{ "<C-c>lb", function() dap.toggle_breakpoint() end, desc = "Debugger: Toggle breakpoint" },
{ "<C-c>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" },
{ "<C-c>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" },
{ "<C-c>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" },
{ "<C-c>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" },
{ "<C-c>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" },
{ "<C-c>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" },
}
})

16
lazy-lock.json Normal file
View File

@ -0,0 +1,16 @@
{
"LuaSnip": { "branch": "master", "commit": "ce0a05ab4e2839e1c48d072c5236cce846a387bc" },
"cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" },
"dashboard-nvim": { "branch": "master", "commit": "fabf5feec96185817c732d47d363f34034212685" },
"gruvbox.nvim": { "branch": "main", "commit": "7a1b23e4edf73a39642e77508ee6b9cbb8c60f9e" },
"lazy.nvim": { "branch": "main", "commit": "6ca90a21202808796418e46d3cebfbb5a44e54a2" },
"lsp-zero.nvim": { "branch": "v3.x", "commit": "87701af045b3032515776abeb47eb8c2ddb5e679" },
"mini.statusline": { "branch": "main", "commit": "ec7e2c509c7262fef85a28a772f60ebe146297db" },
"nvim-cmp": { "branch": "main", "commit": "d818fd0624205b34e14888358037fb6f5dc51234" },
"nvim-dap": { "branch": "master", "commit": "bc03b83c94d0375145ff5ac6a6dcf28c1241e06f" },
"nvim-lspconfig": { "branch": "master", "commit": "01e08d4bf1c35e5126b2ad5209725e4c552289ab" },
"nvim-web-devicons": { "branch": "master", "commit": "c0cfc1738361b5da1cd0a962dd6f774cc444f856" },
"plenary.nvim": { "branch": "master", "commit": "a3e3bc82a3f95c5ed0d7201546d5d2c19b20d683" },
"telescope.nvim": { "branch": "master", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" },
"which-key.nvim": { "branch": "main", "commit": "ed5f7622771d0b5c0ac3a5e286ec6cd17b6be131" }
}

29
lua/config/lazy.lua Normal file
View File

@ -0,0 +1,29 @@
-- Bootstrap lazy.nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
if vim.v.shell_error ~= 0 then
vim.api.nvim_echo({
{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
{ out, "WarningMsg" },
{ "\nPress any key to exit..." },
}, true, {})
vim.fn.getchar()
os.exit(1)
end
end
vim.opt.rtp:prepend(lazypath)
-- Setup lazy.nvim
require("lazy").setup({
spec = {
-- import your plugins
{ import = "plugins" },
},
-- Configure any other settings here. See the documentation for more details.
-- colorscheme that will be used when installing plugins.
install = { colorscheme = { "habamax" } },
-- automatically check for plugin updates
checker = { enabled = true },
})

View File

@ -0,0 +1 @@
return {'hrsh7th/cmp-nvim-lsp'}

View File

@ -0,0 +1,12 @@
return {
'nvimdev/dashboard-nvim',
event = 'VimEnter',
config = function()
require('dashboard').setup {
-- config
--
theme = 'hyper'
}
end,
dependencies = { {'nvim-tree/nvim-web-devicons'}}
}

1
lua/plugins/gruvbox.lua Normal file
View File

@ -0,0 +1 @@
return { "ellisonleao/gruvbox.nvim", priority = 1000 , config = true, opts = ...}

1
lua/plugins/lsp-zero.lua Normal file
View File

@ -0,0 +1 @@
return {'VonHeikemen/lsp-zero.nvim', branch = 'v3.x'}

1
lua/plugins/luasnip.lua Normal file
View File

@ -0,0 +1 @@
return {'L3MON4D3/LuaSnip'}

View File

@ -0,0 +1 @@
return { 'echasnovski/mini.statusline', version = false }

1
lua/plugins/nvim-cmp.lua Normal file
View File

@ -0,0 +1 @@
return {'hrsh7th/nvim-cmp'}

3
lua/plugins/nvim-dap.lua Normal file
View File

@ -0,0 +1,3 @@
return {
'mfussenegger/nvim-dap'
}

View File

@ -0,0 +1 @@
return {'neovim/nvim-lspconfig'}

View File

@ -0,0 +1,5 @@
return {
'nvim-telescope/telescope.nvim', tag = '0.1.8',
-- or , branch = '0.1.x',
dependencies = { 'nvim-lua/plenary.nvim' }
}

View File

@ -0,0 +1,18 @@
return {
"folke/which-key.nvim",
event = "VeryLazy",
opts = {
-- your configuration comes here
-- or leave it empty to use the default settings
-- refer to the configuration section below
},
keys = {
{
"<leader>?",
function()
require("which-key").show({ global = false })
end,
desc = "Buffer Local Keymaps (which-key)",
},
},
}

BIN
which-key-preview.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB