dotfiles/data/nvim/init.lua

620 lines
14 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"
vim.opt.mousemodel = "extend"
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.keymap.set("n", ";", "<Leader>", { remap = true })
vim.keymap.set("n", "'", "<Leader>", { remap = true })
2023-07-07 06:46:28 +00:00
-- Keymap
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
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",
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
enabled = false,
},
-- https://github.com/nyoom-engineering/oxocarbon.nvim
{
"nyoom-engineering/oxocarbon.nvim",
lazy = false,
priority = 1000,
config = function()
vim.cmd("colorscheme oxocarbon")
end,
enabled = false,
},
-- https://github.com/projekt0n/github-nvim-theme
{
"projekt0n/github-nvim-theme",
lazy = false,
priority = 1000,
config = function()
require("github-theme").setup({})
vim.cmd("colorscheme github_dark")
end,
enabled = false,
},
-- https://github.com/projekt0n/caret.nvim
{
"projekt0n/caret.nvim",
lazy = false,
priority = 1000,
config = function()
2023-09-21 08:22:01 +00:00
require("caret").setup({
options = {
transparent = true,
},
})
2023-09-15 08:18:57 +00:00
vim.cmd("colorscheme caret")
end,
2023-09-20 06:49:26 +00:00
enabled = true,
2023-09-15 08:18:57 +00:00
},
-- https://github.com/folke/tokyonight.nvim
{
"folke/tokyonight.nvim",
lazy = false,
priority = 1000,
config = function()
require("tokyonight").setup({})
vim.cmd("colorscheme tokyonight")
end,
enabled = false,
},
{
"rebelot/kanagawa.nvim",
lazy = false,
priority = 1000,
config = function()
require("kanagawa").setup({
theme = "lotus",
})
vim.cmd("colorscheme kanagawa")
end,
2023-09-15 08:37:58 +00:00
enabled = false,
2023-09-15 08:18:57 +00:00
},
-- https://github.com/rose-pine/neovim
{
"rose-pine/neovim",
name = "rose-pine",
lazy = false,
priority = 1000,
config = function()
require("rose-pine").setup({})
vim.cmd("colorscheme rose-pine")
end,
enabled = false,
2023-06-29 18:04:45 +00:00
},
2023-09-15 08:37:58 +00:00
-- https://github.com/ramojus/mellifluous.nvim
{
"ramojus/mellifluous.nvim",
lazy = false,
priority = 1000,
config = function()
require("mellifluous").setup({})
vim.cmd("colorscheme mellifluous")
end,
2023-09-20 06:49:26 +00:00
enabled = false,
2023-09-15 08:37:58 +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-07-07 10:34:37 +00:00
require("fzf-lua").setup({ "max-perf" })
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>")
vim.keymap.set("n", "<Leader>rg", ":FzfLua live_grep_native<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-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
2023-06-30 17:43:55 +00:00
-- https://github.com/hrsh7th/nvim-cmp
{
"hrsh7th/nvim-cmp",
event = "InsertEnter",
dependencies = {
"neovim/nvim-lspconfig",
"hrsh7th/cmp-nvim-lsp",
2023-07-04 04:19:40 +00:00
"hrsh7th/cmp-vsnip",
"hrsh7th/vim-vsnip",
2023-07-06 08:29:18 +00:00
"zbirenbaum/copilot-cmp",
2023-06-30 17:43:55 +00:00
},
config = function()
local cmp = require("cmp")
cmp.setup({
performance = {
max_view_entries = 8,
},
2023-07-04 04:19:40 +00:00
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
2023-06-30 17:43:55 +00:00
mapping = cmp.mapping.preset.insert({
["<C-Space>"] = cmp.mapping.complete(),
2023-09-23 05:44:44 +00:00
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = true }),
2023-06-30 17:43:55 +00:00
}),
completion = {
autocomplete = false,
},
2023-06-30 17:43:55 +00:00
sources = cmp.config.sources({
2023-07-19 11:37:49 +00:00
{ name = "copilot" },
2023-09-23 05:44:44 +00:00
{ name = "nvim_lsp" },
2023-06-30 17:43:55 +00:00
}),
})
2023-07-06 08:29:18 +00:00
end,
},
2023-07-05 09:57:39 +00:00
2023-07-06 08:29:18 +00:00
-- https://github.com/zbirenbaum/copilot-cmp
{
"zbirenbaum/copilot-cmp",
dependencies = {
"zbirenbaum/copilot.lua",
},
config = function()
require("copilot_cmp").setup()
2023-06-30 17:43:55 +00:00
end,
},
-- 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-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
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-09-20 06:49:26 +00:00
-- https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-statusline.md
require("mini.statusline").setup({
use_icons = false,
})
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()
vim.g.neoformat_enabled_go = { "gofumpt" }
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" }
2023-08-05 19:29:17 +00:00
vim.g.neoformat_enabled_toml = { "taplo" }
2023-07-08 14:44:45 +00:00
vim.g.shfmt_opt = "-ci"
end,
2023-07-25 06:02:23 +00:00
config = function()
local augroup = vim.api.nvim_create_augroup("UserNeoformatConfig", {})
vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup,
2023-07-25 10:08:31 +00:00
pattern = { "*.lua", "*.md" },
2023-07-25 06:02:23 +00:00
command = "Neoformat",
})
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",
},
2023-07-13 05:49:01 +00:00
init = function()
vim.opt.foldmethod = "expr"
vim.opt.foldexpr = "nvim_treesitter#foldexpr()"
vim.opt.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,
2023-07-17 06:21:04 +00:00
codelenses = {
gc_details = true,
},
semanticTokens = 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 }
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-07-04 06:23:12 +00:00
vim.keymap.set({ "n", "v" }, "<Space>ca", vim.lsp.buf.code_action, opts)
end,
})
2023-07-04 06:23:12 +00:00
2023-07-25 06:02:23 +00:00
-- Custom
vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup,
pattern = "*.go",
callback = function()
-- Format without async then code action
-- https://github.com/neovim/neovim/issues/24168
vim.lsp.buf.format()
vim.lsp.buf.code_action({ context = { only = { "source.organizeImports" } }, apply = true })
end,
})
end,
},
2022-09-21 03:37:23 +00:00
2023-07-05 09:57:39 +00:00
-- https://github.com/zbirenbaum/copilot.lua
{
"zbirenbaum/copilot.lua",
event = "InsertEnter",
config = function()
require("copilot").setup({
2023-07-05 10:08:02 +00:00
panel = {
enabled = false,
},
2023-07-05 09:57:39 +00:00
suggestion = {
2023-07-06 08:29:18 +00:00
enabled = false,
2023-07-05 09:57:39 +00:00
},
filetypes = {
["."] = false,
c = true,
cpp = true,
go = true,
java = true,
json = true,
lua = true,
make = true,
markdown = true,
proto = true,
python = true,
toml = true,
yaml = true,
},
})
end,
},
2023-06-17 04:20:37 +00:00
})