dotfiles/data/nvim/init.lua

487 lines
12 KiB
Lua
Raw 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
-- Truecolor
if vim.env.COLORTERM == "truecolor" then
vim.opt.termguicolors = true
end
-- 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
-- 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", "d", '"_d')
vim.keymap.set({ "n", "v" }, "D", '"_D')
vim.keymap.set({ "n", "v" }, "c", '"_c')
vim.keymap.set({ "n", "v" }, "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
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",
2023-09-15 08:18:57 +00:00
lazy = false,
2023-06-30 08:08:46 +00:00
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)
return {
2023-10-28 17:57:26 +00:00
-- Support mini.statusline
StatusLineNC = {
fg = colors.flamingo,
},
2024-01-10 18:05:27 +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
DiagnosticVirtualTextError = {
fg = "#44d62c",
bg = "#5f249e",
},
}
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
},
2023-07-04 04:19:40 +00:00
-- https://github.com/ibhagwan/fzf-lua
{
"ibhagwan/fzf-lua",
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",
},
},
})
2023-07-04 06:23:12 +00:00
vim.keymap.set("n", "<Leader>f", ":FzfLua files<CR>")
vim.keymap.set("n", "<Leader>l", ":FzfLua blines<CR>")
2023-11-03 17:14:22 +00:00
vim.keymap.set("n", "<Leader>rg", ":FzfLua live_grep_resume<CR>")
vim.keymap.set("n", "<Space>s", ":FzfLua lsp_document_symbols<CR>")
vim.keymap.set("n", "<Space>d", ":FzfLua lsp_definitions<CR>")
2023-11-06 19:23:44 +00:00
vim.keymap.set("n", "gd", ":FzfLua lsp_definitions<CR>")
vim.keymap.set("n", "<Space>r", ":FzfLua lsp_references<CR>")
2023-11-06 19:23:44 +00:00
vim.keymap.set("n", "gr", ":FzfLua lsp_references<CR>")
vim.keymap.set("n", "<Space>i", ":FzfLua lsp_implementations<CR>")
2023-11-06 19:23:44 +00:00
vim.keymap.set("n", "gi", ":FzfLua lsp_implementations<CR>")
vim.keymap.set("n", "<Space>ca", ":FzfLua lsp_code_actions previewer=false<CR>")
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
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",
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$",
"^\\.venv$",
2023-08-10 17:06:56 +00:00
"^\\.vscode$",
2023-06-29 03:28:18 +00:00
},
2023-05-24 07:10:08 +00:00
},
2022-09-21 03:37:23 +00:00
})
2023-07-04 06:23:12 +00:00
vim.keymap.set("n", "<C-n>", ":NvimTreeToggle<CR>")
vim.keymap.set("n", "<Leader>n", ":NvimTreeFindFile<CR>")
2023-09-15 16:44:23 +00:00
-- https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup
local function open_nvim_tree(data)
2023-09-21 02:48:58 +00:00
-- Buffer is a real file on the disk
2023-09-15 16:44:23 +00:00
local real_file = vim.fn.filereadable(data.file) == 1
2023-09-21 02:48:58 +00:00
-- Buffer is a [No Name]
2023-09-15 16:44:23 +00:00
local no_name = data.file == "" and vim.bo[data.buf].buftype == ""
if not real_file and not no_name then
return
end
local IGNORED_FT = {
"gitcommit",
}
-- &ft
local filetype = vim.bo[data.buf].ft
2023-09-21 02:48:58 +00:00
-- Skip ignored filetypes
if vim.tbl_contains(IGNORED_FT, filetype) then
return
end
2023-09-21 02:48:58 +00:00
-- Ignore small window
-- https://stackoverflow.com/a/42648387
if vim.api.nvim_win_get_width(0) < 800 then
return
end
2023-09-15 16:44:23 +00:00
require("nvim-tree.api").tree.toggle({ focus = false })
end
local augroup = vim.api.nvim_create_augroup("UserNvimTreeConfig", {})
vim.api.nvim_create_autocmd("VimEnter", {
group = augroup,
callback = open_nvim_tree,
})
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()
require("gitsigns").setup({
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 = {
delay = 1200,
ignore_whitespace = true,
},
on_attach = function(bufnr)
local gs = package.loaded.gitsigns
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
return "]c"
end
vim.schedule(function()
gs.next_hunk()
end)
return "<Ignore>"
end, { expr = true })
map("n", "[c", function()
if vim.wo.diff then
return "[c"
end
vim.schedule(function()
gs.prev_hunk()
end)
return "<Ignore>"
end, { expr = true })
end,
})
end,
},
2023-04-26 05:57:22 +00:00
2023-07-21 03:37:15 +00:00
-- https://github.com/tpope/vim-fugitive
{
"tpope/vim-fugitive",
},
2023-07-08 11:29:01 +00:00
-- https://github.com/tpope/vim-projectionist
{
"tpope/vim-projectionist",
init = function()
vim.g.projectionist_heuristics = {
["*.go"] = {
["*.go"] = {
alternate = "{}_test.go",
type = "source",
},
["*_test.go"] = {
alternate = "{}.go",
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
},
2024-01-28 07:20:00 +00:00
-- https://github.com/ntpeters/vim-better-whitespace
{
"ntpeters/vim-better-whitespace",
},
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-bracketed.md
2023-06-17 04:33:05 +00:00
require("mini.bracketed").setup({
comment = { suffix = "", options = {} },
2023-07-25 18:04:19 +00:00
file = { suffix = "", options = {} },
indent = { suffix = "", options = {} },
jump = { suffix = "", options = {} },
location = { suffix = "", options = {} },
oldfile = { suffix = "", options = {} },
2023-11-11 14:35:32 +00:00
treesitter = { suffix = "", options = {} },
2023-07-25 18:04:19 +00:00
undo = { suffix = "", options = {} },
window = { suffix = "", options = {} },
yank = { suffix = "", options = {} },
2023-06-17 04:33:05 +00:00
})
2023-02-28 09:00:43 +00:00
2023-06-21 09:35:14 +00:00
-- https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-comment.md
2024-02-10 16:56:53 +00:00
require("mini.comment").setup()
2023-03-01 09:19:40 +00:00
-- https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-completion.md
2023-10-03 05:48:54 +00:00
require("mini.completion").setup({
window = {
2023-10-29 17:55:48 +00:00
info = { height = 8, width = 40, border = "rounded" },
signature = { height = 8, width = 40, border = "rounded" },
2023-10-03 05:48:54 +00:00
},
mappings = {
force_twostep = "<C-Space>",
force_fallback = "",
},
})
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()
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/sbdchd/neoformat
2023-07-08 14:44:45 +00:00
{
"sbdchd/neoformat",
init = function()
2023-10-02 16:33:21 +00:00
vim.g.neoformat_enabled_go = {}
vim.g.neoformat_enabled_javascript = { "denofmt" }
2023-08-05 19:04:00 +00:00
vim.g.neoformat_enabled_json = { "denofmt" }
vim.g.neoformat_enabled_lua = { "stylua" }
vim.g.neoformat_enabled_markdown = { "denofmt" }
2024-02-22 12:38:42 +00:00
vim.g.neoformat_enabled_python = { "ruff" }
vim.g.neoformat_enabled_sh = { "shfmt" }
2023-08-05 19:29:17 +00:00
vim.g.neoformat_enabled_toml = { "taplo" }
vim.g.neoformat_enabled_zsh = { "shfmt" }
2023-07-08 14:44:45 +00:00
vim.g.shfmt_opt = "-ci"
end,
config = function()
vim.keymap.set("v", "=", ":Neoformat<CR>")
end,
2023-07-08 14:44:45 +00:00
},
2022-09-21 03:37:23 +00:00
-- https://github.com/neovim/nvim-lspconfig
{
"neovim/nvim-lspconfig",
config = function()
2023-07-01 08:49:15 +00:00
local lspconfig = require("lspconfig")
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({
settings = {
gopls = {
gofumpt = true,
2023-10-28 18:26:26 +00:00
usePlaceholders = true,
},
},
})
2023-06-30 17:27:29 +00:00
-- General
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev)
vim.keymap.set("n", "]d", vim.diagnostic.goto_next)
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-10-02 16:33:21 +00:00
vim.keymap.set("n", "<Space>f", function()
vim.lsp.buf.format({ async = true })
end, 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({
virtual_text = {
2024-01-15 03:34:27 +00:00
prefix = "🏓",
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",
init = function()
vim.g.copilot_filetypes = {
["*"] = false,
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-01-24 10:41:16 +00:00
}
end,
},
2023-06-17 04:20:37 +00:00
})