dotfiles/dot_config/nvim/init.lua.tmpl

258 lines
8.0 KiB
Cheetah
Raw Normal View History

2023-10-13 21:54:13 +02:00
{{- if eq .chezmoi.os "openbsd" }}
2024-02-15 09:53:19 +01:00
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",
"--branch=stable", -- latest stable release
lazypath,
})
2024-02-15 09:53:19 +01:00
end
vim.opt.rtp:prepend(lazypath)
2023-02-11 14:11:00 +01:00
HOME = os.getenv("HOME")
2023-02-24 07:31:04 +01:00
vim.g.mapleader = ' '
2023-02-11 14:11:00 +01:00
vim.g.maplocalleader = '\\'
-- Plugins
2024-02-15 09:53:19 +01:00
require("lazy").setup("plugins")
2023-02-11 14:11:00 +01:00
-- Options
2023-02-27 07:44:10 +01:00
local o = vim.opt
2023-02-11 14:11:00 +01:00
-- basic settings
2023-02-27 07:44:10 +01:00
o.encoding = "utf-8"
o.backspace = "indent,eol,start" -- backspace works on every char in insert mode
o.completeopt = { 'menu', 'menuone', 'noselect' }
o.conceallevel = 2 -- Hide * markup for bold and italic, but not markers with substitutions
2023-02-27 07:44:10 +01:00
o.history = 1000
o.startofline = true
o.title = true
o.clipboard = 'unnamedplus'
o.mouse = "a" -- Enable mouse mode
2023-02-11 14:11:00 +01:00
-- Mapping waiting time
o.timeoutlen = 300
2023-02-27 07:44:10 +01:00
o.ttimeoutlen = 0
2023-02-11 14:11:00 +01:00
-- Spellchecker
2023-02-27 07:44:10 +01:00
o.spell = false
o.spelllang = { 'en_us' }
o.spellfile = HOME .. '/.vim/spell/en.utf8.add'
o.thesaurus = HOME .. '/.vim/thesaurus/english.txt'
2023-02-11 14:11:00 +01:00
-- Display
2023-02-24 09:19:42 +01:00
o.showmatch = true -- show matching brackets
o.colorcolumn = '90'
o.confirm = true -- Confirm to save changes before exiting modified buffer
2023-02-24 09:19:42 +01:00
o.cursorline = true
o.scrolloff = 4 -- always show 3 rows from edge of the screen
2023-02-24 09:19:42 +01:00
o.splitbelow = true
o.splitkeep = "screen"
2023-02-24 09:19:42 +01:00
o.splitright = true
o.virtualedit = 'block'
o.synmaxcol = 300 -- stop syntax highlight after x lines for performance
o.laststatus = 3 -- always show status line
o.list = false -- do not display white characters
2023-02-11 14:11:00 +01:00
o.termguicolors = true
2023-02-27 07:44:10 +01:00
o.wrap = false --do not wrap lines even if very long
o.eol = false -- show if there's no eol char
o.showbreak = '↪' -- character to show when line is broken
o.pumblend = 10 -- Popup blend
o.pumheight = 10 -- Maximum number of entries in a popup
2023-02-11 14:11:00 +01:00
-- Folding
-- o.foldenable = true
-- o.foldnestmax = 2
-- o.foldminlines = 10
-- o.foldmethod = "expr"
-- o.foldexpr = "nvim_treesitter#foldexpr()"
2023-02-27 07:44:10 +01:00
-- workaround for Telescope bug
vim.api.nvim_create_autocmd({ "BufEnter" }, {
pattern = { "*" },
command = "normal zx",
2023-02-27 07:44:10 +01:00
})
2023-02-11 14:11:00 +01:00
-- Sidebar
o.number = true -- line number on the left
2023-02-11 14:11:00 +01:00
o.relativenumber = true
o.numberwidth = 3 -- always reserve 3 spaces for line number
2023-02-24 07:31:04 +01:00
o.signcolumn = 'yes'
2023-02-11 14:11:00 +01:00
o.modelines = 0
-- Bottombar
o.showcmd = true -- display command in bottom bar
o.ruler = false
o.showmode = false
-- Search
o.grepformat = "%f:%l:%c:%m"
o.grepprg = "rg --vimgrep"
o.incsearch = true -- starts searching as soon as typing, without enter needed
o.hlsearch = true -- highlighting of search matches
2023-02-11 14:11:00 +01:00
o.ignorecase = true -- ignore letter case when searching
o.smartcase = true -- case insentive unless capitals used in search
2023-02-11 14:11:00 +01:00
o.wildignorecase = true
o.inccommand = "nosplit" -- preview incremental substitute
o.matchtime = 2 -- delay before showing matching paren
2023-02-11 14:11:00 +01:00
o.mps = vim.o.mps .. ",<:>"
-- White characters
o.smartindent = true
o.breakindent = true
o.tabstop = 2
o.shiftwidth = 2 -- indentation rule
o.softtabstop = 2
o.expandtab = true -- expand tab to spaces
2023-02-11 14:11:00 +01:00
o.smarttab = true
o.shiftround = true -- Round indent
2023-02-11 14:11:00 +01:00
-- Shortmess
o.shortmess = o.shortmess
+ {
-- A = true, -- don't give the "ATTENTION" message when an existing swap file is found.
I = true, -- don't give the intro message when starting Vim |:intro|.
W = true, -- don't give "written" or "[w]" when writing a file
c = true, -- don't give |ins-completion-menu| messages
C = true, -- don't give |ins-completion-menu| messages
-- m = true, -- use "[+]" instead of "[Modified]"
2023-02-11 14:11:00 +01:00
}
-- Format options
o.formatoptions = o.formatoptions
+ {
c = false,
o = false, -- O and o, don't continue comments
r = true, -- Pressing Enter will continue comments
2023-02-11 14:11:00 +01:00
}
o.fillchars = {
foldopen = "",
foldclose = "",
-- fold = "⸱",
fold = " ",
foldsep = " ",
diff = "",
eob = " ",
}
o.wildmode = "longest:full,full" -- Command-line completion mode
2023-02-11 14:11:00 +01:00
-- Backup files
o.hidden = true
o.autowrite = true
o.autoread = true
o.backup = true -- use backup files
2023-02-11 14:11:00 +01:00
o.writebackup = false
o.swapfile = false -- do not use swap file
2023-02-11 14:11:00 +01:00
o.undofile = true
o.undolevels = 10000
o.updatetime = 200 -- Save swap file and trigger CursorHold
o.undodir = HOME .. '/.local/share/nvim/dirs/undo//' -- undo files
2023-02-24 07:31:04 +01:00
o.backupdir = HOME .. '/.local/share/nvim/dirs/backup//' -- backups
2023-02-11 14:11:00 +01:00
-- Commands mode
o.wildmenu = true -- on TAB, complete options for system command
2023-02-27 07:44:10 +01:00
o.wildignore =
'deps,.svn,CVS,.git,.hg,*.o,*.a,*.class,*.mo,*.la,*.so,*.obj,*.swp,*.jpg,*.png,*.xpm,*.gif,.DS_Store,*.aux,*.out,*.toc'
2023-02-11 14:11:00 +01:00
2023-02-24 07:31:04 +01:00
vim.cmd([[
2023-07-06 07:10:22 +02:00
au BufRead,BufNewFile *.md set tw=80 syntax=markdown
2023-02-24 07:31:04 +01:00
]])
vim.g.markdown_recommended_style = 0
2023-02-24 07:31:04 +01:00
vim.api.nvim_create_user_command('ReloadConfig', 'source $MYVIMRC', {})
2023-02-24 09:19:42 +01:00
local group = vim.api.nvim_create_augroup('user_cmds', { clear = true })
2023-02-24 07:31:04 +01:00
vim.api.nvim_create_autocmd('TextYankPost', {
desc = 'Highlight on yank',
group = group,
callback = function()
vim.highlight.on_yank({ higroup = 'Visual', timeout = 200 })
end,
2023-02-24 07:31:04 +01:00
})
2023-02-11 14:11:00 +01:00
local map = vim.keymap.set
2023-02-24 09:19:42 +01:00
map({ 'n', 'v' }, '<Space>', "<Nop>", { silent = true })
2023-02-11 14:11:00 +01:00
-- Clear search with <esc>
map({ "i", "n" }, "<esc>", "<cmd>noh<cr><esc>", { desc = "Escape and clear hlsearch" })
2023-02-11 14:11:00 +01:00
-- sane regexes
2023-02-24 09:19:42 +01:00
map({ 'n', 'v' }, '/', '/\\v', { noremap = true, silent = true })
2023-02-11 14:11:00 +01:00
-- don't jump when using *
2023-02-24 09:19:42 +01:00
map('n', '*', '*<c-o>')
2023-02-11 14:11:00 +01:00
-- https://github.com/mhinz/vim-galore#saner-behavior-of-n-and-n
map("n", "n", "'Nn'[v:searchforward].'zv'", { expr = true, desc = "Next search result" })
map("x", "n", "'Nn'[v:searchforward]", { expr = true, desc = "Next search result" })
map("o", "n", "'Nn'[v:searchforward]", { expr = true, desc = "Next search result" })
map("n", "N", "'nN'[v:searchforward].'zv'", { expr = true, desc = "Prev search result" })
map("x", "N", "'nN'[v:searchforward]", { expr = true, desc = "Prev search result" })
map("o", "N", "'nN'[v:searchforward]", { expr = true, desc = "Prev search result" })
2023-02-11 14:11:00 +01:00
-- Same when jumping around
2023-02-24 09:19:42 +01:00
map('n', 'g;', 'g;zz')
2023-02-11 14:11:00 +01:00
-- replace ex mode map and use it for repeating 'q' macro
2023-02-24 09:19:42 +01:00
map('n', 'Q', '@q')
map('v', 'Q', '<cmd>norm @q<CR>')
2023-02-11 14:11:00 +01:00
-- save file
map({ "i", "x", "n", "s" }, "<C-s>", "<cmd>w<cr><esc>", { desc = "Save file" })
map({ "i", "n" }, "<C-s><C-s>", "<cmd>silent! xa<cr><cmd>qa<cr>", { desc = "Save all and quit" })
-- better indenting
map("v", "<", "<gv")
map("v", ">", ">gv")
-- lazy
map("n", "<leader>l", "<cmd>Lazy<cr>", { desc = "Lazy" })
map("n", "<leader>xl", "<cmd>lopen<cr>", { desc = "Location List" })
map("n", "<leader>xq", "<cmd>copen<cr>", { desc = "Quickfix List" })
map("n", "[q", vim.cmd.cprev, { desc = "Previous quickfix" })
map("n", "]q", vim.cmd.cnext, { desc = "Next quickfix" })
2023-02-11 14:11:00 +01:00
-- Shortcut to close quickfix windows
2023-02-24 09:19:42 +01:00
map('n', '<leader>a', '<cmd>windo lcl|ccl<CR>')
2023-02-11 14:11:00 +01:00
-- <Leader>q Closes the current buffer
2023-02-24 09:19:42 +01:00
map('n', '<leader>q', '<cmd>bdelete<CR>')
2023-02-11 14:11:00 +01:00
-- Easier in-file navigation with Tab and S-Tab
2023-02-24 09:19:42 +01:00
map('n', '<S-Tab>', '<C-U>')
map('n', '<Tab>', '<C-D>')
map("n", "-", "<CMD>Oil<CR>", { desc = "Open parent directory" })
2023-02-11 14:11:00 +01:00
-- Easy buffer navigation
2023-02-24 09:19:42 +01:00
map('n', '<C-h>', '<C-w>h')
map('n', '<C-j>', '<C-w>j')
map('n', '<C-k>', '<C-w>k')
map('n', '<C-l>', '<C-w>l')
map("n", "[b", "<cmd>bprevious<cr>", { desc = "Prev buffer" })
map("n", "]b", "<cmd>bnext<cr>", { desc = "Next buffer" })
map("n", "<leader>bb", "<cmd>e #<cr>", { desc = "Switch to Other Buffer" })
2023-02-24 09:19:42 +01:00
map('n', '<up>', '<cmd>resize -2<CR>')
map('n', '<down>', '<cmd>resize +2<CR>')
map('n', '<left>', '<cmd>vertical resize -2<CR>')
map('n', '<right>', '<cmd>vertical resize +2<CR>')
-- windows
map("n", "<leader>ww", "<C-W>p", { desc = "Other window", remap = true })
map("n", "<leader>wd", "<C-W>c", { desc = "Delete window", remap = true })
map("n", "<leader>-", "<C-W>s", { desc = "Split window below", remap = true })
map("n", "<leader>|", "<C-W>v", { desc = "Split window right", remap = true })
2023-10-13 21:54:13 +02:00
{{ else }}
require("config.lazy")
{{ end }}