dotfiles/data/nvim/init.lua

468 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,
},
}
end,
2023-10-30 17:03:44 +00:00
integrations = {
treesitter = true,
treesitter_context = true,
},
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-10-28 17:57:26 +00:00
enabled = true,
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()
2023-10-30 16:48:46 +00:00
require("fzf-lua").setup({ "fzf-native" })
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>")
vim.keymap.set("n", "<Space>r", ":FzfLua lsp_references<CR>")
vim.keymap.set("n", "<Space>i", ":FzfLua lsp_implementations<CR>")
2023-10-28 17:25:41 +00:00
vim.keymap.set("n", "<Space>ca", ":FzfLua lsp_code_actions<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,
indent_width = 1,
2023-02-07 10:10:22 +00:00
icons = {
show = {
file = false,
folder = false,
folder_arrow = false,
},
},
2022-09-21 03:37:23 +00:00
},
2023-05-24 07:10:08 +00:00
filters = {
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$",
2023-08-10 17:06:56 +00:00
"\\.out$",
"\\.pdf$",
"\\.zip$",
2023-08-10 17:06:56 +00:00
"^\\.DS_Store$",
"^\\.git$",
"^\\.idea$",
"^\\.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
},
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({
2023-07-25 18:04:19 +00:00
buffer = { suffix = "", options = {} },
2023-06-17 04:33:05 +00:00
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 = {} },
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
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" }
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/nvim-treesitter/nvim-treesitter
2023-06-17 04:20:37 +00:00
{
"nvim-treesitter/nvim-treesitter",
2023-06-17 16:07:41 +00:00
build = {
":TSUpdate",
},
init = function()
vim.opt_local.foldmethod = "expr"
vim.opt_local.foldexpr = "nvim_treesitter#foldexpr()"
vim.opt_local.foldenable = false
end,
2023-06-17 16:07:41 +00:00
config = function()
require("nvim-treesitter.configs").setup({
ensure_installed = {
"go",
"json",
"lua",
2023-08-24 08:25:20 +00:00
"proto",
"sql",
2023-07-03 04:07:08 +00:00
"toml",
"yaml",
2023-06-17 16:07:41 +00:00
},
})
-- Workaround to update fold
-- https://github.com/nvim-treesitter/nvim-treesitter/issues/1337
-- https://www.jmaguire.tech/posts/treesitter_folding/
local augroup = vim.api.nvim_create_augroup("UserTreesitterConfig", {})
vim.api.nvim_create_autocmd("BufEnter", {
group = augroup,
pattern = "*",
command = "normal zR",
})
2023-06-17 16:07:41 +00:00
end,
2023-06-17 04:20:37 +00:00
},
-- https://github.com/nvim-treesitter/nvim-treesitter-context
2023-06-17 04:20:37 +00:00
{
"nvim-treesitter/nvim-treesitter-context",
config = function()
require("treesitter-context").setup({
enable = true,
max_lines = 2,
})
end,
2023-06-17 04:20:37 +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,
semanticTokens = true,
2023-10-28 18:26:26 +00:00
usePlaceholders = true,
},
},
})
2023-06-29 11:26:53 +00:00
-- Proto
2023-07-01 08:49:15 +00:00
-- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#bufls
2023-06-29 10:40:46 +00:00
lspconfig.bufls.setup({})
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)
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,
})
end,
},
2023-06-17 04:20:37 +00:00
})