-- Bootstrap the Packer plugin manager local execute = vim.api.nvim_command local fn = vim.fn local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' if fn.empty(fn.glob(install_path)) > 0 then fn.system({'git', 'clone', 'https://github.com/wbthomason/packer.nvim', install_path}) execute 'packadd packer.nvim' end -- Packer plugin installations local use = require('packer').use require('packer').startup(function() use 'wbthomason/packer.nvim' -- Maintain plugin manager use 'tpope/vim-eunuch' -- File manipulation in Vim use 'tpope/vim-vinegar' -- Fixes netrw file explorer use 'tpope/vim-fugitive' -- Git commands use 'tpope/vim-surround' -- Manipulate parentheses use 'tpope/vim-commentary' -- Use gc or gcc to add comments use 'tpope/vim-repeat' -- Actually repeat using . use 'christoomey/vim-tmux-navigator' -- Hotkeys for tmux panes use 'morhetz/gruvbox' -- Colorscheme use 'sheerun/vim-polyglot' -- Syntax for every language use 'phaazon/hop.nvim' -- Quick jump around the buffer use 'neovim/nvim-lspconfig' -- Language server linting use 'folke/lsp-colors.nvim' -- Pretty LSP highlights use 'jiangmiao/auto-pairs' -- Parentheses use 'rafamadriz/friendly-snippets' use 'hrsh7th/vim-vsnip' use 'hrsh7th/vim-vsnip-integ' use 'hrsh7th/nvim-compe' -- Auto-complete use 'godlygeek/tabular' -- Spacing and alignment use 'vimwiki/vimwiki' -- Wiki Markdown System use 'airblade/vim-rooter' -- Change directory to git route use 'itchyny/lightline.vim' -- Status bar use { -- Git next to line numbers 'lewis6991/gitsigns.nvim', requires = {'nvim-lua/plenary.nvim'}, config = function() require('gitsigns').setup() end } use { -- Fuzzy finder 'junegunn/fzf.vim', requires = {'/usr/local/opt/fzf'} } -- use 'ludovicchabant/vim-gutentags' -- Good for autogen tags end) -- LSP Plugins require('lspconfig').rust_analyzer.setup{} require('lspconfig').pyright.setup{ cmd = { "poetry", "run", "pyright-langserver", "--stdio" } } require'compe'.setup({ enabled = true, source = { path = true, buffer = true, nvim_lsp = true, }, }) -- Auto-complete -- ==================== -- Auto-complete mapping local t = function(str) return vim.api.nvim_replace_termcodes(str, true, true, true) end local check_back_space = function() local col = vim.fn.col('.') - 1 if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then return true else return false end end -- Use (s-)tab to: --- move to prev/next item in completion menuone --- jump to prev/next snippet's placeholder _G.tab_complete = function() if vim.fn.pumvisible() == 1 then return t "" elseif vim.fn.call("vsnip#available", {1}) == 1 then return t "(vsnip-expand-or-jump)" elseif check_back_space() then return t "" else return vim.fn['compe#complete']() end end _G.s_tab_complete = function() if vim.fn.pumvisible() == 1 then return t "" elseif vim.fn.call("vsnip#jumpable", {-1}) == 1 then return t "(vsnip-jump-prev)" else return t "" end end -- Auto-complete keybinds vim.api.nvim_set_keymap("i", "", "v:lua.tab_complete()", {expr = true}) vim.api.nvim_set_keymap("s", "", "v:lua.tab_complete()", {expr = true}) vim.api.nvim_set_keymap("i", "", "v:lua.s_tab_complete()", {expr = true}) vim.api.nvim_set_keymap("s", "", "v:lua.s_tab_complete()", {expr = true}) -- Settings -- ======== -- Basic Settings vim.o.termguicolors = true -- Set to truecolor vim.cmd[[colorscheme gruvbox]] -- Installed with a plugin vim.o.hidden = true -- Don't unload buffers when leaving them vim.wo.number = true -- Show line numbers vim.wo.relativenumber = true -- Relative numbers instead of absolute vim.o.list = true -- Reveal whitespace with dashes vim.o.expandtab = true -- Tabs into spaces vim.o.shiftwidth = 4 -- Amount to shift with > key vim.o.softtabstop = 4 -- Amount to shift with key vim.o.ignorecase = true -- Ignore case when searching vim.o.smartcase = true -- Check case when using capitals in search vim.o.infercase = true -- Don't match cases when completing suggestions vim.o.incsearch = true -- Search while typing vim.o.visualbell = true -- No sounds vim.o.scrolljump = 1 -- Number of lines to scroll vim.o.scrolloff = 3 -- Margin of lines to see while scrolling vim.o.splitright = true -- Vertical splits on the right side vim.o.splitbelow = true -- Horizontal splits on the bottom side vim.o.pastetoggle = "" -- Use F3 to enter raw paste mode vim.o.clipboard = "unnamedplus" -- Uses system clipboard for yanking vim.o.updatetime = 300 -- Faster diagnostics vim.o.mouse = "nv" -- Mouse interaction / scrolling -- Neovim features vim.o.inccommand = "split" -- Live preview search and replace vim.o.completeopt = "menuone,noselect" -- Required for nvim-compe completion -- Remember last position when reopening file vim.api.nvim_exec([[ if has("autocmd") au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal! g`\"" | endif endif ]], false) -- Better backup, swap and undo storage vim.o.backup = true -- Easier to recover and more secure vim.bo.swapfile = false -- Instead of swaps, create backups vim.bo.undofile = true -- Keeps undos after quit -- Create backup directories if they don't exist vim.api.nvim_exec([[ set backupdir=~/.local/share/nvim/backup set undodir=~/.local/share/nvim/undo if !isdirectory(&backupdir) call mkdir(&backupdir, "p") endif if !isdirectory(&undodir) call mkdir(&undodir, "p") endif ]], false) -- Keep selection when tabbing vim.api.nvim_set_keymap("v", "<", "", ">gv", {noremap=true}) -- Force filetype patterns that Vim doesn't know about vim.api.nvim_exec([[ au BufRead,BufNewFile *.Brewfile setfiletype brewfile au BufRead,BufNewFile tmux.conf* setfiletype tmux au BufRead,BufNewFile *ignore.*link setfiletype gitignore au BufRead,BufNewFile gitconfig.*link setfiletype gitconfig au BufRead,BufNewFile *.toml.*link setfiletype toml au BufRead,BufNewFile .env* set ft=text | set syntax=sh ]], false) -- LaTeX options vim.api.nvim_exec([[ au FileType tex inoremap ;bf \textbf{}i au BufWritePost *.tex silent! execute "!pdflatex -output-directory=%:p:h % >/dev/null 2>&1" | redraw! ]], false) -- Highlight when yanking vim.api.nvim_exec([[ au TextYankPost * silent! lua vim.highlight.on_yank { timeout = 250 } ]], false) -- Auto-pairs vim.g.AutoPairsFlyMode = 1 -- Netrw vim.g.netrw_liststyle = 3 -- Change style to 'tree' view vim.g.netrw_banner = 0 -- Remove useless banner vim.g.netrw_winsize = 15 -- Explore window takes % of page vim.g.netrw_browse_split = 4 -- Open in previous window vim.g.netrw_altv = 1 -- Always split left -- Polyglot vim.g.terraform_fmt_on_save = 1 -- Formats with terraform plugin vim.g.rustfmt_autosave = 1 -- Formats with rust plugin -- VimWiki vim.g.vimwiki_list = { { ["path"] = "$NOTES_PATH", ["syntax"] = "markdown", ["index"] = "home", ["ext"] = ".md" } } vim.g.vimwiki_key_mappings = { ["all_maps"] = 1, ["mouse"] = 1, } vim.g.vimwiki_auto_chdir = 1 -- Set local dir to Wiki when open vim.g.vimwiki_create_link = 0 -- Don't automatically create new links vim.g.vimwiki_listsyms = " x" -- Set checkbox symbol progression vim.g.vimwiki_table_mappings = 0 -- VimWiki table keybinds interfere with tab completion vim.api.nvim_exec([[ au FileType markdown inoremap ;tt :AddTag function! PInsert(item) let @z=a:item norm "zpx endfunction command! AddTag call fzf#run({'source': 'rg "#[\w/]+[ |\$]" -o --no-filename --no-line-number | sort | uniq', 'sink': function('PInsert')}) ]], false) -- Lightline status bar vim.g.lightline = { ["colorscheme"] = "jellybeans", ["active"] = { ["right"] = { { "lineinfo" } }, ["left"] = { { "mode", "paste" }, { "readonly", "relativepath", "gitbranch", "modified" } } }, ["component_function"] = { ["gitbranch"] = "fugitive#head" }, } -- Remap space as leader key vim.api.nvim_set_keymap("", "", "", {noremap=true, silent=true}) vim.g.mapleader = " " vim.g.maplocalleader = " " -- Unset search pattern register vim.api.nvim_set_keymap("n", "", ":noh", {noremap=true, silent=true}) -- Shuffle lines around vim.api.nvim_set_keymap("n", "", ":m .+1==", {noremap=true}) vim.api.nvim_set_keymap("n", "", ":m .-2==", {noremap=true}) vim.api.nvim_set_keymap("i", "", ":m .+1==gi", {noremap=true}) vim.api.nvim_set_keymap("i", "", ":m .-2==gi", {noremap=true}) vim.api.nvim_set_keymap("v", "", ":m '>+1gv=gv", {noremap=true}) vim.api.nvim_set_keymap("v", "", ":m '<-2gv=gv", {noremap=true}) -- Fzf (fuzzy finder) vim.api.nvim_set_keymap("n", "/", ":Rg", {noremap=true}) vim.api.nvim_set_keymap("n", "ff", ":Files", {noremap=true}) vim.api.nvim_set_keymap("n", "fr", ":History", {noremap=true}) vim.api.nvim_set_keymap("n", "b", ":Buffers", {noremap=true}) vim.api.nvim_set_keymap("n", "s", ":BLines", {noremap=true}) -- File commands vim.api.nvim_set_keymap("n", "q", ":quit", {noremap=true}) vim.api.nvim_set_keymap("n", "Q", ":quitall", {noremap=true}) vim.api.nvim_set_keymap("n", "fs", ":write", {noremap=true}) vim.api.nvim_set_keymap("n", "fe", ":!chmod 755 %", {noremap=true}) vim.api.nvim_set_keymap("n", "fn", ":!chmod 644 %", {noremap=true}) vim.api.nvim_set_keymap("n", "fd", ":lcd %:p:h", {silent=true, noremap=true}) vim.api.nvim_set_keymap("n", "fu", ":lcd ..", {silent=true, noremap=true}) vim.api.nvim_set_keymap("n", "", ":b#", {silent=true, noremap=true}) vim.api.nvim_set_keymap("n", "gr", ":!gh repo view -w", {silent=true, noremap=true}) vim.api.nvim_set_keymap("n", "tt", [[exe 'edit ~/notes/journal/'.strftime("%Y-%m-%d_%a").'.md']], {noremap=true}) -- Window commands vim.api.nvim_set_keymap("n", "wv", ":vsplit", {noremap=true}) vim.api.nvim_set_keymap("n", "wh", ":split", {noremap=true}) vim.api.nvim_set_keymap("n", "wm", ":only", {noremap=true}) -- Tabularize vim.api.nvim_set_keymap("", "ta", ":Tabularize /", {noremap=true}) vim.api.nvim_set_keymap("", "t#", ":Tabularize /#", {noremap=true}) vim.api.nvim_set_keymap("", "t\"", ":Tabularize /\"", {noremap=true}) -- Vimrc vim.api.nvim_set_keymap("n", "fv", ":edit $MYVIMRC", {noremap=true}) vim.api.nvim_set_keymap("n", "rr", ":luafile $MYVIMRC", {noremap=true}) -- Other vim.api.nvim_set_keymap("n", "", ":HopWord", {noremap=true}) vim.api.nvim_set_keymap("t", "", "", {noremap=true}) -- Exit terminal mode vim.api.nvim_set_keymap('n', 'Y', 'y$', { noremap = true})