Created
October 14, 2024 08:54
-
-
Save ALF-er/93a05bab8ae861114840f094dcd8765f to your computer and use it in GitHub Desktop.
Nvim config (awfully not finished)
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
-- Keymaps for better default experience | |
vim.keymap.set({ "n", "v" }, "<Space>", "<Nop>", { silent = true }) | |
-- Must happen before plugins are required (otherwise wrong leader will be used) | |
vim.g.mapleader = " " | |
vim.g.maplocalleader = " " | |
-- [[ Setting options ]] | |
-- See `:help vim.o` | |
-- Set highlight on search | |
vim.o.hlsearch = false | |
-- Make line numbers default | |
vim.wo.number = true | |
vim.opt.relativenumber = true | |
-- Highlight line with cursor | |
vim.opt.cursorline = true | |
vim.opt.cursorlineopt = "both" | |
-- Enable mouse mode | |
vim.o.mouse = "a" | |
-- Enable break indent | |
vim.o.breakindent = true | |
-- Save undo history | |
-- NOTE: ends up in ~\AppData\Local\nvim-data\undo | |
vim.opt.undofile = true | |
-- Case-insensitive searching UNLESS \C or capital in search | |
vim.o.ignorecase = true | |
vim.o.smartcase = true | |
-- Keep signcolumn on by default | |
vim.wo.signcolumn = "yes:1" | |
-- Decrease update time | |
vim.o.updatetime = 250 | |
vim.o.timeout = true | |
vim.o.timeoutlen = 300 | |
-- Set completeopt to have a better completion experience | |
vim.o.completeopt = "menuone,noselect" | |
-- You should make sure your terminal supports this | |
vim.o.termguicolors = true | |
-- Hide mode in command line | |
vim.o.showmode = false | |
-- Hide ruler in command line | |
vim.o.ruler = false | |
-- Disable folding | |
vim.opt.foldenable = false | |
vim.opt.foldmethod = "manual" | |
vim.opt.foldlevelstart = 99 | |
-- Keep more context on screen while scrolling | |
vim.opt.scrolloff = 2 | |
-- Disable word wraps | |
vim.opt.wrap = false | |
-- Disable any beeping | |
vim.opt.visualbell = true | |
-- In completion, when there is more than one match, | |
-- list all matches, and only complete to longest common match | |
vim.opt.wildmode = "list:longest" | |
-- don't suggest files like there: | |
vim.opt.wildignore = ".hg,.svn,*~,*.png,*.jpg,*.gif,*.min.js,*.swp,*.o,vendor,dist,_site" | |
-- Ignore whitespace in diff (nvim -d) | |
vim.opt.diffopt:append("iwhite") | |
-- Use a smarter algorithm for diffs | |
-- https://vimways.org/2018/the-power-of-diff/ | |
-- https://stackoverflow.com/questions/32365271/whats-the-difference-between-git-diff-patience-and-git-diff-histogram | |
-- https://luppeng.wordpress.com/2020/10/10/when-to-use-each-of-the-git-diff-algorithms/ | |
vim.opt.diffopt:append("algorithm:histogram") | |
vim.opt.diffopt:append("indent-heuristic") | |
-- Whitespace chars | |
vim.opt.list = true | |
vim.opt.listchars:append("space:⋅") | |
vim.opt.listchars:append("eol:↴") | |
vim.opt.listchars:append("tab:>-") | |
-- Disable providers | |
vim.g.loaded_python3_provider = 0 | |
vim.g.loaded_ruby_provider = 0 | |
vim.g.loaded_node_provider = 0 | |
vim.g.loaded_perl_provider = 0 | |
-- Indicate explicitly that we have Nerd Font | |
vim.g.have_nerd_font = true | |
-- Setup diagnostics (at the end of each line) | |
vim.diagnostic.config({ | |
severity_sort = true, | |
virtual_text = { | |
source = true, | |
prefix = "▎", | |
spacing = 2, | |
}, | |
}) | |
-- [[ Basic Keymaps ]] | |
-- Disable arrow keys - force yourself to use the home row | |
vim.keymap.set("n", "<up>", "<nop>") | |
vim.keymap.set("n", "<down>", "<nop>") | |
vim.keymap.set("i", "<up>", "<nop>") | |
vim.keymap.set("i", "<down>", "<nop>") | |
vim.keymap.set("i", "<left>", "<nop>") | |
vim.keymap.set("i", "<right>", "<nop>") | |
-- but let left/right to switch buffers | |
vim.keymap.set("n", "<left>", ":bp<cr>") | |
vim.keymap.set("n", "<right>", ":bn<cr>") | |
-- I don't use this | |
vim.keymap.set("n", "Q", "<Nop>") | |
-- Remap for dealing with word wrap | |
vim.keymap.set("n", "k", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true }) | |
vim.keymap.set("n", "j", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true }) | |
-- Move line up or down | |
vim.keymap.set("v", "K", ":m '<-2<CR>gv=gv", { desc = "Move line up" }) | |
vim.keymap.set("v", "J", ":m '>+1<CR>gv=gv", { desc = "Move line down" }) | |
-- Center view when scrolled up or down | |
vim.keymap.set("n", "<C-u>", "<C-u>zz") | |
vim.keymap.set("n", "<C-d>", "<C-d>zz") | |
-- Diagnostic keymaps | |
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, { desc = "Go to previous diagnostic message" }) | |
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, { desc = "Go to next diagnostic message" }) | |
vim.keymap.set("n", "<leader>e", vim.diagnostic.open_float, { desc = "Open floating diagnostic message" }) | |
vim.keymap.set("n", "<leader>q", vim.diagnostic.setloclist, { desc = "Open diagnostics list" }) | |
-- [[ Highlight on yank ]] | |
-- See `:help vim.highlight.on_yank()` | |
local highlight_group = vim.api.nvim_create_augroup("YankHighlight", { clear = true }) | |
vim.api.nvim_create_autocmd("TextYankPost", { | |
callback = function() | |
vim.highlight.on_yank() | |
end, | |
group = highlight_group, | |
pattern = "*", | |
}) | |
-- [[ Package manager ]] | |
-- `:help lazy.nvim.txt` for more info | |
local lazypath = vim.fn.stdpath "data" .. "/lazy/lazy.nvim" | |
if not vim.loop.fs_stat(lazypath) then | |
vim.fn.system { | |
"git", | |
"clone", | |
"--filter=blob:none", | |
"https://github.com/folke/lazy.nvim.git", | |
"--branch=stable", | |
lazypath, | |
} | |
end | |
vim.opt.rtp:prepend(lazypath) | |
require("lazy").setup({ | |
-- Colorscheme | |
{ | |
"shaunsingh/nord.nvim", | |
lazy = false, | |
priority = 1000, | |
config = function() | |
vim.g.nord_contrast = true | |
vim.g.nord_borders = true | |
vim.g.nord_disable_background = false | |
vim.g.nord_enable_sidebar_background = true | |
vim.g.nord_italic = false | |
vim.g.nord_bold = false | |
vim.g.nord_uniform_diff_background = true | |
vim.cmd("colorscheme nord") | |
-- TODO: Consider forking shaunsingh/nord.nvim to define own highlight groups | |
-- Highlight cursorline in status column | |
vim.cmd("highlight! link CursorLineNr CursorLine") | |
vim.cmd("highlight! link CursorLineSign CursorLine") | |
-- Diagnostic signs on the sign column | |
local cursorline_hlg = vim.api.nvim_get_hl(0, { name = "CursorLine", link = false }) | |
for _, severity in ipairs({ "Error", "Warn", "Hint", "Info" }) do | |
local diagnostic_name = "DiagnosticSign" .. severity | |
local diagnostic_hlg = vim.api.nvim_get_hl(0, { name = diagnostic_name, link = false }) | |
cursorline_hlg.fg = diagnostic_hlg.fg | |
vim.api.nvim_set_hl(0, diagnostic_name .. "CursorLine", cursorline_hlg) | |
vim.fn.sign_define(diagnostic_name, { | |
text = "▐", | |
texthl = diagnostic_name, | |
culhl = diagnostic_name .. "CursorLine", | |
}) | |
end | |
end, | |
}, | |
-- Highlight, edit, and navigate code | |
{ | |
"nvim-treesitter/nvim-treesitter", | |
dependencies = { | |
"nvim-treesitter/nvim-treesitter-textobjects", | |
}, | |
build = ":TSUpdate", | |
config = function() | |
require("nvim-treesitter.install").prefer_git = false | |
vim.defer_fn(function () | |
require("nvim-treesitter.configs").setup({ | |
ensure_installed = { "lua", "tsx", "typescript", "javascript", "vimdoc", "vim", "zig", "bash", "markdown", "markdown_inline" }, | |
ignore_install = {}, | |
sync_install = false, | |
auto_install = false, | |
highlight = { enable = true }, | |
incremental_selection = { enable = false }, | |
indent = { enable = true }, | |
textobjects = { | |
swap = { | |
enable = true, | |
swap_next = { | |
["<leader>a"] = { query = "@parameter.inner", desc = "Swap parameter with next one" }, | |
}, | |
swap_previous = { | |
["<leader>A"] = { query = "@parameter.inner", desc = "Swap parameter with prev one" }, | |
}, | |
}, | |
select = { | |
enable = true, | |
lookahead = true, | |
include_surrounding_whitespace = true, | |
keymaps = { | |
["aa"] = { query = "@parameter.outer", desc = "Select outer parameter" }, | |
["ia"] = { query = "@parameter.inner", desc = "Select inner parameter" }, | |
["af"] = { query = "@function.outer", desc = "Select outer function" }, | |
["if"] = { query = "@function.inner", desc = "Select inner function" }, | |
["ac"] = { query = "@comment.outer", desc = "Select outer comment" }, | |
["ic"] = { query = "@comment.inner", desc = "Select inner comment" }, | |
}, | |
}, | |
move = { | |
enable = true, | |
set_jumps = true, | |
goto_next_start = { | |
["]m"] = { query = "@function.outer", desc = "Go to start of next function" }, | |
}, | |
goto_next_end = { | |
["]M"] = { query = "@function.outer", desc = "Go to end of next function" }, | |
}, | |
goto_previous_start = { | |
["[m"] = { query = "@function.outer", desc = "Go to start of prev function" }, | |
}, | |
goto_previous_end = { | |
["[M"] = { query = "@function.outer", desc = "Go to end of prev function" }, | |
}, | |
}, | |
}, | |
}) | |
end, 0) | |
end, | |
}, | |
-- Fuzzy Finder (files, lsp, etc) | |
{ | |
"nvim-telescope/telescope.nvim", | |
dependencies = { | |
"nvim-lua/plenary.nvim", | |
-- Fuzzy Finder Algorithm which requires local dependencies to be built. | |
{ | |
"nvim-telescope/telescope-fzf-native.nvim", | |
build = "make", | |
cond = function() | |
return vim.fn.executable("make") == 1 | |
end, | |
config = function() | |
pcall(require("telescope").load_extension, "fzf") | |
end, | |
}, | |
}, | |
keys = { | |
-- See `:help telescope.builtin` | |
{ | |
"<leader>?", | |
id = "<leader>?", | |
function() | |
return require("telescope.builtin").oldfiles() | |
end, | |
desc = "[?] Find recently opened files", | |
}, | |
{ | |
"<leader><space>", | |
id = "<leader><space>", | |
function() | |
return require("telescope.builtin").buffers() | |
end, | |
desc = "[ ] Find existing buffers", | |
}, | |
{ | |
"<leader>/", | |
id = "<leader>/", | |
function() | |
return require("telescope.builtin").current_buffer_fuzzy_find( | |
require("telescope.themes").get_dropdown { | |
winblend = 10, | |
previewer = false, | |
} | |
) | |
end, | |
desc = "[/] Fuzzily search in current buffer", | |
}, | |
{ | |
"<leader>sf", | |
id = "<leader>sf", | |
function() | |
return require("telescope.builtin").find_files() | |
end, | |
desc = "[S]earch [F]iles", | |
}, | |
{ | |
"<leader>sh", | |
id = "<leader>sh", | |
function() | |
return require("telescope.builtin").help_tags() | |
end, | |
desc = "[S]earch [H]elp", | |
}, | |
{ | |
"<leader>sw", | |
function() | |
return require("telescope.builtin").grep_string() | |
end, | |
desc = "[S]earch current [W]ord", | |
}, | |
{ | |
"<leader>sg", | |
function() | |
return require("telescope.builtin").live_grep() | |
end, | |
desc = "[S]earch by [G]rep", | |
}, | |
{ | |
"<leader>sd", | |
function() | |
return require("telescope.builtin").diagnostics() | |
end, | |
desc = "[S]earch [D]iagnostics", | |
}, | |
{ | |
"<leader>sr", | |
function() | |
return require("telescope.builtin").resume() | |
end, | |
desc = "[S]earch [R]esume", | |
}, | |
{ | |
"<leader>gf", | |
function() | |
return require("telescope.builtin").git_files() | |
end, | |
desc = "Search [G]it [F]iles", | |
}, | |
{ | |
"<leader>gr", | |
function() | |
return require("telescope.builtin").lsp_references() | |
end, | |
desc = "[G]oto [R]eferences", | |
}, | |
{ | |
"<leader>gI", | |
function() | |
return require("telescope.builtin").lsp_implementations() | |
end, | |
desc = "[G]oto [I]mplementation", | |
}, | |
{ | |
"<leader>ds", | |
function() | |
return require("telescope.builtin").lsp_document_symbols() | |
end, | |
desc = "[D]ocument [S]ymbols", | |
}, | |
{ | |
"<leader>ws", | |
function() | |
return require("telescope.builtin").lsp_dynamic_workspace_symbols() | |
end, | |
desc = "[W]orkspace [S]ymbols", | |
}, | |
}, | |
config = true, | |
}, | |
-- LSP Configuration & Plugins | |
{ | |
"neovim/nvim-lspconfig", | |
dependencies = { | |
{ | |
"j-hui/fidget.nvim", | |
event = "LspAttach", | |
config = true, | |
}, | |
{ | |
"folke/neodev.nvim", | |
config = true, | |
}, | |
{ | |
"williamboman/mason.nvim", | |
config = true, | |
}, | |
{ | |
"williamboman/mason-lspconfig.nvim", | |
opts = { | |
handlers = { | |
function(server_name) | |
require("lspconfig")[server_name].setup({ | |
capabilities = require("cmp_nvim_lsp").default_capabilities( | |
vim.lsp.protocol.make_client_capabilities() | |
), | |
on_init = function(client) | |
if client.server_capabilities then | |
client.server_capabilities.documentFormattingProvider = false | |
client.server_capabilities.semanticTokensProvider = false | |
end | |
end, | |
on_attach = function(_, buffer) | |
local nmap = function(keys, func, desc) | |
vim.keymap.set("n", keys, func, { buffer = buffer, desc = desc }) | |
end | |
nmap("K", vim.lsp.buf.hover, "Hover Documentation") | |
nmap("<C-k>", vim.lsp.buf.signature_help, "Signature Documentation") | |
nmap("gd", vim.lsp.buf.definition, "[G]oto [D]efinition") | |
nmap("gD", vim.lsp.buf.declaration, "[G]oto [D]eclaration") | |
nmap("<leader>rn", vim.lsp.buf.rename, "[R]e[n]ame") | |
nmap("<leader>ca", vim.lsp.buf.code_action, "[C]ode [A]ction") | |
nmap("<leader>D", vim.lsp.buf.type_definition, "Type [D]efinition") | |
nmap("<leader>wa", vim.lsp.buf.add_workspace_folder, "[W]orkspace [A]dd Folder") | |
nmap("<leader>wr", vim.lsp.buf.remove_workspace_folder, "[W]orkspace [R]emove Folder") | |
nmap( | |
"<leader>wl", | |
function() | |
print(vim.inspect(vim.lsp.buf.list_workspace_folders())) | |
end, | |
"[W]orkspace [L]ist Folders" | |
) | |
end, | |
settings = ({ | |
["lua_ls"] = { | |
Lua = { | |
workspace = { checkThirdParty = false }, | |
}, | |
}, | |
})[server_name], | |
}) | |
end, | |
}, | |
}, | |
}, | |
}, | |
}, | |
-- Autocompletion | |
{ | |
"hrsh7th/nvim-cmp", | |
dependencies = { | |
"hrsh7th/cmp-nvim-lsp", | |
"L3MON4D3/LuaSnip", | |
"saadparwaiz1/cmp_luasnip", | |
}, | |
event = "InsertEnter", | |
config = function() | |
local cmp = require("cmp") | |
local luasnip = require("luasnip") | |
luasnip.config.setup({}) | |
cmp.setup({ | |
snippet = { | |
expand = function(args) | |
luasnip.lsp_expand(args.body) | |
end, | |
}, | |
mapping = cmp.mapping.preset.insert({ | |
["<C-d>"] = cmp.mapping.scroll_docs(4), | |
["<C-u>"] = cmp.mapping.scroll_docs(-4), | |
["<C-Space>"] = cmp.mapping.complete(), | |
["<CR>"] = cmp.mapping.confirm({ | |
behavior = cmp.ConfirmBehavior.Replace, | |
select = true, | |
}), | |
["<Tab>"] = cmp.mapping( | |
function(fallback) | |
if cmp.visible() then | |
cmp.select_next_item() | |
elseif luasnip.expand_or_locally_jumpable() then | |
luasnip.expand_or_jump() | |
else | |
fallback() | |
end | |
end, | |
{ "i", "s" } | |
), | |
["<S-Tab>"] = cmp.mapping( | |
function(fallback) | |
if cmp.visible() then | |
cmp.select_prev_item() | |
elseif luasnip.locally_jumpable(-1) then | |
luasnip.jump(-1) | |
else | |
fallback() | |
end | |
end, | |
{ "i", "s" } | |
), | |
}), | |
sources = { | |
{ name = "nvim_lsp" }, | |
{ name = "luasnip" }, | |
}, | |
}) | |
end, | |
}, | |
-- Git related plugins | |
{ | |
"tpope/vim-fugitive", | |
event = "VeryLazy", | |
}, | |
{ | |
"tpope/vim-rhubarb", | |
event = "VeryLazy", | |
}, | |
-- Adds git releated signs to the signcolumn, as well as utilities for managing changes | |
{ | |
"lewis6991/gitsigns.nvim", | |
event = "VeryLazy", | |
opts = { | |
signs = { | |
untracked = { text = "▌" }, | |
add = { text = "▌" }, | |
change = { text = "▌" }, | |
delete = { text = "▁" }, | |
topdelete = { text = "▔" }, | |
changedelete = { text = "▌" }, | |
}, | |
sign_priority = 10, | |
}, | |
}, | |
-- Statusline | |
{ | |
"freddiehaddad/feline.nvim", | |
config = function() | |
local nord_colors = require("nord.named_colors") | |
local theme = { | |
fg = nord_colors.white, | |
bg = nord_colors.black, | |
black = nord_colors.black, | |
skyblue = nord_colors.off_blue, | |
cyan = nord_colors.teal, | |
green = nord_colors.green, | |
oceanblue = nord_colors.blue, | |
magenta = nord_colors.purple, | |
orange = nord_colors.orange, | |
red = nord_colors.red, | |
violet = nord_colors.glacier, | |
white = nord_colors.white, | |
yellow = nord_colors.yellow, | |
} | |
local vi_mode_colors = { | |
["NORMAL"] = nord_colors.off_blue, | |
["OP"] = nord_colors.off_blue, | |
["INSERT"] = nord_colors.white, | |
["VISUAL"] = nord_colors.teal, | |
["LINES"] = nord_colors.teal, | |
["BLOCK"] = nord_colors.teal, | |
["REPLACE"] = nord_colors.yellow, | |
["V-REPLACE"] = nord_colors.yellow, | |
["ENTER"] = nord_colors.orange, | |
["MORE"] = nord_colors.orange, | |
["SELECT"] = nord_colors.red, | |
["COMMAND"] = nord_colors.purple, | |
["SHELL"] = nord_colors.purple, | |
["TERM"] = nord_colors.green, | |
["NONE"] = nord_colors.yellow, | |
} | |
local vi_mode = { | |
provider = function() | |
return vim.api.nvim_get_mode().mode:upper() | |
end, | |
hl = function() | |
return { | |
fg = "bg", | |
bg = require("feline.providers.vi_mode").get_mode_color(), | |
style = "bold", | |
} | |
end, | |
left_sep = "block", | |
right_sep = "block", | |
} | |
local git_branch = { | |
provider = "git_branch", | |
hl = { | |
fg = nord_colors.darker_white, | |
}, | |
left_sep = " ", | |
} | |
local file_info = { | |
provider = "file_info", | |
opts = { | |
type = "unique", | |
colored_icon = false, | |
}, | |
hl = { | |
fg = nord_colors.darkest_white, | |
}, | |
left_sep = " ", | |
} | |
local diagnostic_errors = { | |
provider = "diagnostic_errors", | |
hl = "DiagnosticSignError", | |
icon = "▎", | |
right_sep = " ", | |
} | |
local diagnostic_warnings = { | |
provider = "diagnostic_warnings", | |
hl = "DiagnosticSignWarn", | |
icon = "▎", | |
right_sep = " ", | |
} | |
local diagnostic_hints = { | |
provider = "diagnostic_hints", | |
hl = "DiagnosticSignHint", | |
icon = "▎", | |
right_sep = " ", | |
} | |
local diagnostic_info = { | |
provider = "diagnostic_info", | |
hl = "DiagnosticSignInfo", | |
icon = "▎", | |
right_sep = " ", | |
} | |
local components = { | |
active = { | |
{ | |
vi_mode, | |
git_branch, | |
file_info, | |
}, | |
{ | |
diagnostic_errors, | |
diagnostic_warnings, | |
diagnostic_hints, | |
diagnostic_info, | |
}, | |
}, | |
inactive = { | |
{ | |
vi_mode, | |
git_branch, | |
file_info, | |
}, | |
{}, | |
}, | |
} | |
require("feline").setup({ | |
components = components, | |
theme = theme, | |
vi_mode_colors = vi_mode_colors, | |
}) | |
end, | |
}, | |
-- Detect tabstop and shiftwidth automatically | |
{ | |
"tpope/vim-sleuth", | |
event = "VeryLazy", | |
}, | |
-- "gc" to comment visual regions/lines | |
{ | |
"numToStr/Comment.nvim", | |
event = "VeryLazy", | |
config = true, | |
}, | |
-- Surround some text with any brackets, parenthesies, tags etc | |
{ | |
"kylechui/nvim-surround", | |
event = "VeryLazy", | |
config = true, | |
}, | |
-- Autotrim postspaces and multiple blank lines | |
{ | |
"cappyzawa/trim.nvim", | |
event = "VeryLazy", | |
opts = { | |
patterns = { | |
[[%s/\(\n\n\)\n\+/\1/]], | |
}, | |
}, | |
}, | |
-- Improved % | |
{ | |
"andymass/vim-matchup", | |
event = "VeryLazy", | |
config = function() | |
vim.g.matchup_matchparen_offscreen = { method = "popup" } | |
end, | |
}, | |
-- Automatically cd to root of git project | |
"notjedi/nvim-rooter.lua", | |
-- Which key | |
{ | |
"Cassin01/wf.nvim", | |
dependencies = { | |
"nvim-tree/nvim-web-devicons", | |
}, | |
event = "VeryLazy", | |
config = function() | |
require("wf").setup({ | |
theme = "default", | |
}) | |
vim.keymap.set( | |
{ "n", "v" }, | |
"<leader>", | |
require("wf.builtin.which_key")(), | |
{ | |
noremap = true, | |
silent = true, | |
desc = "wf.which_key", | |
} | |
) | |
end, | |
}, | |
}, { | |
-- ui = { | |
-- icons = { | |
-- cmd = "⌘", | |
-- config = "🛠", | |
-- event = "📅", | |
-- ft = "📂", | |
-- init = "⚙", | |
-- keys = "🗝", | |
-- plugin = "🔌", | |
-- runtime = "💻", | |
-- source = "📄", | |
-- start = "🚀", | |
-- task = "📌", | |
-- lazy = "💤 ", | |
-- }, | |
-- }, | |
}) | |
-- The line beneath this is called `modeline`. See `:help modeline` | |
-- vim: ts=4 sts=4 sw=4 noet |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment