From 3474ece326452705f9e08cf8ce558e42dc49c0cb Mon Sep 17 00:00:00 2001 From: Renken Date: Sat, 20 Jan 2024 21:29:32 +0100 Subject: nichijou: nvim: init lua config --- nichijou/home/config/nvim/init.lua | 173 +++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 nichijou/home/config/nvim/init.lua (limited to 'nichijou') diff --git a/nichijou/home/config/nvim/init.lua b/nichijou/home/config/nvim/init.lua new file mode 100644 index 0000000..6c5d737 --- /dev/null +++ b/nichijou/home/config/nvim/init.lua @@ -0,0 +1,173 @@ +function map(mode, shortcut, command) + vim.api.nvim_set_keymap(mode, shortcut, command, { noremap = true, silent = true }) +end + +function nmap(shortcut, command) + map('n', shortcut, command) +end + +function imap(shortcut, command) + map('i', shortcut, command) +end + + +--------------------------------------------------- +-- General +--------------------------------------------------- + +-- Set the amount of lines of history to remember. +vim.opt.history = 100 + +-- Set a mapleader key. This is used for extra key combinations. +vim.g.mapleader = "\\" +nmap("", "") + +-- Better command line completion. +vim.opt.wildmenu = true +vim.opt.wildmode = "list:longest,full" + +-- Ignore compiled and binary files. +vim.opt.wildignore = "*.o,*~,*.pyc,*.png,*.pdf" + +-- Filetypes +vim.api.nvim_create_autocmd( + { + "BufNewFile", + "BufRead", + }, + { + pattern = "*.irst", + callback = function() + local buf = vim.api.nvim_get_current_buf() + vim.api.nvim_buf_vim.opt_option(buf, "filetype", "rst") + end + } +) + +vim.api.nvim_create_autocmd( + { + "BufNewFile", + "BufRead", + }, + { + pattern = "*.puml", + callback = function() + local buf = vim.api.nvim_get_current_buf() + vim.api.nvim_buf_vim.opt_option(buf, "filetype", "plantuml") + end + } +) + +vim.api.nvim_create_autocmd( + { + "BufNewFile", + "BufRead", + }, + { + pattern = "*.tikz", + callback = function() + local buf = vim.api.nvim_get_current_buf() + vim.api.nvim_buf_vim.opt_option(buf, "filetype", "tex") + end + } +) + +vim.api.nvim_create_autocmd( + { + "BufNewFile", + "BufRead", + }, + { + pattern = "*.tpp", + callback = function() + local buf = vim.api.nvim_get_current_buf() + vim.api.nvim_buf_vim.opt_option(buf, "filetype", "cpp") + end + } +) + +-- TODO: Restore last known cursor position, see https://github.com/neovim/neovim/issues/16339. + +-- Set the swap directory to ~/.cache/nvim/swap. +local cache = vim.env.XDG_CACHE_HOME or vim.fn.expand("~/.cache") +local swap = cache .. "/nvim/swap" +if vim.fn.isdirectory(swap) == 0 then + vim.fn.mkdir(swap, 'p', 0700) +end +-- The extra '/' suffix is required to make vim create unique filenames. +-- XXX: Not sure if this is required in neovim however. +vim.opt.dir = { swap .. "//" } + +-- Use system clipboard by default. +vim.opt.clipboard = "unnamedplus" + +--------------------------------------------------- +-- User interface +--------------------------------------------------- + +-- Display line numbers. +vim.opt.number = true +vim.opt.relativenumber = true + +-- Show the (partial) command in status line. +vim.opt.showcmd = true + +-- Always display the status line, even if only one window is displayed. +vim.opt.laststatus = 2 + +-- Shows a dialogue asking if the file has to be saved, instead of raising an +-- error. +vim.opt.confirm = true + +-- Keep the cursor in the centre of the buffer if possible. +vim.opt.scrolloff = 10000 + +-- Disable automatic folding. +-- vim.opt.nofoldenable = true + +-- Delete the current buffer without closing the windows +nmap("bd", ":Bdelete") +-- Close window +nmap("wd", ":q") +-- Vertical split +nmap("wv", ":vsplit") +-- Horizontal split +nmap("wh", ":split") +-- Exit vim +nmap("qq", ":qa") + +-- Easy vertical terminal split opening (why is this not built-in?) +-- cnoreabbrev vterm vert term + +-- Set filetype. +vim.opt.ffs = "unix" + +vim.opt.termguicolors = true +vim.opt.colorcolumn = "80" + +vim.opt.splitbelow = true +vim.opt.splitright = true + +--------------------------------------------------- +-- Search +-------------------------------------------------- + +vim.opt.ignorecase = true + +vim.opt.smartcase = true + +nmap("", ":nohl") + +vim.env.MANSECT = "3p:3:2:1:n:l:8:0:5:4:9:6:7" + + +--------------------------------------------------- +-- Text (tab, spaces, indent) +--------------------------------------------------- + +vim.bo.softtabstop = 2 +vim.opt.autoindent = true +vim.opt.expandtab = true +vim.opt.listchars = { tab = "»-", trail = "·" } +vim.opt.shiftwidth = 2 +vim.opt.tabstop = 2 -- cgit v1.2.3