-- init.lua -- Neovim-specific configuration require("globals") local opt = vim.opt local cmd = vim.cmd local g = vim.g local o = vim.o local fn = vim.fn local env = vim.env local utils = require("utils") local termcodes = utils.termcodes local nmap = utils.nmap local vmap = utils.vmap local imap = utils.imap local xmap = utils.xmap local omap = utils.omap local nnoremap = utils.nnoremap local inoremap = utils.inoremap local vnoremap = utils.vnoremap local colors = require("colors") -- create a completion_nvim table on _G which is visible via -- v:lua from vimscript _G.completion_nvim = {} function _G.completion_nvim.smart_pumvisible(vis_seq, not_vis_seq) if (fn.pumvisible() == 1) then return termcodes(vis_seq) else return termcodes(not_vis_seq) end end -- General ---------------------------------------------------------------- cmd [[abbr funciton function]] cmd [[abbr teh the]] cmd [[abbr tempalte template]] cmd [[abbr fitler filter]] cmd [[abbr cosnt const]] cmd [[abbr attribtue attribute]] cmd [[abbr attribuet attribute]] opt.backup = false -- don't use backup files opt.writebackup = false -- don't backup the file while editing opt.swapfile = false -- don't create swap files for new buffers opt.updatecount = 0 -- don't write swap files after some number of updates opt.backupdir = { "~/.vim-tmp", "~/.tmp", "~/tmp", "/var/tmp", "/tmp" } opt.directory = { "~/.vim-tmp", "~/.tmp", "~/tmp", "/var/tmp", "/tmp" } opt.history = 1000 -- store the last 1000 commands entered opt.textwidth = 120 -- after configured number of characters, wrap line opt.inccommand = "nosplit" -- show the results of substition as they're happening -- but don't open a split opt.backspace = {"indent", "eol,start"} -- make backspace behave in a sane manner opt.clipboard = {"unnamed", "unnamedplus"} -- use the system clipboard opt.mouse = "a" -- set mouse mode to all modes -- searching opt.ignorecase = true -- case insensitive searching opt.smartcase = true -- case-sensitive if expresson contains a capital letter opt.hlsearch = true -- highlight search results opt.incsearch = true -- set incremental search, like modern browsers opt.lazyredraw = false -- don't redraw while executing macros opt.magic = true -- set magic on, for regular expressions if fn.executable("rg") then -- if ripgrep installed, use that as a grepper opt.grepprg = "rg --vimgrep --no-heading" opt.grepformat = "%f:%l:%c:%m,%f:%l:%m" end -- error bells opt.errorbells = false opt.visualbell = true opt.timeoutlen = 500 -- Appearance --------------------------------------------------------- o.termguicolors = true opt.number = true -- show line numbers opt.wrap = true -- turn on line wrapping opt.wrapmargin = 8 -- wrap lines when coming within n characters from side opt.linebreak = true -- set soft wrapping opt.showbreak = "↪" opt.autoindent = true -- automatically set indent of new line opt.ttyfast = true -- faster redrawing table.insert(opt.diffopt, "vertical") table.insert(opt.diffopt, "iwhite") table.insert(opt.diffopt, "internal") table.insert(opt.diffopt, "algorithm:patience") table.insert(opt.diffopt, "hiddenoff") opt.laststatus = 2 -- show the status line all the time opt.scrolloff = 7 -- set 7 lines to the cursors - when moving vertical opt.wildmenu = true -- enhanced command line completion opt.hidden = true -- current buffer can be put into background opt.showcmd = true -- show incomplete commands opt.showmode = true -- don't show which mode disabled for PowerLine opt.wildmode = {"list", "longest"} -- complete files like a shell opt.shell = env.SHELL opt.cmdheight = 1 -- command bar height opt.title = true -- set terminal title opt.showmatch = true -- show matching braces opt.mat = 2 -- how many tenths of a second to blink opt.updatetime = 300 opt.signcolumn = "yes" opt.shortmess = "atToOFc" -- prompt message options -- Tab control opt.smarttab = true -- tab respects 'tabstop', 'shiftwidth', and 'softtabstop' opt.tabstop = 4 -- the visible width of tabs opt.softtabstop = 4 -- edit as if the tabs are 4 characters wide opt.shiftwidth = 4 -- number of spaces to use for indent and unindent opt.shiftround = true -- round indent to a multiple of 'shiftwidth' -- code folding settings cmd [[set foldmethod=expr]] -- use treesitter folding support cmd [[set foldexpr=nvim_treesitter#foldexpr()]] opt.foldlevelstart = 99 opt.foldnestmax = 10 -- deepest fold is 10 levels opt.foldenable = false -- don't fold by default opt.foldlevel = 1 -- toggle invisible characters opt.list = true opt.listchars = { tab = "→ ", eol = "¬", trail = "⋅", extends = "❯", precedes = "❮" } -- Mappings g.mapleader = "," opt.pastetoggle = "v" nnoremap("Q", "") imap("jk", "") nmap(",", ":w") nmap("", ":set hlsearch! hlsearch?") nmap("", [[:%s/\s\+$]]) nmap("", [[:%s/\n\{2,}/\r\r/g]]) nmap("l", ":set list!") inoremap("", [[v:lua.completion_nvim.smart_pumvisible('', '')]], {expr = true}) inoremap("", [[v:lua.completion_nvim.smart_pumvisible('', '')]], {expr = true}) vmap("<", "", ">gv") nmap(".", "") vmap(".", ":normal .") nmap("", "WinMoveLeft") nmap("", "WinMoveDown") nmap("", "WinMoveUp") nmap("", "WinMoveRight") -- helpers for dealing with other people's code nmap([[\t]], ":set ts=4 sts=4 sw=4 noet") nmap([[\s]], ":set ts=4 sts=4 sw=4 et") nmap("z", "Zoom") -- move line mappings local opt_h = "˙" local opt_j = "∆" local opt_k = "˚" local opt_l = "¬" nnoremap(opt_h, ":cprevzz") nnoremap(opt_l, ":cnextzz") nnoremap(opt_j, ":m .+1==") nnoremap(opt_k, ":m .-2==") inoremap(opt_j, ":m .+1==gi") inoremap(opt_k, ":m .-2==gi") vnoremap(opt_j, ":m '>+1gv=gv") vnoremap(opt_k, ":m '<-2gv=gv") -- TODO: what exactly does this do? vnoremap("$(", "`>a)`") vnoremap("$[", "`>a]`") vnoremap("${", "`>a}`") vnoremap([[$']], [[`>a"`]]) vnoremap("$'", "`>a'`") vnoremap([[$\]], "`>o*/`") vnoremap([[$<]], "`>a>`") nmap("i", ":set cursorline!") -- scroll the viewport faster nnoremap("", "3") nnoremap("", "3") -- moving up and down work as you would expect nnoremap("j", 'v:count == 0 ? "gj" : "j"', {expr = true}) nnoremap("k", 'v:count == 0 ? "gk" : "k"', {expr = true}) nnoremap("^", 'v:count == 0 ? "g^" : "^"', {expr = true}) nnoremap("$", 'v:count == 0 ? "g$" : "$"', {expr = true}) -- custom text objects -- inner-line xmap("il", ":normal! g_v^") omap("il", ":normal! g_v^") -- around line vmap("al", ":normal! $v0") omap("al", ":normal! $v0") -- interesting word mappings nmap("0", "ClearInterestingWord") nmap("1", "HiInterestingWord1") nmap("2", "HiInterestingWord2") nmap("3", "HiInterestingWord3") nmap("4", "HiInterestingWord4") nmap("5", "HiInterestingWord5") nmap("6", "HiInterestingWord6") -- open current buffer in a new tab nmap("gTT", ":tab sb") require("plugins") if fn.filereadable(fn.expand("~/.vimrc_background")) then g.base16colorspace = 256 cmd [[source ~/.vimrc_background]] end cmd [[syntax on]] cmd [[filetype plugin indent on]] cmd [[syntax on]] cmd [[filetype plugin indent on]] -- make the highlighting of tabs and other non-text less annoying cmd [[highlight SpecialKey ctermfg=19 guifg=#333333]] cmd [[highlight NonText ctermfg=19 guifg=#333333]] -- make comments and HTML attributes italic cmd [[highlight Comment cterm=italic term=italic gui=italic]] cmd [[highlight htmlArg cterm=italic term=italic gui=italic]] cmd [[highlight xmlAttrib cterm=italic term=italic gui=italic]] -- highlight Type cterm=italic term=italic gui=italic cmd [[highlight Normal ctermbg=none]] -- make the StatusLine background match the GalaxyLine styles cmd("hi StatusLine guibg=" .. colors.bg)