diff options
author | Nicholas Noll <nbnoll@eml.cc> | 2021-09-09 16:46:00 -0700 |
---|---|---|
committer | Nicholas Noll <nbnoll@eml.cc> | 2021-09-09 16:46:00 -0700 |
commit | 5be9f3619243706b8fa201ae725ef219039aa1b3 (patch) | |
tree | edc655d7340c5d611cad237b3a45019c09072d98 | |
parent | db877acd7bff561aec115c5dec6c9eac8a444cde (diff) |
feat: moved to lua only init system
-rw-r--r-- | .config/nvim/init.lua | 34 | ||||
-rw-r--r-- | .config/nvim/lua/function.lua | 33 | ||||
-rw-r--r-- | .config/nvim/lua/keybind.lua | 53 | ||||
-rw-r--r-- | .config/nvim/lua/lsp.lua | 40 | ||||
-rw-r--r-- | .config/nvim/lua/settings.lua | 151 | ||||
-rw-r--r-- | .config/nvim/lua/theme.lua | 15 | ||||
-rwxr-xr-x | .config/nvim/pack/vendor/install | 46 | ||||
-rw-r--r-- | .config/nvim/pack/vendor/packages | 23 | ||||
-rwxr-xr-x | .config/nvim/pack/vendor/update | 17 |
9 files changed, 412 insertions, 0 deletions
diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua new file mode 100644 index 0000000..86824e6 --- /dev/null +++ b/.config/nvim/init.lua @@ -0,0 +1,34 @@ +local home = vim.env.HOME +local config = home .. '/.config/nvim' +local root = vim.env.USER == 'root' +local vi = vim.v.progname == 'vi' + +-------------------------------------------------------------------------- +-- plugins + +local packages = string.gmatch(vim.fn.glob(config .. "/pack/vendor/opt/*"), "[^\n]+") + +for package in packages do + local basename, _ = package:gsub("(.*/)(.*)", "%2") + if vim.v.vim_did_enter == 1 then + vim.cmd("packadd " .. basename) + else + vim.cmd("packadd! " .. basename) + end +end +vim.cmd("packadd termdebug") + +-------------------------------------------------------------------------- +-- commands + +vim.cmd('filetype indent plugin on') +vim.cmd('syntax on') + +-------------------------------------------------------------------------- +-- includes + +require("settings") +require("theme") +require("function") +require("keybind") +require("lsp") diff --git a/.config/nvim/lua/function.lua b/.config/nvim/lua/function.lua new file mode 100644 index 0000000..d0327fd --- /dev/null +++ b/.config/nvim/lua/function.lua @@ -0,0 +1,33 @@ +-------------------------------------------------------------------------- +-- tmux / nvim pane unification + +function navigate_nvim(direction) + vim.cmd('wincmd ' .. direction) +end + +function navigate_l_nvim() navigate_nvim('h') end +function navigate_r_nvim() navigate_nvim('l') end +function navigate_u_nvim() navigate_nvim('k') end +function navigate_d_nvim() navigate_nvim('j') end + +tmux_map = { ['h'] = 'L', ['j'] = 'D', ['k'] = 'U', ['l'] = 'R' } + +function navigate_tmux(direction) + local socket = vim.fn.split(vim.env.TMUX, ',')[1] + + local winnr = vim.fn.winnr() + navigate_nvim(direction) + local notmove = (winnr == vim.fn.winnr()) + + if notmove then + vim.fn.system("tmux -S " .. socket .. " select-pane -" .. tmux_map[direction]) + end +end + +function navigate_l_tmux() navigate_tmux('h') end +function navigate_r_tmux() navigate_tmux('l') end +function navigate_u_tmux() navigate_tmux('k') end +function navigate_d_tmux() navigate_tmux('j') end + +-------------------------------------------------------------------------- +-- autoformatting diff --git a/.config/nvim/lua/keybind.lua b/.config/nvim/lua/keybind.lua new file mode 100644 index 0000000..929b449 --- /dev/null +++ b/.config/nvim/lua/keybind.lua @@ -0,0 +1,53 @@ +vim.g.mapleader = ' ' +vim.g.maplocalleader = '\\' + +-------------------------------------------------------------------------- +-- normal + +vim.api.nvim_set_keymap("n", "Q", "q", {}) +vim.api.nvim_set_keymap("n", "Y", "y$", { noremap = true }) + +if vim.env.TMUX ~= nil then + vim.api.nvim_set_keymap("n", "<C-h>", ":lua navigate_l_tmux() <CR>", { noremap = true, silent = true }) + vim.api.nvim_set_keymap("n", "<C-l>", ":lua navigate_r_tmux() <CR>", { noremap = true, silent = true }) + vim.api.nvim_set_keymap("n", "<C-k>", ":lua navigate_u_tmux() <CR>", { noremap = true, silent = true }) + vim.api.nvim_set_keymap("n", "<C-j>", ":lua navigate_d_tmux() <CR>", { noremap = true, silent = true }) +else + vim.api.nvim_set_keymap("n", "<C-h>", ":lua navigate_l_nvim() <CR>", { noremap = true, silent = true }) + vim.api.nvim_set_keymap("n", "<C-l>", ":lua navigate_r_nvim() <CR>", { noremap = true, silent = true }) + vim.api.nvim_set_keymap("n", "<C-k>", ":lua navigate_u_nvim() <CR>", { noremap = true, silent = true }) + vim.api.nvim_set_keymap("n", "<C-j>", ":lua navigate_d_nvim() <CR>", { noremap = true, silent = true }) +end + +vim.api.nvim_set_keymap("n", "<Leader>f", ":Files<CR>", { noremap = true, silent = true }) +vim.api.nvim_set_keymap("n", "<Leader>b", ":Buffers<CR>", { noremap = true, silent = true }) +vim.api.nvim_set_keymap("n", "<Leader>l", ":Lines<CR>", { noremap = true, silent = true }) +vim.api.nvim_set_keymap("n", "<Leader>w", ":BLines<CR>", { noremap = true, silent = true }) + +vim.api.nvim_set_keymap("n", "<Leader>o", ":only<CR>", { noremap = true, silent = true }) +vim.api.nvim_set_keymap("n", "<Leader>|", ":wincmd |<CR>", { noremap = true, silent = true }) +vim.api.nvim_set_keymap("n", "<Leader>=", ":wincmd =<CR>", { noremap = true, silent = true }) +vim.api.nvim_set_keymap("n", "<Leader>r", ":wincmd R<CR>", { noremap = true, silent = true }) + +vim.api.nvim_set_keymap("n", "<Leader><Leader>d", ":Termdebug<CR>", { noremap = true, silent = true }) +vim.api.nvim_set_keymap("n", "<Leader><Leader>b", ":Break<CR>", { noremap = true, silent = true }) +vim.api.nvim_set_keymap("n", "<Leader><Leader><S-b>", ":Clear<CR>", { noremap = true, silent = true }) + +-------------------------------------------------------------------------- +-- insert + +vim.api.nvim_set_keymap("i", "<C-D>", "·", { noremap = true }) + +-------------------------------------------------------------------------- +-- visual + +vim.api.nvim_set_keymap("x", "<C-h>", "<C-w>h", { noremap = true }) +vim.api.nvim_set_keymap("x", "<C-j>", "<C-w>j", { noremap = true }) +vim.api.nvim_set_keymap("x", "<C-k>", "<C-w>k", { noremap = true }) +vim.api.nvim_set_keymap("x", "<C-l>", "<C-w>l", { noremap = true }) + +-------------------------------------------------------------------------- +-- keybind + +vim.api.nvim_set_keymap("c", "<C-a>", "<Home>", { noremap = true }) +vim.api.nvim_set_keymap("c", "<C-e>", "<End>", { noremap = true }) diff --git a/.config/nvim/lua/lsp.lua b/.config/nvim/lua/lsp.lua new file mode 100644 index 0000000..33f71e8 --- /dev/null +++ b/.config/nvim/lua/lsp.lua @@ -0,0 +1,40 @@ +local lsp = require('lspconfig') + +local setup = function(client, buffer) + local function set_keymap(...) vim.api.nvim_buf_set_keymap(buffer, ...) end + local function set_option(...) vim.api.nvim_buf_set_option(buffer, ...) end + + set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') + + local opts = { noremap=true, silent=true } + + set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts) + set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts) + set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts) + set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts) + set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts) + set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts) + set_keymap('n', '[c', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts) + set_keymap('n', ']c', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts) + set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts) + --[[ + set_keymap('n', '<space>dt', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts) + set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts) + --]] +end + +local servers = { 'clangd', 'julials', 'tsserver' } +for _, s in ipairs(servers) do + lsp[s].setup { + on_attach=setup, + flags = { + debounce_text_changes = 150, + } + } +end + +vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( + vim.lsp.diagnostic.on_publish_diagnostics, { + virtual_text = false + } +) diff --git a/.config/nvim/lua/settings.lua b/.config/nvim/lua/settings.lua new file mode 100644 index 0000000..b8c9440 --- /dev/null +++ b/.config/nvim/lua/settings.lua @@ -0,0 +1,151 @@ +-------------------------------------------------------------------------- +-- vanilla settings + +local home = vim.env.HOME +local opt = vim.opt +local tmp = home .. '/.vim/tmp' + +opt.autoindent = true -- maintain indent of current line +opt.backspace = 'indent,start,eol' -- allow unrestricted backspacing in insert mode +opt.backup = false -- don't make backups before writing +opt.backupcopy = 'yes' -- overwrite files to update, instead of renaming + rewriting +opt.backupdir = tmp .. '/backup//' -- keep backup files out of the way (ie. if 'backup' is ever set) +opt.backupdir = opt.backupdir + '.' -- fallback +opt.backupskip = opt.backupskip + '*.re,*.rei' -- prevent bsb's watch mode from getting confused (if 'backup' is ever set) +opt.belloff = 'all' -- never ring the bell for any reason +opt.cursorline = true -- highlight current line +opt.diffopt = opt.diffopt + 'foldcolumn:0' -- don't show fold column in diff view +opt.directory = tmp .. '/swap//' -- keep swap files out of the way +opt.directory = opt.directory + '.' -- fallback +opt.emoji = false -- don't assume all emoji are double width +opt.expandtab = true -- always use spaces instead of tabs +opt.fillchars = { + diff = '∙', -- BULLET OPERATOR (U+2219, UTF-8: E2 88 99) + eob = ' ', -- NO-BREAK SPACE (U+00A0, UTF-8: C2 A0) to suppress ~ at EndOfBuffer + fold = '·', -- MIDDLE DOT (U+00B7, UTF-8: C2 B7) + vert = '┃', -- BOX DRAWINGS HEAVY VERTICAL (U+2503, UTF-8: E2 94 83) +} +opt.foldlevelstart = 99 -- start unfolded +opt.foldmethod = 'syntax' -- not as cool as syntax, but faster +opt.formatoptions = opt.formatoptions + 'j' -- remove comment leader when joining comment lines +opt.formatoptions = opt.formatoptions + 'n' -- smart auto-indenting inside numbered lists +opt.guifont = 'Inconsolata' +opt.hidden = true -- allows you to hide buffers with unsaved changes without being prompted +opt.inccommand = 'split' -- live preview of :s results +opt.incsearch = true -- live preview of search hits +opt.joinspaces = false -- don't autoinsert two spaces after '.', '?', '!' for join command +opt.laststatus = 2 -- always show status line +opt.lazyredraw = true -- don't bother updating screen during macro playback +opt.linebreak = true -- wrap long lines at characters in 'breakat' +opt.list = true -- show whitespace +opt.listchars = { + nbsp = '⦸', -- CIRCLED REVERSE SOLIDUS (U+29B8, UTF-8: E2 A6 B8) + extends = '»', -- RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK (U+00BB, UTF-8: C2 BB) + precedes = '«', -- LEFT-POINTING DOUBLE ANGLE QUOTATION MARK (U+00AB, UTF-8: C2 AB) + tab = '▷⋯', -- WHITE RIGHT-POINTING TRIANGLE (U+25B7, UTF-8: E2 96 B7) + MIDLINE HORIZONTAL ELLIPSIS (U+22EF, UTF-8: E2 8B AF) + trail = '•', -- BULLET (U+2022, UTF-8: E2 80 A2) +} + +if vi then + opt.loadplugins = false +end + +opt.modelines = 5 -- scan this many lines looking for modeline +opt.number = true -- show line numbers in gutter +opt.pumblend = 10 -- pseudo-transparency for popup-menu +opt.relativenumber = true -- show relative numbers in gutter +opt.ruler = true -- show row and column of cursor +opt.scrolloff = 3 -- start scrolling 3 lines before edge of viewport + +if root then + opt.shada = '' -- Don't create root-owned files. + opt.shadafile = 'NONE' +else + -- Defaults: + -- Neovim: !,'100,<50,s10,h + -- + -- - ! save/restore global variables (only all-uppercase variables) + -- - '100 save/restore marks from last 100 files + -- - <50 save/restore 50 lines from each register + -- - s10 max item size 10KB + -- - h do not save/restore 'hlsearch' setting + -- + -- Our overrides: + -- - '0 store marks for 0 files + -- - <0 don't save registers + -- - f0 don't store file marks + -- - n: store in ~/.config/nvim/ + -- + opt.shada = "'0,<0,f0,n~/.vim/tmp/shada" +end + +opt.shell = 'sh' -- shell to use for `!`, `:!`, `system()` etc. +opt.shiftround = false -- don't always indent by multiple of shiftwidth +opt.shiftwidth = 4 -- spaces per tab (when shifting) +opt.shortmess = opt.shortmess + 'A' -- ignore annoying swapfile messages +opt.shortmess = opt.shortmess + 'I' -- no splash screen +opt.shortmess = opt.shortmess + 'O' -- file-read message overwrites previous +opt.shortmess = opt.shortmess + 'T' -- truncate non-file messages in middle +opt.shortmess = opt.shortmess + 'W' -- don't echo "[w]"/"[written]" when writing +opt.shortmess = opt.shortmess + 'a' -- use abbreviations in messages eg. `[RO]` instead of `[readonly]` +opt.shortmess = opt.shortmess + 'c' -- completion messages +opt.shortmess = opt.shortmess + 'o' -- overwrite file-written messages +opt.shortmess = opt.shortmess + 't' -- truncate file messages at start +opt.showbreak = '↳ ' -- DOWNWARDS ARROW WITH TIP RIGHTWARDS (U+21B3, UTF-8: E2 86 B3) +opt.showcmd = false -- don't show extra info at end of command line +opt.sidescroll = 0 -- sidescroll in jumps because terminals are slow +opt.sidescrolloff = 3 -- same as scrolloff, but for columns +opt.smartindent = true -- auto-indent new line +opt.smarttab = true -- <tab>/<BS> indent/dedent in leading whitespace + +if not vi then + opt.softtabstop = -1 -- use 'shiftwidth' for tab/bs at end of line +end + +opt.spellcapcheck = '' -- don't check for capital letters at start of sentence +opt.splitbelow = true -- open horizontal splits below current window +opt.splitright = true -- open vertical splits to the right of the current window +opt.suffixes = opt.suffixes - '.h' -- don't sort header files at lower priority +opt.swapfile = false -- don't create swap files +opt.switchbuf = 'usetab' -- try to reuse windows/tabs when switching buffers +opt.synmaxcol = 200 -- don't bother syntax highlighting long lines +opt.tabstop = 4 -- spaces per tab +opt.termguicolors = true -- use guifg/guibg instead of ctermfg/ctermbg in terminal +opt.textwidth = 0 -- automatically hard wrap at 0 columns + +if root then + opt.undofile = false -- don't create root-owned files +else + opt.undodir = tmp .. '/undo//' -- keep undo files out of the way + opt.undodir = opt.undodir + '.' -- fallback + opt.undofile = true -- actually use undo files +end + +opt.updatetime = 2000 -- CursorHold interval +opt.updatecount = 0 -- update swapfiles every 80 typed chars +opt.viewdir = tmp .. '/view' -- where to store files for :mkview +opt.viewoptions = 'cursor,folds' -- save/restore just these (with `:{mk,load}view`) +opt.virtualedit = 'block' -- allow cursor to move where there is no text in visual block mode +opt.visualbell = true -- stop annoying beeping for non-error errors +opt.whichwrap = 'b,h,l,s,<,>,[,],~' -- allow <BS>/h/l/<Left>/<Right>/<Space>, ~ to cross line boundaries +opt.wildcharm = 26 -- ('<C-z>') substitute for 'wildchar' (<Tab>) in macros +opt.wildignore = opt.wildignore + '*.o,*.rej,*.so' -- patterns to ignore during file-navigation +opt.wildmenu = true -- show options as list when switching buffers etc +opt.wildmode = 'longest:full,full' -- shell-like autocomplete to unambiguous portion +opt.winblend = 10 -- psuedo-transparency for floating windows +opt.wrap = false -- no automatic line wraps +opt.wrapmargin = 0 -- no line wrapping +opt.writebackup = false -- don't keep backups after writing + +-------------------------------------------------------------------------- +-- plugin settings + +-- gdb debug +vim.g.termdebug_wide = 1 + +-- latex +vim.g.tex_flavor = "latex" + +-- git gutter +vim.g.gitgutter_grep = "" +vim.g.gitgutter_set_sign_backgrounds = 1 diff --git a/.config/nvim/lua/theme.lua b/.config/nvim/lua/theme.lua new file mode 100644 index 0000000..f4f5789 --- /dev/null +++ b/.config/nvim/lua/theme.lua @@ -0,0 +1,15 @@ +vim.cmd("colorscheme seoul256") + +vim.cmd("hi Normal guibg=NONE ctermbg=NONE") +vim.cmd("hi NonText guibg=NONE ctermbg=NONE") +vim.cmd("hi EndOfBuffer guibg=NONE ctermbg=NONE") +vim.cmd("hi LineNr guibg=NONE ctermbg=NONE") +vim.cmd("hi SignColumn guibg=NONE ctermbg=NONE") +vim.cmd("hi VertSplit guibg=NONE ctermbg=NONE ") + +vim.cmd("hi Pmenu ctermbg=237 ctermfg=NONE cterm=NONE guibg=#3a3a3a guifg=NONE gui=NONE") +vim.cmd("hi PmenuSbar ctermbg=236 ctermfg=NONE cterm=NONE guibg=#303030 guifg=NONE gui=NONE") +vim.cmd("hi PmenuSel ctermbg=236 ctermfg=140 cterm=NONE guibg=#303030 guifg=#af87d7 gui=NONE") +vim.cmd("hi PmenuThumb ctermbg=167 ctermfg=NONE cterm=NONE guibg=#d75f5f guifg=NONE gui=NONE") + +vim.cmd("set pumblend=10") diff --git a/.config/nvim/pack/vendor/install b/.config/nvim/pack/vendor/install new file mode 100755 index 0000000..9bcc676 --- /dev/null +++ b/.config/nvim/pack/vendor/install @@ -0,0 +1,46 @@ +#!/usr/bin/python + +import os, subprocess + +def noop(url): + print(f"> skipping {url}...") + +def package(url): + return url.split("/")[1] + +def github(url): + return subprocess.Popen(["git", "clone", f"https://github.com/{url}.git", f"opt/{package(url)}"]) + +hosts = {"github": github} + +def host(name): + key = name[1:-1].strip() + if key in hosts: + return hosts[key] + return noop + +if __name__ == "__main__": + clone = noop + if not os.path.isdir("opt"): + os.mkdir("opt") + + procs = [] + with open("packages") as io: + for url in io: + url = url.strip("\n") + # TODO: better comment removal + if len(url) == 0 or url.startswith("#"): + continue + + if url.startswith("[") and url.endswith("]"): + clone = host(url) + + else: + if os.path.isdir(f"opt/{package(url)}"): + print(f"> {package(url)} installed") + continue + + procs.append(clone(url)) + + for p in procs: + p.wait() diff --git a/.config/nvim/pack/vendor/packages b/.config/nvim/pack/vendor/packages new file mode 100644 index 0000000..b2a1808 --- /dev/null +++ b/.config/nvim/pack/vendor/packages @@ -0,0 +1,23 @@ +[ github ] + +neovim/nvim-lspconfig + +junegunn/seoul256.vim +junegunn/fzf.vim + +tpope/vim-surround +tpope/vim-repeat +tpope/vim-vinegar +tpope/vim-commentary +tpope/vim-git + +simeji/winresizer +adelarsq/vim-matchit +airblade/vim-gitgutter + +lervag/vimtex +plasticboy/vim-markdown +fatih/vim-go +JuliaEditorSupport/julia-vim +leafgarland/typescript-vim +peitalin/vim-jsx-typescript diff --git a/.config/nvim/pack/vendor/update b/.config/nvim/pack/vendor/update new file mode 100755 index 0000000..5dabe5c --- /dev/null +++ b/.config/nvim/pack/vendor/update @@ -0,0 +1,17 @@ +#!/usr/bin/python + +import os +import subprocess + +from glob import glob + +if __name__ == "__main__": + cwd = os.getcwd() + procs = [] + for repo in glob("opt/*/"): + os.chdir(repo) + procs.append(subprocess.Popen(["git", "pull"])) + os.chdir(cwd) + + for p in procs: + p.wait() |