-- Make local variables, instead of typing long commands over and over again. local map = vim.api.nvim_set_keymap local s = { silent = true } local function autocmd(event, pattern, cmd) vim.api.nvim_create_autocmd(event, { pattern = pattern, command = cmd, }) end --This function loads a table of options into vim.opt local function load(x) for name, value in pairs(x) do vim.opt[name] = value end end -- Set leader key to comma vim.g.mapleader = "," --Autoload function if vim.fn.filereadable(vim.fn.system('echo -n "${XDG_CONFIG_HOME:-$HOME/.config}/nvim/autoload/plug.vim"')) == 0 then print("Downloading junegunn/vim-plug to manage plugins...") vim.fn.system('mkdir -p ${XDG_CONFIG_HOME:-$HOME/.config}/nvim/autoload/') vim.fn.system('curl "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" > ${XDG_CONFIG_HOME:-$HOME/.config}/nvim/autoload/plug.vim') autocmd("VimEnter", "*", "PlugInstall") end map('n', ',,', [[:keepp /<++>ca<]], s) map('i', ',,', ':keepp /<++>ca<', s) -- Call plugins local Plug = vim.fn['plug#'] vim.call('plug#begin', (vim.fn['system']('echo -n "${XDG_CONFIG_HOME:-$HOME/.config}/nvim/plugged"'))) Plug 'tpope/vim-surround' Plug 'preservim/nerdtree' Plug 'junegunn/goyo.vim' Plug 'jreybert/vimagit' Plug 'vimwiki/vimwiki' Plug 'vim-airline/vim-airline' Plug 'tpope/vim-commentary' Plug 'ap/vim-css-color' Plug 'nvim-treesitter/nvim-treesitter' Plug 'neovim/nvim-lspconfig' Plug 'williamboman/mason.nvim' Plug 'williamboman/mason-lspconfig.nvim' Plug 'hrsh7th/nvim-cmp' Plug 'hrsh7th/cmp-nvim-lsp' Plug 'L3MON4D3/LuaSnip' Plug 'VonHeikemen/lsp-zero.nvim' Plug 'zbirenbaum/copilot.lua' Plug 'kchmck/vim-coffee-script' vim.call('plug#end') -- Set options local basics = { title = true, background = "light", go = "a", hlsearch = false, clipboard = "unnamedplus", showmode = false, ruler = false, laststatus = 0, showcmd = false, --filetype plugin on | this is default in neovim syntax = "on", -- this is default in neovim encoding = "utf-8", number = true, relativenumber = true, --Enable autocompletion: wildmode = "longest,list,full", splitright = true, splitbelow = true } -- Some basics vim.keymap.set("n", "c", '"_c', s) --Disables automatic commenting on newline: autocmd("FileType", "markdown", "setlocal formatoptions-=c formatoptions-=r formatoptions-=o") -- Perform dot commands over visual blocks: map("v", ".", ":normal .",s) --Goyo plugin makes text more readable when writing prose: map('n', 'f', ":Goyo | set bg=light | set linebreak",s) --Spell-check set to o, 'o' for 'orthography': map('n', 'o', ":setlocal spell! spelllang=en_us",s) --nerdtree map("n", "n", ":NERDTreeToggle",s) autocmd("bufenter *", "*", "if (winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree()) | q | endif") if vim.fn.has('nvim') == 1 then vim.b.NERDTreeBookmarksFile = vim.fn.stdpath('data') .. '/NERDTreeBookmarks' else vim.b.NERDTreeBookmarksFile = '~/.vim/NERDTreeBookmarks' end -- vimling map("n","d", ":call ToggleDeadKeys()",s) map("i", "d", ":call ToggleDeadKeys()a",s) map("n","i", ":call ToggleIPA()",s) map("i", "i", ":call ToggleIPA()a",s) map("n", "q", ":call ToggleProse()",s) --Shortcutting split navigation, saving a keypress: map("n", "", "h", s) map("n", "", "j", s) map("n", "", "k", s) map("n", "", "l", s) --Replace ex mode with gq map("n", "Q", "gq", s) --Check file in shellcheck: map("n", "s", ":!clear && spellcheck -x %", s) --Open my bibliography file in split map("n", "leader>b", ":vsp$BIB", s) map("n", "leader>r", ":vsp$REFER", s) --Replace all in aliased to S map('n', 'S', ":%s//g", s) --Compile document, be it groff/LaTeX/markdown/etc. map("n", "c", ":w! |!compiler '%:p'", s) --Open corresponding .pdf/.html or preview map("n", "p", ":!opout '%:p'", s) --Runs a script that cleans out tex build files whenever I close out of a .tex file. autocmd("VimLeave", "*.tex", "!texclear %") -- Ensure files are read as what I want: map("n", "v", ":VimwikiIndex", s) vim.g.vimwiki_ext2syntax = { ['.Rmd'] = 'markdown', ['.rmd'] = 'markdown', ['.md'] = 'markdown', ['.markdown'] = 'markdown', ['.mdown'] = 'markdown' } --Runs a script that cleans out tex build files whenever I close out of a .tex file. vim.g.vimwiki_list = { { path = '~/.local/share/nvim/vimwiki', syntax = 'markdown', ext = '.md' } } --Save file as sudo on files that require root permission vim.api.nvim_command('cabbrev w!! execute "silent! write !sudo tee % >/dev/null" edit!') --Enable markdown syntax for .md files autocmd({"BufRead", "BufNewFile"}, {"/tmp/calcurse*","~/.calcurse/notes/*"}, "set filetype=markdown") autocmd({"BufRead", "BufNewFile"}, {"*.ms", "*.me", "*.mom", "*.man"}, "set filetype=groff") autocmd({"BufRead", "BufNewFile"}, {"*.tex"}, "set filetype=tex") -- Enable Goyo by default for mutt writing autocmd({"BufRead", "BufNewFile"}, {"/tmp/neomutt*"}, "let g:goyo_width=80") autocmd({"BufRead", "BufNewFile"}, {"/tmp/neomutt*"}, "set bg=light") autocmd({"BufRead", "BufNewFile"}, {"/tmp/neomutt*"}, "map ZZ :Goyo|x!") autocmd({"BufRead", "BufNewFile"}, {"/tmp/neomutt*"}, "map ZQ :Goyo|q!") --Automatically deletes all trailing whitespace and newlines at end of file on save. & reset cursor position autocmd("BufWritePre", "*", "let currPos = getpos('.')") autocmd("BufWritePre", "*", "%s/\\s\\+$//e") autocmd("BufWritePre", "*", "%s/\\n\\+\\%$//e") autocmd("BufWritePre", "*", "cal cursor(currPos[1], currPos[2])") --When shortcut files are updated, renew bash and ranger configs with new material: autocmd("BufWritePost", "bm-files,bm-dirs", "!shortcuts") --Run xrdb whenever Xdefaults or Xresources are updated. autocmd("BufWritePost", "Xresources,Xdefaults,xresources,xdefaults", "set filetype=xdefaults") autocmd("BufWritePost", "Xresources,Xdefaults,xresources,xdefaults", "!xrdb %") --Recompile dwmblocks on config edit. autocmd("BufWritePost", "config.h", "!cd ~/.local/src/dwmblocks/; sudo make install && { killall -q dwmblocks;setsid -f dwmblocks }") -- Auto compile dwm on config.h change function compile_dwm_config() local current_file = vim.fn.expand('%:p') -- get current file path if current_file == os.getenv("HOME")..'/.local/src/dwm/config.h' then os.execute('cd ~/.local/src/dwm && sudo make clean install') end end autocmd("BufWritePost", "config.h", "lua compile_dwm_config()") --Turns off highlighting on the bits of code that are changed, so the line that is changed is highlighted but the actual text that has changed stands out on the line and is readable. if vim.opt.diff:get() then vim.cmd('highlight! link DiffText MatchParen') end --Function for toggling the bottom statusbar: local h = {hidden_all = 0} function Toggle_hidden_all() local hideOptions = {} if h.hidden_all == 0 then h.hidden_all = 1 hideOptions = { showmode = false, ruler = false, laststatus = 0, showcmd = false, } else h.hidden_all = 0 hideOptions = { showmode = true, ruler = true, laststatus = 2, showcmd = true, } end load(hideOptions) end vim.keymap.set('n', 'h', function() Toggle_hidden_all() end, {silent = true, noremap = true}) -- load options load(basics) vim.cmd('silent! source ~/.config/nvim/shortcuts.vim') require("victor")