dotfiles/data/nvim/init.lua

579 lines
13 KiB
Lua
Raw Permalink Normal View History

2023-03-12 03:28:32 +00:00
-- https://neovim.io/doc/user/lua-guide.html
vim.opt.completeopt = { "menuone", "noinsert", "noselect" }
2022-09-21 03:37:23 +00:00
vim.opt.swapfile = false
vim.opt.title = true
vim.opt.virtualedit = "block"
vim.opt.whichwrap = "<,>,[,]"
2023-05-19 09:43:12 +00:00
-- Case character
vim.opt.ignorecase = true
vim.opt.smartcase = true
2022-09-21 03:37:23 +00:00
-- Line number
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.scrolloff = 4
2023-07-06 08:29:18 +00:00
vim.opt.signcolumn = "number"
2022-09-21 03:37:23 +00:00
-- Tab
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
vim.opt.expandtab = true
-- Wrap
vim.opt.breakindent = true
2023-03-20 06:22:29 +00:00
-- Clipboard support
vim.opt.clipboard = "unnamedplus"
2023-03-20 06:22:29 +00:00
2022-09-21 03:37:23 +00:00
-- Mouse support
vim.opt.mouse = "a"
2023-10-05 19:13:12 +00:00
vim.opt.mousemodel = "popup"
2023-09-07 09:19:15 +00:00
vim.opt.mousescroll = "ver:4,hor:6"
2022-09-21 03:37:23 +00:00
2024-03-18 11:43:15 +00:00
-- Annoying
vim.cmd([[aunmenu PopUp.How-to\ disable\ mouse]])
vim.cmd([[aunmenu PopUp.-1-]])
2022-09-21 03:37:23 +00:00
-- Workaround
-- https://github.com/neovim/neovim/issues/16416
2023-07-04 06:23:12 +00:00
-- https://github.com/rafamadriz/dotfiles/commit/1298a91558a7def5866ebee3a0b13899a6d1a78e
vim.keymap.set("i", "<C-c>", "<C-c>")
2022-09-21 03:37:23 +00:00
2023-07-07 08:25:50 +00:00
-- Typo
vim.cmd("command W w")
vim.cmd("command Q q")
vim.cmd("command WQ wq")
vim.cmd("command Wq wq")
2023-07-22 17:23:03 +00:00
vim.cmd("command Qa qa")
2023-07-07 08:25:50 +00:00
2023-07-07 06:46:28 +00:00
-- Leader
vim.g.mapleader = ";"
vim.keymap.set("n", "'", "<Leader>", { remap = true })
2023-07-07 06:46:28 +00:00
-- Keymap
2023-10-02 16:33:21 +00:00
vim.keymap.set("n", "<Leader>w", ":w<CR>")
2023-07-07 06:46:28 +00:00
vim.keymap.set("n", "n", "nzz")
vim.keymap.set("n", "N", "Nzz")
2023-07-07 09:59:07 +00:00
vim.keymap.set("n", "{", "{zz")
vim.keymap.set("n", "}", "}zz")
2023-08-28 04:46:23 +00:00
-- Unnamed register aka black hole to not push to register aka trigger yank
vim.keymap.set({ "n", "v" }, "<Leader>d", '"_d')
vim.keymap.set({ "n", "v" }, "<Leader>c", '"_c')
vim.keymap.set({ "n", "v" }, "<Leader>x", '"_x')
2023-09-06 12:02:33 +00:00
-- Conflict with :q
-- https://neovim.io/doc/user/cmdline.html#c_CTRL-F
vim.keymap.set({ "n", "v" }, "q:", "<Nop>")
2023-09-06 12:02:33 +00:00
2023-08-28 04:46:23 +00:00
-- Conflict with QMK Space Cadet
vim.keymap.set({ "n", "v" }, "(", "<Nop>")
vim.keymap.set({ "n", "v" }, ")", "<Nop>")
2023-04-18 03:52:55 +00:00
2023-08-28 04:46:23 +00:00
-- Disable scrolling
-- https://neovim.io/doc/user/scroll.html
vim.keymap.set({ "n", "v" }, "<C-e>", "<Nop>")
vim.keymap.set({ "n", "v" }, "<C-d>", "<Nop>")
vim.keymap.set({ "n", "v" }, "<C-f>", "<Nop>")
vim.keymap.set({ "n", "v" }, "<C-y>", "<Nop>")
vim.keymap.set({ "n", "v" }, "<C-u>", "<Nop>")
vim.keymap.set({ "n", "v" }, "<C-b>", "<Nop>")
2023-08-28 04:46:23 +00:00
2024-04-30 07:36:23 +00:00
-- Disable more
vim.g.loaded_python3_provider = 0
vim.g.loaded_ruby_provider = 0
vim.g.loaded_node_provider = 0
vim.g.loaded_perl_provider = 0
2023-06-17 04:20:37 +00:00
-- https://github.com/folke/lazy.nvim
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",
2023-06-17 04:53:00 +00:00
"--branch=stable",
2023-06-17 04:20:37 +00:00
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
2022-09-21 03:37:23 +00:00
2023-06-17 04:20:37 +00:00
require("lazy").setup({
2023-06-30 08:08:46 +00:00
-- Colorschemes
-- https://github.com/catppuccin/nvim
2023-06-29 18:04:45 +00:00
{
2023-06-30 08:08:46 +00:00
"catppuccin/nvim",
name = "catppuccin",
priority = 1000,
2023-06-29 18:04:45 +00:00
config = function()
2023-06-30 08:08:46 +00:00
require("catppuccin").setup({
2023-08-06 07:26:21 +00:00
flavour = "mocha",
transparent_background = false,
custom_highlights = function(colors)
2024-02-29 15:17:14 +00:00
-- Eva-01 vibe
-- https://enjoykeycap.github.io/docs/gmk-keycaps/Mecha-01/
-- https://www.pantone.com/connect/802-C
-- https://www.pantone.com/connect/267-C
local color_eva = {
fg = "#44d62c",
bg = "#5f249e",
}
return {
2024-02-29 15:17:14 +00:00
-- Help my eyes
Comment = {
fg = colors.overlay2,
},
LineNr = {
fg = colors.overlay1,
},
ExtraWhitespace = {
bg = color_eva.bg,
},
markdownLinkText = {
style = {},
},
2023-10-28 17:57:26 +00:00
-- Support mini.statusline
StatusLineNC = {
fg = colors.flamingo,
},
2024-03-28 05:45:33 +00:00
-- Support gitsigns.nvim
GitSignsCurrentLineBlame = {
fg = colors.overlay1,
style = { "italic" },
},
2024-02-29 15:17:14 +00:00
-- https://neovim.io/doc/user/diagnostic.html#diagnostic-highlights
DiagnosticVirtualTextError = color_eva,
DiagnosticSignError = color_eva,
}
end,
2023-06-30 08:08:46 +00:00
})
2023-08-06 07:26:21 +00:00
vim.cmd("colorscheme catppuccin")
2023-06-29 18:04:45 +00:00
end,
2023-09-15 08:18:57 +00:00
},
-- https://codeberg.org/ibhagwan/fzf-lua.git
2023-07-04 04:19:40 +00:00
{
url = "https://codeberg.org/ibhagwan/fzf-lua.git",
keys = {
{ "<Leader>f", ":FzfLua files<CR>" },
{ "<Leader>l", ":FzfLua blines<CR>" },
{ "<Leader>rg", ":FzfLua live_grep_resume<CR>" },
{ "<Leader>g", ":FzfLua git_status<CR>" },
{ "<Space>s", ":FzfLua lsp_document_symbols<CR>" },
{ "<Space>r", ":FzfLua lsp_references<CR>" },
{ "gr", ":FzfLua lsp_references<CR>" },
{ "<Space>i", ":FzfLua lsp_implementations<CR>" },
{ "gi", ":FzfLua lsp_implementations<CR>" },
{ "<Space>ca", ":FzfLua lsp_code_actions previewer=false<CR>" },
},
2023-07-04 04:19:40 +00:00
dependencies = {
"neovim/nvim-lspconfig",
},
2023-07-04 06:23:12 +00:00
config = function()
2024-02-28 08:52:15 +00:00
require("fzf-lua").setup({
"fzf-native",
winopts = {
preview = {
wrap = "wrap",
},
},
2024-05-06 03:22:54 +00:00
defaults = {
formatter = "path.filename_first",
},
2024-02-28 08:52:15 +00:00
})
2023-07-04 06:23:12 +00:00
end,
2023-07-04 04:19:40 +00:00
},
2022-09-21 03:37:23 +00:00
-- https://github.com/hrsh7th/nvim-cmp
{
"hrsh7th/nvim-cmp",
event = "InsertEnter",
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
},
config = function()
local cmp = require("cmp")
cmp.setup({
-- Custom
completion = {
autocomplete = false,
},
preselect = cmp.PreselectMode.None,
-- Largely copy from GitHub
snippet = {
expand = function(args)
vim.snippet.expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
["<C-Space>"] = cmp.mapping.complete(),
["<CR>"] = cmp.mapping.confirm(),
["<C-e>"] = cmp.mapping.abort(),
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
}, {
{
name = "buffer",
option = {
-- All buffers
get_bufnrs = function()
return vim.api.nvim_list_bufs()
end,
},
},
}),
})
end,
},
2023-04-12 07:09:54 +00:00
-- https://github.com/nvim-tree/nvim-tree.lua
2023-06-17 04:20:37 +00:00
{
2023-04-12 07:09:54 +00:00
"nvim-tree/nvim-tree.lua",
keys = {
{ "<C-n>", ":NvimTreeToggle<CR>" },
{ "<Leader>n", ":NvimTreeFindFile<CR>" },
},
2023-07-08 14:44:45 +00:00
init = function()
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
end,
2022-09-21 03:37:23 +00:00
config = function()
require("nvim-tree").setup({
renderer = {
2023-04-12 07:09:54 +00:00
group_empty = true,
2023-07-01 08:07:07 +00:00
root_folder_label = false,
2024-02-26 03:52:30 +00:00
indent_width = 2,
2024-02-26 03:27:32 +00:00
special_files = {
"go.mod",
"go.sum",
},
2023-02-07 10:10:22 +00:00
icons = {
show = {
2024-02-26 03:52:30 +00:00
file = false,
folder = false,
2023-02-07 10:10:22 +00:00
folder_arrow = false,
},
},
2022-09-21 03:37:23 +00:00
},
2023-05-24 07:10:08 +00:00
filters = {
2023-12-16 16:08:40 +00:00
git_ignored = false,
2023-06-29 03:28:18 +00:00
custom = {
2023-08-10 09:50:45 +00:00
"\\.bin$",
2023-08-10 17:06:56 +00:00
"\\.class$",
"\\.exe$",
"\\.hex$",
2024-02-29 11:28:46 +00:00
"\\.jpeg$",
"\\.jpg$",
2023-08-10 17:06:56 +00:00
"\\.out$",
"\\.pdf$",
2024-02-29 11:28:46 +00:00
"\\.png$",
"\\.zip$",
2023-08-10 17:06:56 +00:00
"^\\.DS_Store$",
"^\\.git$",
"^\\.idea$",
2024-02-29 11:28:46 +00:00
"^\\.ruff_cache$",
2023-08-10 17:06:56 +00:00
"^\\.vscode$",
2024-02-29 15:17:14 +00:00
"pycache",
"venv",
2023-06-29 03:28:18 +00:00
},
2023-05-24 07:10:08 +00:00
},
2022-09-21 03:37:23 +00:00
})
end,
2023-06-17 04:20:37 +00:00
},
2022-09-21 03:37:23 +00:00
-- https://github.com/lewis6991/gitsigns.nvim
{
"lewis6991/gitsigns.nvim",
config = function()
local gitsigns = require("gitsigns")
gitsigns.setup({
-- Custom
2023-07-01 09:02:34 +00:00
signs = {
untracked = { text = "" },
},
2023-07-13 14:18:53 +00:00
current_line_blame = true,
current_line_blame_opts = {
ignore_whitespace = true,
},
2024-03-28 05:45:33 +00:00
current_line_blame_formatter = "<author> <author_time:%Y-%m-%d> <summary>",
-- Largely copy from GitHub
on_attach = function(bufnr)
local function map(mode, l, r, opts)
opts = opts or {}
opts.buffer = bufnr
vim.keymap.set(mode, l, r, opts)
end
-- Navigation
map("n", "]c", function()
if vim.wo.diff then
vim.cmd.normal({ "]c", bang = true })
else
gitsigns.nav_hunk("next")
end
end)
map("n", "[c", function()
if vim.wo.diff then
vim.cmd.normal({ "[c", bang = true })
else
gitsigns.nav_hunk("prev")
end
end)
end,
})
end,
},
2023-04-26 05:57:22 +00:00
2023-07-08 11:29:01 +00:00
-- https://github.com/tpope/vim-projectionist
{
"tpope/vim-projectionist",
ft = "go",
2023-07-08 11:29:01 +00:00
init = function()
vim.g.projectionist_heuristics = {
["*.go"] = {
["*.go"] = {
alternate = "{}_test.go",
type = "source",
},
["*_generated.go"] = {
alternate = "{}_test.go",
type = "source",
},
2023-07-08 11:29:01 +00:00
["*_test.go"] = {
alternate = { "{}.go", "{}_generated.go" },
2023-07-08 11:29:01 +00:00
type = "test",
},
},
}
end,
2023-10-02 15:18:06 +00:00
config = function()
vim.keymap.set("n", "<Leader>a", ":A<CR>")
end,
2023-07-08 11:29:01 +00:00
},
2023-06-21 09:35:14 +00:00
-- https://github.com/echasnovski/mini.nvim
2023-06-17 04:20:37 +00:00
{
2023-06-21 09:35:14 +00:00
"echasnovski/mini.nvim",
2023-02-28 09:00:43 +00:00
config = function()
2023-06-21 09:35:14 +00:00
-- https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-cursorword.md
2023-04-02 18:10:10 +00:00
require("mini.cursorword").setup()
2024-03-01 15:05:55 +00:00
-- https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-hipatterns.md
local hipatterns = require("mini.hipatterns")
hipatterns.setup({
highlighters = {
hex_color = hipatterns.gen_highlighter.hex_color(),
},
})
2023-10-28 17:25:41 +00:00
-- https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-pairs.md
require("mini.pairs").setup()
2023-09-20 06:49:26 +00:00
-- https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-statusline.md
2023-10-28 17:57:26 +00:00
require("mini.statusline").setup()
2023-09-20 06:49:26 +00:00
2023-06-21 09:35:14 +00:00
-- https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-surround.md
2023-04-02 18:17:38 +00:00
require("mini.surround").setup()
2023-05-03 17:12:34 +00:00
end,
2023-06-17 04:20:37 +00:00
},
2023-05-03 17:12:34 +00:00
2022-09-21 03:37:23 +00:00
-- Programming languages
-- https://github.com/stevearc/conform.nvim
2023-07-08 14:44:45 +00:00
{
"stevearc/conform.nvim",
ft = {
2024-05-31 11:24:22 +00:00
"asciidoc",
"bash",
"conf",
"go",
"javascript",
"json",
"lua",
2024-05-15 08:03:34 +00:00
"make",
"markdown",
2024-05-15 08:03:34 +00:00
"proto",
"python",
"sh",
"toml",
"yaml",
"zsh",
},
config = function()
local conform = require("conform")
conform.setup({
formatters_by_ft = {
2024-04-30 08:13:02 +00:00
["_"] = { "trim_whitespace" },
2024-04-04 10:04:12 +00:00
bash = { "shfmt" },
go = { "gofumpt" },
javascript = { "deno_fmt" },
json = { "deno_fmt" },
lua = { "stylua" },
markdown = { "deno_fmt" },
2024-05-15 08:03:34 +00:00
proto = { "buf" },
python = { "ruff_format" },
sh = { "shfmt" },
toml = { "taplo" },
2024-04-16 09:01:54 +00:00
yaml = { "prettier" },
2024-04-04 10:04:12 +00:00
zsh = { "shfmt" },
},
formatters = {
gofumpt = {
prepend_args = { "-extra" },
},
shfmt = {
prepend_args = { "-s", "-i", "4" },
},
2024-05-15 08:03:34 +00:00
taplo = {
args = { "fmt", "-o", "indent_string= ", "-o", "allowed_blank_lines=1", "-" },
},
},
})
vim.keymap.set("n", "<Space>f", function()
conform.format()
end)
2023-07-08 14:44:45 +00:00
end,
},
2022-09-21 03:37:23 +00:00
-- https://github.com/neovim/nvim-lspconfig
{
"neovim/nvim-lspconfig",
ft = {
"go",
"markdown",
"python",
},
dependencies = {
"hrsh7th/nvim-cmp",
},
config = function()
2023-07-01 08:49:15 +00:00
local lspconfig = require("lspconfig")
local capabilities = require("cmp_nvim_lsp").default_capabilities()
2023-06-29 11:26:53 +00:00
-- Go
-- https://github.com/golang/tools/blob/master/gopls/doc/vim.md
-- https://github.com/golang/tools/blob/master/gopls/doc/settings.md
2023-07-01 08:49:15 +00:00
-- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#gopls
lspconfig.gopls.setup({
capabilities = capabilities,
})
2024-02-29 15:17:14 +00:00
-- Python
-- https://github.com/Microsoft/pyright
-- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#pyright
lspconfig.pyright.setup({})
-- Markdown
-- https://github.com/artempyanykh/marksman
-- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#marksman
lspconfig.marksman.setup({})
2023-06-30 17:27:29 +00:00
-- General
vim.keymap.set("n", "<Space>e", vim.diagnostic.open_float)
2023-07-25 06:02:23 +00:00
vim.keymap.set("n", "<Space>lr", ":LspRestart<CR>")
2023-07-25 06:02:23 +00:00
local augroup = vim.api.nvim_create_augroup("UserLspConfig", {})
vim.api.nvim_create_autocmd("LspAttach", {
2023-07-25 06:02:23 +00:00
group = augroup,
callback = function(ev)
vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc"
local opts = { buffer = ev.buf }
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
2023-07-04 06:23:12 +00:00
vim.keymap.set("n", "<Space>k", vim.lsp.buf.hover, opts)
2023-11-06 19:23:44 +00:00
vim.keymap.set("n", "gk", vim.lsp.buf.hover, opts)
vim.keymap.set("n", "<F2>", vim.lsp.buf.rename, opts)
2023-07-25 06:02:23 +00:00
end,
})
2023-12-30 04:06:11 +00:00
-- Chaos
-- https://www.reddit.com/r/neovim/comments/18teetv/one_day_you_will_wake_up_and_choose_the_chaos
-- https://github.com/neovim/nvim-lspconfig/wiki/UI-Customization
-- https://neovim.io/doc/user/diagnostic.html#diagnostic-highlights
local signs = {
Error = "🤬",
2024-01-16 07:09:24 +00:00
Warn = "😤",
Info = "🤔",
2024-01-27 18:24:25 +00:00
Hint = "🤯",
2023-12-30 04:06:11 +00:00
}
for type, icon in pairs(signs) do
local hl = "DiagnosticSign" .. type
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
end
2024-01-12 10:27:00 +00:00
-- https://neovim.io/doc/user/diagnostic.html#diagnostic-api
vim.diagnostic.config({
2024-02-29 15:17:14 +00:00
underline = false,
virtual_text = false,
2024-01-12 10:27:00 +00:00
})
end,
},
2024-01-24 10:41:16 +00:00
-- https://github.com/github/copilot.vim
{
"github/copilot.vim",
ft = {
2024-05-31 11:24:22 +00:00
"asciidoc",
"gitcommit",
"go",
"lua",
"make",
"markdown",
"proto",
"python",
"toml",
"yaml",
"zsh",
},
2024-01-24 10:41:16 +00:00
init = function()
vim.g.copilot_filetypes = {
["*"] = false,
2024-05-31 11:24:22 +00:00
asciidoc = true,
2024-02-26 03:27:32 +00:00
gitcommit = true,
2024-01-24 10:41:16 +00:00
go = true,
lua = true,
2024-02-26 03:27:32 +00:00
make = true,
2024-02-17 08:26:42 +00:00
markdown = true,
2024-02-22 12:38:42 +00:00
proto = true,
python = true,
2024-02-17 08:26:42 +00:00
toml = true,
yaml = true,
2024-03-10 18:06:52 +00:00
zsh = true,
2024-01-24 10:41:16 +00:00
}
vim.g.copilot_no_tab_map = true
end,
config = function()
-- Largely copy from GitHub
vim.keymap.set("i", "<M-Right>", 'copilot#Accept("\\<CR>")', {
expr = true,
replace_keycodes = false,
})
2024-01-24 10:41:16 +00:00
end,
},
2024-04-30 08:13:02 +00:00
}, {
performance = {
rtp = {
disabled_plugins = {
"editorconfig",
"gzip",
"spellfile",
"tarPlugin",
"tohtml",
"tutor",
"zipPlugin",
},
},
},
2023-06-17 04:20:37 +00:00
})