1
0
Files
dotfiles/config/nvim/init.lua

101 lines
3.1 KiB
Lua
Raw Normal View History

local MAP = vim.keymap.set
local AUTOCMD = vim.api.nvim_create_autocmd
vim.cmd("colorscheme scheme")
vim.cmd("filetype indent on")
-- Language people you have more important things to do than police the code style, if people
-- want consistent styling it should be done at a project level using a linter or .editorconfig
vim.g.rust_recommended_style = false
vim.g.python_recommended_style = false
vim.g.go_recommended_style = false
vim.g.zig_recommended_style = false
vim.g.markdown_recommended_style = false
vim.g.arduino_recommended_style = false
vim.g.gdscript_recommended_style = false
vim.g.yaml_recommended_style = false
-- Basic options
vim.o.tabstop = 2
vim.o.shiftwidth = 0
vim.o.expandtab = false
vim.o.list = true
vim.o.clipboard = "unnamedplus"
vim.o.ff = "unix"
vim.o.ffs = "unix,dos"
vim.o.switchbuf = "useopen,uselast"
vim.o.textwidth = 95
vim.o.wrapmargin = 5
vim.o.number = true
vim.o.relativenumber = true
vim.o.splitbelow = true
vim.o.splitright = true
vim.o.autoread = true
vim.o.lazyredraw = true
vim.o.cursorline = true
vim.o.ignorecase = true
vim.o.wrap = false
vim.o.wildmenu = false
vim.o.termguicolors = true
vim.o.cindent = true
vim.o.timeoutlen = 1500
vim.o.completeopt = "preview"
vim.o.wildmode = "full"
vim.o.cinoptions = "l1,b-s"
vim.o.statusline = "%#LineNr# [%n] %#Default# %f%m%r %= %#StatusLineNC# %w[%{&ft == '' ? 'None' : ''}%Y] %#LineNr# Line: %l Column: %c "
vim.opt.errorformat = {
"%f:%l:%c: fatal %trror: %m", -- gcc/clang fatal error
"%f:%l:%c: %trror: %m", -- gcc/clang error
"%f:%l:%c: %tarning: %m", -- gcc/clang warning
"%-G%m" -- Ignore anything else
}
vim.opt.formatoptions:append("/")
vim.opt.cinkeys:append("0=break")
vim.opt.listchars:append({ lead = "." })
--------------------------------------------------------------------------------
-- Functions
--------------------------------------------------------------------------------
-- Buffers
local function BufferComplete()
local pos = vim.api.nvim_win_get_cursor(0)
local line = vim.fn.getline('.')
local ident = line:sub(1, pos[2]):match("[^ \t]*$")
return #ident ~= 0 and "<C-P>" or "<Tab>"
end
local function TrimBuffer()
local view = vim.fn.winsaveview()
vim.cmd("%s/\\s\\+$//e")
vim.fn.winrestview(view)
end
-- Input mappings
vim.g.mapleader = " "
MAP("n", "<A-j>", "mz:m+<CR>")
MAP("n", "<A-k>", "mz:m-2<CR>")
MAP("n", "<Esc>", ":nohl<CR>")
MAP("n", "<Leader>n", ":cnext<CR>")
MAP("n", "<Leader>N", ":cprev<CR>")
MAP("n", "J", "}")
MAP("v", "J", "}")
MAP("n", "K", "{")
MAP("v", "K", "{")
MAP("n", "<Leader>k", ":Man<CR>")
MAP("i", "<S-Tab>", "<C-o><<")
MAP("i", "<Tab>", BufferComplete, { expr = true })
-- Autocommands
AUTOCMD('BufEnter', { command = "let b:man_default_sects=\"2,3\"", pattern = "*.c" })
AUTOCMD('BufReadPost', { command = "setlocal nornu", pattern = "quickfix" })
AUTOCMD('BufWritePre', { callback = TrimBuffer, pattern = "*" })