dotfiles/dot_config/nvim/init.lua

136 lines
3.1 KiB
Lua
Raw Normal View History

2022-07-30 07:17:12 +02:00
-- vim:fdm=marker
pcall(require, "impatient")
pcall(require, "plugins")
pcall(require, "lsp")
2022-07-30 07:17:12 +02:00
-- true colors
vim.o.termguicolors = true
-- map leader to space
2022-07-30 07:17:12 +02:00
vim.g.mapleader = " "
vim.o.cmdheight = 0
-- line numbers
2022-10-17 17:13:31 +02:00
vim.o.mouse = ""
vim.o.number = true
vim.o.relativenumber = true
-- scroll offsets
vim.o.scrolloff = 5
vim.o.sidescrolloff = 15
-- show leading/trailing whitespace
vim.opt.list = true
vim.opt.listchars:append("tab:»·")
-- always show status & tab line
vim.o.laststatus = 3
vim.o.showtabline = 2
2022-11-07 11:57:53 +01:00
vim.g.termguicolors = false
-- completion height
vim.o.pumheight = 15
-- split directions
vim.o.splitbelow = true
vim.o.splitright = true
2022-11-02 16:50:16 +01:00
vim.o.wrap = false
2022-07-30 07:17:12 +02:00
-- redefine word boundaries - '_' is a word seperator, this helps with snake_case
vim.opt.iskeyword:remove("_")
2022-07-30 07:17:12 +02:00
2022-11-07 11:57:53 +01:00
-- netrw is handled by nvim-tree
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
2022-10-17 17:13:31 +02:00
function Map(mode, shortcut, command, opt)
opt = opt or { noremap = true, silent = true }
vim.keymap.set(mode, shortcut, command, opt)
end
2022-10-11 07:40:50 +02:00
2022-10-17 17:13:31 +02:00
-- easier split navigation
Map("n", "<C-J>", "<C-W>j")
Map("n", "<C-K>", "<C-W>k")
Map("n", "<C-L>", "<C-W>l")
Map("n", "<C-H>", "<C-W>h")
Map("n", "<C-W>\\", ":vsplit<CR>")
Map("n", "<C-W>-", ":split<CR>")
Map("n", "<C-W>x", ":q<CR>")
2022-10-11 07:40:50 +02:00
-- merge conflicts
2022-10-17 17:13:31 +02:00
Map("n", "<leader>gd", ":Gvdiff!<CR>")
2022-11-16 14:46:41 +01:00
Map("n", "gd", ":diffget")
2022-10-17 17:13:31 +02:00
Map("n", "gdh", ":diffget //2<CR>")
Map("n", "gdl", ":diffget //3<CR>")
-- clipboard
2022-11-15 20:30:50 +01:00
Map({ "n", "v" }, "<leader>p", '"+p')
Map({ "n", "v" }, "<leader>y", '"+y')
2022-07-30 07:17:12 +02:00
-- escape :terminal easier
vim.cmd([[tnoremap <Esc> <C-\><C-n>]])
-- indentations settings
vim.o.shiftwidth = 2
vim.o.tabstop = 2
2022-10-17 17:13:31 +02:00
vim.o.softtabstop = 0
vim.o.expandtab = true
2022-07-30 07:17:12 +02:00
vim.cmd([[
2022-10-11 07:40:50 +02:00
autocmd FileType html,lua,css,js,jsreact,ts,tsreact,json,yaml setlocal ts=2 sw=2 sts=0 et
autocmd FileType go setlocal ts=4 sw=4 sts=4 noet
2022-07-30 07:17:12 +02:00
autocmd FileType python,rust setlocal ts=4 sw=4 sts=4 et
autocmd FileType markdown let g:table_mode_corner='|'
2022-07-30 07:17:12 +02:00
]])
local builtins = {
"2html_plugin",
"bugreport",
"compiler",
"ftplugin",
"fzf",
"getscript",
"getscriptPlugin",
"gzip",
"logipat",
"matchit",
"netrw",
"netrwFileHandlers",
"netrwPlugin",
"netrwSettings",
"optwin",
"rplugin",
"rrhelper",
"spellfile_plugin",
"synmenu",
"syntax",
"tar",
"tarPlugin",
"tutor",
"vimball",
"vimballPlugin",
"zip",
"zipPlugin",
}
-- disable builtin plugins
for _, plugin in pairs(builtins) do
vim.g["loaded_" .. plugin] = 1
end
2022-10-11 07:40:50 +02:00
vim.api.nvim_create_autocmd("VimResized", {
pattern = "*",
command = "wincmd =",
desc = "Automatically resize windows when the host window size changes.",
2022-07-30 07:17:12 +02:00
})
2022-11-16 14:46:41 +01:00
2022-10-17 17:13:31 +02:00
vim.api.nvim_create_autocmd("TextYankPost", {
pattern = "*",
callback = function()
vim.highlight.on_yank({ higroup = "IncSearch", timeout = 200 })
end,
desc = "Highlight yanked text",
})
2022-11-15 20:30:50 +01:00
2022-11-16 14:46:41 +01:00
local trnuGroup = vim.api.nvim_create_augroup("toggleRnu", {})
vim.api.nvim_create_autocmd("InsertEnter,BufLeave,WinLeave,FocusLost", {
callback = function()
vim.opt_local.relativenumber = false
end,
group = trnuGroup,
})
vim.api.nvim_create_autocmd("InsertLeave,BufEnter,WinEnter,FocusGained", {
callback = function()
vim.opt_local.relativenumber = true
end,
group = trnuGroup,
})