let g:loaded_netrw = 1 let g:loaded_netrwPlugin = 1 if filereadable('/etc/hostname') let hostname=join(readfile('/etc/hostname')) else let hostname='unknown' endif let g:vsnip_snippet_dir = "~/.config/nvim/snippets" let g:vsnip_snippet_dirs = ["~/.config/nvim/local/snippets"] call plug#begin() if filereadable(printf('%s/.config/nvim/local-plug.vim', $HOME)) exec "source " . printf('%s/.config/nvim/local-plug.vim', $HOME) endif Plug 'nvim-lua/lsp-status.nvim' Plug 'bfrg/vim-jq' Plug 'folke/trouble.nvim' Plug 'git@git.josher.dev:bulletjava.vim.git' Plug 'git@git.josher.dev:fieldmarshal.vim.git' Plug 'git@git.josher.dev:nvim-color-picker.git' Plug 'git@git.josher.dev:nvim-warp.git' Plug 'git@git.josher.dev:meltdown.git' Plug 'google/vim-codefmt' Plug 'google/vim-glaive' Plug 'google/vim-maktaba' Plug 'hrsh7th/cmp-buffer' Plug 'hrsh7th/cmp-nvim-lsp' Plug 'hrsh7th/cmp-nvim-lua' Plug 'hrsh7th/cmp-path' Plug 'hrsh7th/cmp-vsnip' Plug 'hrsh7th/nvim-cmp' Plug 'hrsh7th/vim-vsnip' Plug 'kyazdani42/nvim-web-devicons' " Plug 'lukas-reineke/virt-column.nvim' Plug 'nanozuki/tabby.nvim' Plug 'neovim/nvim-lspconfig' Plug 'nvim-lua/plenary.nvim' Plug 'nvim-lualine/lualine.nvim' Plug 'nvim-telescope/telescope.nvim' Plug 'nvim-tree/nvim-tree.lua' Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} Plug 'nvim-treesitter/nvim-treesitter-textobjects' Plug 'onsails/lspkind.nvim' " Plug 'tpope/vim-surround' Plug 'kylechui/nvim-surround' Plug 'vito-c/jq.vim' Plug 'EdenEast/nightfox.nvim' Plug 'sphamba/smear-cursor.nvim' Plug 'smoka7/hop.nvim' Plug 'lewis6991/gitsigns.nvim' if exists('&userregfunc') Plug 'git@git.josher.dev:rneovim-userregs.git' endif Plug 'git@git.josher.dev:config.vim.git', \ { 'dir': g:plug_home . '/config.vim', \ 'do': ':UpdateInitVimHook' } call plug#end() command! UpdateInitVimHook source ~/.config/nvim/init.vim PlugInstall set termguicolors set shiftwidth=2 set tabstop=2 set expandtab set nowrap set splitright set splitbelow set wildmode=longest,list,full set scrolloff=8 set number set relativenumber set pumheight=20 set updatetime=1000 set matchpairs+=<:> let mapleader=" " function! Jump(...) normal! `[ endfunction noremap g. set operatorfunc=Jumpg@ " Make splitting more congruent with how Tmux does it. noremap % v noremap " s " Open a terminal in a split below the current file. noremap sterm " Opens a terminal in the directory the current file is in. noremap sTERM " Fix the yank behavior. noremap Y y$ " Format code. This is vnoremap ú :FormatLines noremap ú lua run_format_code() " Synstack to help profile syntax highlighting issues. noremap p (SynStack) " Way to find files. noremap ff Telescope find_files noremap Telescope find_files noremap Telescope find_files function! s:find_in_dir() exec "Telescope find_files search_dirs={\"" . escape(resolve(expand('%:h')), ' ') . "\"} path_display={\"shorten\"} hidden=true" endfunction noremap call find_in_dir() inoremap (vsnip-expand) " When navigating to the beginning of a line, I want to always reset the screen " to the leftmost position. noremap ^ ^zH noremap to Telescope oldfiles noremap ta Telescope autocommands noremap tbu Telescope buffers noremap T Telescope builtin noremap tcs Telescope colorscheme noremap tch Telescope command_history noremap tco Telescope commands noremap t/ Telescope current_buffer_fuzzy_find noremap tcbt Telescope current_buffer_tags noremap td Telescope diagnostics noremap tf Telescope find_files noremap tgb Telescope git_branches noremap tgc Telescope git_commits noremap tgf Telescope git_files noremap tgs Telescope git_stash noremap tgr Telescope grep_string noremap thi Telescope highlights noremap tjl Telescope jumplist noremap tlg Telescope live_grep noremap tll Telescope loclist noremap t[d Telescope lsp_definitions noremap t[s Telescope lsp_document_symbols noremap t[w Telescope lsp_dynamic_workspace_symbols noremap t[i Telescope lsp_implementations noremap t[r Telescope lsp_incoming_calls noremap t[n Telescope lsp_outgoing_calls noremap t[e Telescope lsp_references noremap t[t Telescope lsp_type_definitions noremap t? Telescope man_pages noremap t' Telescope marks noremap tp Telescope pickers noremap tqf Telescope quickfix noremap tqh Telescope quickfixhistory noremap t" Telescope registers noremap th/ Telescope search_history noremap tz Telescope spell_suggest noremap ty Telescope symbols noremap tt Telescope tags noremap tst Telescope tagstack noremap tsit Telescope treesitter noremap tv Telescope vim_options augroup InitVim au! " Automatically stop highligting things when leaving insert mode. If I want " the highlight back, I can just hit 'n' and it will come back. " " I don't know why it can't just be 'noh' and why I have to do this feedkeys " nonsense, but there appears to be a bug of some kind. autocmd InsertLeave * call feedkeys("\noh\") autocmd TextYankPost * \ lua require'vim.hl'.on_yank( \ { higroup = "IncSearch", timeout = 100 }); " autocmd CursorHold * lua vim.lsp.buf.document_highlight() " autocmd CursorHoldI * lua vim.lsp.buf.document_highlight() " autocmd CursorMoved * lua vim.lsp.buf.clear_references() augroup END " Local configuration that can be set by hostname or just a local configuration. " Local files are ignored by .gitignore so they won't be added to the repo, " allowing local (*cough* work) configuration to be separate from general " configuration. if isdirectory(printf('%s/.config/nvim/%s', $HOME, hostname)) exec "set rtp+=" . printf('%s/.config/nvim/%s', $HOME, hostname) endif if isdirectory(printf('%s/.config/nvim/local', $HOME)) exec "set rtp+=" . printf('%s/.config/nvim/local', $HOME) endif if filereadable(printf('%s/.config/nvim/%s.vim', $HOME, hostname)) exec "source " . printf('%s/.config/nvim/%s.vim', $HOME, hostname) endif if filereadable(printf('%s/.config/nvim/local.vim', $HOME)) exec "source " . printf('%s/.config/nvim/local.vim', $HOME) endif if isdirectory(printf('%s/.config/nvim/after', $HOME)) exec "set rtp+=" . printf('%s/.config/nvim/after', $HOME) endif noremap nt NvimTreeToggle noremap :e =escape(expand('%:h'), ' \')/ noremap . lua require('windownav').goto_terminal() noremap I lua require('windownav').goto_initvim() noremap ' lua require('windownav').goto_lastwin() nnoremap termstartinsert nnoremap TERMstartinsert nnoremap nnoremap Telescope buffers nnoremap bnext nnoremap bprev noremap lua vim.diagnostic.open_float() noremap WarpFull noremap WarpGrid onoremap vWarpGrid noremap w WarpWords onoremap w vWarpWords " - search within last visual selection. noremap  /\%V nmap œ k nmap ï j omap œ k omap ï j omap aœ ak omap aï aj omap iœ ik omap iï ij vmap œ k vmap ï j noremap TSNodeUnderCursor noremap TSCaptureUnderCursor " Greek capital tau (τ) noremap Τ Inspect command! Config edit $HOME/.config/nvim/init.vim command! Configl edit $HOME/.config/nvim/local.vim cnoreabbrev _config expand("$HOME/.config/nvim") cnoreabbrev _plugged expand("$HOME/.local/share/nvim/plugged") cnoreabbrev _fm expand("$HOME/.local/share/nvim/plugged/fieldmarshal.vim") cnoreabbrev _home expand("$HOME/.local/share/nvim") cnoreabbrev _projects expand("$HOME/Projects") cnoreabbrev _ escape(expand('%:h'), ' \') noremap g[r Telescope lsp_references path_display={"shorten"} noremap g[d Telescope lsp_definitions path_display={"shorten"} noremap g[i Telescope lsp_implementations path_display={"shorten"} noremap g[td Telescope lsp_type_definitions path_display={"shorten"} noremap g[ci Telescope lsp_incoming_calls path_display={"shorten"} noremap g[co Telescope lsp_outgoing_calls path_display={"shorten"} noremap g[sd Telescope lsp_document_symbols path_display={"shorten"} noremap g[sw Telescope lsp_workspace_symbols path_display={"shorten"} noremap g[sdw Telescope lsp_dynamic_workspace_symbols path_display={"shorten"} set textwidth=80 set colorcolumn=+1 set title if has('rneovim') " call HighlightColorColumns() " " Grey color column right after text width is grey and in the background and " " a red one after the text width which is red and in the foreground. " set colorcolumn=+1/│/MyColorColumn/b,+20/│/MyRedColorColumn/f endif " Opens a terminal in the directory of the current file. command! TERM exec "term sh -c " . shellescape(printf("cd %s && exec ", shellescape(expand('%:p:h')))) . '$SHELL' " W = w. I often click when typing :w command! W w let g:loaded_netrw = 1 let g:loaded_netrwPlugin = 1 augroup UseTerminal au! au BufNewFile * lua open_terminal_on_directory() au BufEnter * lua open_terminal_on_directory() augroup END let g:jq_highlight_objects = 1 let g:jq_highlight_function_calls = 1 " Increment the character under the cursor to the next character in order. function! OrdNext() let char = matchstr(getline('.'), '\%' . col('.') . 'c.') let nr = char2nr(char) let new_char = nr2char(nr + 1) exec "norm r" . new_char endfunction " Decrement the character under the cursor to the last character in order. function! OrdPrev() let char = matchstr(getline('.'), '\%' . col('.') . 'c.') let nr = char2nr(char) let new_char = nr2char(nr - 1) exec "norm r" . new_char endfunction noremap α call OrdNext() " Capital alpha (α) noremap Α call OrdPrev() noremap € viba) noremap noremap <2-X2Mouse> noremap <3-X2Mouse> noremap noremap <2-X1Mouse> noremap <3-X1Mouse> noremap noremap Telescope tags menu 0.400 PopUp.Find\ References norm g[r menu 0.400 PopUp.Find\ Implementers norm g[i menu PopUp.Split :split menu PopUp.VSplit :vsplit menu PopUp.Close :q noremap gh HopCamelCase lua << EOF function open_terminal_on_directory() local buf = vim.api.nvim_get_current_buf() local bufname = vim.api.nvim_buf_get_name(buf) if vim.fn.isdirectory(bufname) ~= 1 then return end local tcmd = string.format("cd %s && exec $SHELL", vim.fn.shellescape(bufname)) local cmd = string.format("term sh -c %s", vim.fn.shellescape(tcmd)) vim.cmd(cmd) vim.cmd("startinsert") end require'nvim-treesitter.configs'.setup { textobjects = { select = { enable = true, -- Automatically jump forward to textobj, similar to targets.vim lookahead = true, keymaps = { -- You can use the capture groups defined in textobjects.scm ["am"] = "@function.outer", ["im"] = "@function.inner", ["af"] = "@function.outer", ["if"] = "@function.inner", ["aC"] = "@class.outer", ["aa"] = "@parameter.outer", ["ia"] = "@parameter.inner", ["iq"] = "@block.inner", ["aq"] = "@block.outer", ["aS"] = "@statement.outer", ["iS"] = "@statement.inner", -- You can optionally set descriptions to the mappings (used in the desc parameter of -- nvim_buf_set_keymap) which plugins like which-key display ["iC"] = { query = "@class.inner", desc = "Select inner part of a class region" }, }, -- You can choose the select mode (default is charwise 'v') -- -- Can also be a function which gets passed a table with the keys -- * query_string: eg '@function.inner' -- * method: eg 'v' or 'o' -- and should return the mode ('v', 'V', or '') or a table -- mapping query_strings to modes. selection_modes = { ['@parameter.outer'] = 'v', -- charwise ['@function.outer'] = 'V', -- linewise ['@function.inner'] = 'V', -- linewise ['@block.inner'] = 'V', -- linewise ['@block.outer'] = 'V', -- linewise }, -- If you set this to `true` (default is `false`) then any textobject is -- extended to include preceding or succeeding whitespace. Succeeding -- whitespace has priority in order to act similarly to eg the built-in -- `ap`. -- -- Can also be a function which gets passed a table with the keys -- * query_string: eg '@function.inner' -- * selection_mode: eg 'v' -- and should return true of false include_surrounding_whitespace = function (q) return string.match(q.query_string, '.inner$') == nil and string.match(q.query_string, '^function') end, }, move = { enable = true, set_jumps = true, goto_next_start = { ["]C"] = "@injectable_constructor.params.inner", ["]c"] = "@class.outer", }, goto_previous_start = { ["[C"] = "@injectable_constructor.params.inner", ["[c"] = "@class.outer", }, }, }, } require('nvim-treesitter.configs').setup({ highlight = { enable = true, -- Enables highlighting for all supported filetypes additional_vim_regex_highlighting = false, -- Disable regex-based highlighting for speed }, }) function remove_package(str) for k, v in pairs(package.loaded) do if string.match(k, "^" .. str) then package.loaded[k] = nil end end end function reload_package(str) remove_package(str) return require(str) end -- CiderLSP vim.opt.completeopt = { "menu", "menuone", "noselect" } require("lsp") require("lspconfig") require("tabby") -- Diagnostics require("diagnostics") require("nvim-tree").setup({ hijack_directories = {auto_open = false} }) require("lualinesetup") require('telescope').setup({ defaults = { title = "", borderchars = { " ", " ", " ", " ", " ", " ", " ", " " }, prompt_prefix = '🞂 ', selection_caret = '🞂 ', layout_strategy = "horizontal", results_title = false, sorting_strategy = "ascending", pickers = { find_files = { hidden = true } }, -- path_display = "shorten", layout_config = { horizontal = { width = 0.66, height = 0.66, }, -- other layout configuration here }, -- other defaults configuration here }, -- other configuration values here }) -- require("virt-column").setup({ -- char = '│', -- highlight = "ColorColumnLine" -- }) function run_format_code() local lsps = vim.lsp.buf_get_clients() if lsps then vim.lsp.buf.format() else vim.cmd("FormatCode") end end local gitsigns = require("gitsigns") gitsigns.setup({ on_attach = function(bufnr) vim.keymap.set({'o', 'x'}, 'ih', 'Gitsigns select_hunk') local function map(mode, l, r, opts) opts = opts or {} opts.buffer = bufnr vim.keymap.set(mode, l, r, opts) end -- Navigation map('n', ']h', function() if vim.wo.diff then vim.cmd.normal({']c', bang = true}) else gitsigns.nav_hunk('next') end end) map('n', '[h', function() if vim.wo.diff then vim.cmd.normal({'[c', bang = true}) else gitsigns.nav_hunk('prev') end end) -- Actions map('n', 'hs', gitsigns.stage_hunk) map('n', 'hr', gitsigns.reset_hunk) map('v', 'hs', function() gitsigns.stage_hunk({ vim.fn.line('.'), vim.fn.line('v') }) end) map('v', 'hr', function() gitsigns.reset_hunk({ vim.fn.line('.'), vim.fn.line('v') }) end) map('n', 'hS', gitsigns.stage_buffer) map('n', 'hR', gitsigns.reset_buffer) map('n', 'hp', gitsigns.preview_hunk) map('n', 'hi', gitsigns.preview_hunk_inline) end }) require("nvim-surround").setup({}) require('smear_cursor').enabled = true require('smear_cursor').cursor_color = '#ff0000' require('smear_cursor').legacy_computing_symbols_support = true require('smear_cursor').stiffness = 0.4 require('smear_cursor').distance_stop_animating = 5 require('hop').setup() EOF