Last active
June 8, 2024 08:46
-
-
Save djmango/b44a651a4966662cb1fcd7f04289a2ca to your computer and use it in GitHub Desktop.
My LunarVim config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Sulaiman Khan Ghori (https://github.com/djmango) | |
-- My LunarVim configuration file | |
-- https://www.lunarvim.org/docs/configuration | |
local home = os.getenv("HOME") | |
lvim.colorscheme = "lunar" | |
lvim.format_on_save = true | |
lvim.lsp.hover = true | |
vim.opt.wrap = true -- wrap lines | |
vim.opt.timeoutlen = 300 -- faster timeout wait time. makes things feel snappier THIS BROKE IT | |
vim.env.PATH = vim.env.PATH .. | |
":/opt/homebrew/bin" -- add homebrew to path. due to sh vs zsh vs bash, this is the easiest way to do it | |
vim.opt.tabstop = 4 | |
vim.opt.shiftwidth = 4 | |
vim.opt.expandtab = true | |
-- Enable relative numbering | |
vim.opt.relativenumber = true | |
vim.opt.number = true -- This is optional but recommended to show the current line number | |
-- For some reason some plugin is overriding this so we have to set it globally on buffer load | |
vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, { | |
pattern = "*", | |
callback = function() | |
vim.opt_local.expandtab = true | |
end | |
}) | |
lvim.builtin.treesitter.indent.disable = { "yaml", "typescript", "javascript", "python", "toml" } -- treesitter is buggy :( | |
local opts = { noremap = true, silent = true } | |
-- Use an on_attach function to only map the following keys after the language server attaches to the current buffer | |
local on_attach = function(client, bufnr) | |
-- Enable completion triggered by <c-x><c-o> | |
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') | |
-- Mappings. | |
-- See `:help vim.lsp.*` for documentation on any of the below functions | |
local bufopts = { noremap = true, silent = true, buffer = bufnr } | |
-- Append individual LSP keybindings without overwriting existing mappings | |
end | |
local nvim_lsp = require 'lspconfig' | |
-- Setting up efm-langserver | |
nvim_lsp.efm.setup { | |
init_options = { documentFormatting = true }, | |
filetypes = { "markdown", "yaml", "swift" }, | |
settings = { | |
rootMarkers = { ".git/" }, | |
languages = { | |
markdown = { | |
{ formatCommand = "prettier --stdin-filepath ${INPUT}", formatStdin = true }, | |
}, | |
yaml = { | |
{ formatCommand = "prettier --stdin-filepath ${INPUT}", formatStdin = true }, | |
}, | |
swift = { | |
{ formatCommand = "swiftformat stdin --output stdout --stdinpath ${INPUT}", formatStdin = true }, | |
} | |
} | |
} | |
} | |
-- Ruff | |
-- Configure `ruff-lsp`. | |
-- See: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#ruff_lsp | |
-- For the default config, along with instructions on how to customize the settings | |
nvim_lsp.ruff_lsp.setup { | |
on_attach = on_attach, | |
} | |
require'lspconfig'.html.setup{} | |
-- vim.list_extend(lvim.lsp.automatic_configuration.skipped_servers, { "rust_analyzer" }) | |
-- Plugins | |
lvim.plugins = { | |
{ | |
"windwp/nvim-ts-autotag", | |
config = function() | |
require("nvim-ts-autotag").setup() | |
end, | |
}, | |
{ | |
"mrcjkb/rustaceanvim", | |
version = "^4", | |
ft = { "rust" }, | |
config = function() | |
vim.g.rustaceanvim = { | |
server = { | |
on_attach = require("lvim.lsp").common_on_attach | |
}, | |
} | |
end, | |
}, | |
{ "mattn/efm-langserver" }, | |
{ | |
"zbirenbaum/copilot.lua", | |
cmd = "Copilot", | |
event = "InsertEnter", | |
config = function() | |
require("copilot").setup({ | |
suggestion = { | |
auto_trigger = true, | |
keymap = { | |
accept = "<M-l>", | |
accept_word = "<M-;>", | |
next = "<M-]>", | |
prev = "<M-[>" | |
} | |
}, | |
filetypes = { ["*"] = true } | |
}) | |
end, | |
}, | |
{ | |
"ggandor/leap.nvim", | |
name = "leap", | |
config = function() | |
require("leap").add_default_mappings() | |
require("leap").add_repeat_mappings(';', ',', { | |
-- False by default. If set to true, the keys will work like the | |
-- native semicolon/comma, i.e., forward/backward is understood in | |
-- relation to the last motion. | |
relative_directions = true, | |
-- By default, all modes are included. | |
modes = { 'n', 'x', 'o' }, | |
}) | |
end, | |
}, | |
{ | |
"kylechui/nvim-surround", | |
config = function() | |
require("nvim-surround").setup({}) | |
end | |
}, | |
{ | |
"folke/todo-comments.nvim", | |
event = "BufRead", | |
config = function() | |
require("todo-comments").setup() | |
end, | |
}, | |
{ | |
"gbprod/substitute.nvim", | |
config = function() | |
require("substitute").setup() | |
end, | |
}, | |
{ | |
"windwp/nvim-spectre", | |
event = "BufRead", | |
config = function() | |
require("spectre").setup() | |
end, | |
}, | |
{ | |
"sindrets/diffview.nvim", | |
event = "BufRead", | |
}, | |
{ | |
"gelguy/wilder.nvim", | |
config = function() | |
require("wilder").setup { | |
modes = { | |
"/", | |
"?", | |
":" | |
}, | |
} | |
end, | |
}, | |
{ | |
"folke/persistence.nvim", | |
event = "BufReadPre", -- this will only start session saving when an actual file was opened | |
lazy = "true", | |
config = function() | |
require("persistence").setup { | |
dir = vim.fn.expand(vim.fn.stdpath "config" .. "/session/"), | |
options = { "buffers", "curdir", "tabpages", "winsize" }, | |
} | |
end, | |
}, | |
{ | |
"folke/trouble.nvim" | |
}, | |
{ | |
"ray-x/lsp_signature.nvim", | |
config = function() | |
require("lsp_signature").setup() | |
end | |
}, | |
{ | |
"f-person/git-blame.nvim", | |
event = "BufRead", | |
config = function() | |
vim.cmd "highlight default link gitblame SpecialComment" | |
require("gitblame").setup { enabled = false } | |
end, | |
}, | |
} | |
-- Clear search highlighting with <Esc> | |
lvim.keys.normal_mode["<Esc>"] = ":noh<CR><Esc>" | |
-- Have j and k navigate visual lines rather than logical ones | |
lvim.keys.normal_mode["j"] = "gj" | |
lvim.keys.normal_mode["k"] = "gk" | |
-- Navigate telescope with Ctrl jk | |
local telescope_actions = require("telescope.actions") | |
lvim.builtin.telescope.defaults.mappings.i["<C-j>"] = telescope_actions.move_selection_next | |
lvim.builtin.telescope.defaults.mappings.i["<C-k>"] = telescope_actions.move_selection_previous | |
-- Substitute with register with gr | |
lvim.lsp.buffer_mappings.normal_mode["gr"] = { require("substitute").operator, "Substitute with register" } | |
-- this isnt working so lets try it like this | |
lvim.keys.normal_mode["gr"] = ":lua require('substitute').operator()<CR>" | |
-- Go to reference with Space + l + R | |
lvim.builtin.which_key.mappings["l"]["R"] = { "<cmd>lua require('telescope.builtin').lsp_references()<cr>", "References" } | |
-- Also with gR | |
lvim.keys.normal_mode["gR"] = "<cmd>lua require('telescope.builtin').lsp_references()<cr>" | |
-- vim.api.nvim_set_keymap('n', 'gcc', '<CMD>lua require("Comment.api").toggle.linewise.current()<CR>', { noremap = true, silent = true }) | |
-- Do the normal non telescope version of this | |
-- lvim.keys.normal_mode["gR"] = "<cmd>lua vim.lsp.buf.references()<cr>" | |
-- Open Telescope with Space + t | |
lvim.keys.normal_mode["<leader>t"] = ":Telescope<CR>" | |
-- Session management | |
lvim.builtin.which_key.mappings["S"] = { | |
name = "Session", | |
c = { "<cmd>lua require('persistence').load()<cr>", "Restore last session for current dir" }, | |
l = { "<cmd>lua require('persistence').load({ last = true })<cr>", "Restore last session" }, | |
Q = { "<cmd>lua require('persistence').stop()<cr>", "Quit without saving session" }, | |
} | |
-- Toggle Trouble with Space + D | |
lvim.builtin.which_key.mappings["D"] = { "<cmd>Trouble diagnostics<cr>", "Trouble" } | |
-- Toggle undotree with Space + U | |
lvim.builtin.which_key.mappings["U"] = { "<cmd>UndotreeToggle<cr>", "Undo Tree" } | |
-- Open Spectre with Space + F | |
lvim.builtin.which_key.mappings["F"] = { "<cmd>Spectre<cr>", "Spectre" } | |
-- Function to toggle LSP signs | |
local zen_mode_active = false | |
function ToggleZenMode() | |
if zen_mode_active then | |
-- Re-enable LSP signs | |
vim.diagnostic.config({ virtual_text = true, signs = true }) | |
zen_mode_active = false | |
print("Zen Mode disabled") | |
else | |
-- Disable LSP signs | |
vim.diagnostic.config({ virtual_text = false, signs = false }) | |
zen_mode_active = true | |
print("Zen Mode enabled") | |
end | |
end | |
-- Keybinding for Zen Mode | |
lvim.keys.normal_mode["<leader>z"] = ":lua ToggleZenMode()<CR>" | |
-- Keybinding for moving to the start and end of the line | |
lvim.keys.normal_mode["H"] = "^" | |
lvim.keys.normal_mode["L"] = "g_" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment