Skip to content

Instantly share code, notes, and snippets.

@beaugunderson
Created May 21, 2023 15:39
Show Gist options
  • Save beaugunderson/7acffd22a8df616cba263655aaa6b6fe to your computer and use it in GitHub Desktop.
Save beaugunderson/7acffd22a8df616cba263655aaa6b6fe to your computer and use it in GitHub Desktop.
scriptencoding utf8
set t_Co=256
" disable some things for speed
let g:loaded_vimballPlugin = 1
let g:loaded_rrhelper = 1
let g:did_install_default_menus = 1
" https://github.com/neovim/neovim/issues/9912
" TODO: "It's now ~/.local/state/nvim"
if has('nvim')
let &viminfofile = expand('~/.local/share/nvim/shada/main.shada')
endif
if has('nvim')
set exrc
set diffopt+=hiddenoff
set diffopt+=internal,algorithm:patience
set diffopt+=iwhiteall
set diffopt+=linematch:50
endif
call plug#begin('~/.vim/plugged')
" For installing LSP servers, linters, etc.
Plug 'williamboman/mason.nvim'
Plug 'williamboman/mason-lspconfig.nvim'
Plug 'mfussenegger/nvim-dap' " Debug adapter support
" LSP configs + nvim-cmp for completions
Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-cmdline'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/vim-vsnip'
Plug 'vimwiki/vimwiki'
Plug 'nvim-lualine/lualine.nvim'
" Show lint/LSP issues in a box
Plug 'nvim-tree/nvim-web-devicons'
if has('nvim')
Plug 'folke/trouble.nvim'
Plug 'mhartington/formatter.nvim' " for format on save
" TODO investigate null-ls?
" :help vim.lsp.buf.format()
Plug 'lewis6991/gitsigns.nvim'
else
Plug 'airblade/vim-gitgutter'
endif
" Treesitter
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
" Plug 'nvim-treesitter/playground'
" Leekscript
" Plug 'PTank/leek.vim', {'for': 'leek'}
" JavaScript/HTML plugins
Plug 'elzr/vim-json', {'for': 'json'}
" Plug 'gavocanov/vim-js-indent', {'for': 'javascript'}
Plug 'GutenYe/json5.vim', {'for': 'json'}
Plug 'moll/vim-node' " support 'gf' on require/import lines
" Plug 'othree/html5.vim', {'for': 'html'}
" JSX plugins
" Plug 'pangloss/vim-javascript', {'for': ['javascript', 'javascript.jsx', 'jsx']}
" Plug 'mxw/vim-jsx', {'for': ['javascript.jsx', 'jsx']}
Plug 'windwp/nvim-ts-autotag'
" Python plugins
" Plug 'vim-python/python-syntax', {'for': 'python'}
" Other filetypes
Plug 'cakebaker/scss-syntax.vim'
Plug 'chrisbra/csv.vim', {'for': 'csv'}
Plug 'ekalinin/Dockerfile.vim'
Plug 'fatih/vim-go', {'for': 'go'}
Plug 'gabrielelana/vim-markdown'
Plug 'leafgarland/typescript-vim', {'for': 'typescript'}
Plug 'lepture/vim-jinja'
Plug 'syngan/vim-vimlint', {'for': 'vim'}
Plug 'TovarishFin/vim-solidity', {'for': 'solidity'}
Plug 'ynkdir/vim-vimlparser', {'for': 'vim'}
" Other plugins
Plug 'Konfekt/FastFold'
Plug 'norcalli/nvim-colorizer.lua' " colorize hex strings in files
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'junegunn/goyo.vim' " distraction-free writing
Plug 'junegunn/gv.vim' " GV command for browsing git revisions
Plug 'junegunn/limelight.vim' " hyper-distraction-free writing
Plug 'junegunn/vim-emoji'
Plug 'junegunn/vim-slash' " improve search
Plug 'kopischke/vim-fetch' " support `vim file.js:50`
Plug 'misterbuckley/vim-definitive' " go to definition
Plug 'ryanoasis/vim-devicons'
Plug 'todesking/vint-syntastic', {'for': 'vim'}
Plug 'tpope/vim-characterize'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-eunuch'
Plug 'tpope/vim-fugitive' " git support, e.g. GBlame
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-rhubarb' " extends vim-fugitive for github
Plug 'tpope/vim-surround'
Plug 'tpope/vim-unimpaired'
Plug 'tpope/vim-vinegar' " better file navigator
Plug 'tweekmonster/fzf-filemru'
Plug 'tweekmonster/startuptime.vim'
Plug 'wakatime/vim-wakatime' " log editing activity to wakatime.com
Plug 'wincent/terminus' " iTerm niceties (focus, mouse)
Plug 'zirrostig/vim-schlepp'
call plug#end()
if has('nvim')
augroup FormatAutogroup
autocmd!
autocmd BufWritePost * FormatWrite
augroup END
endif
if has('nvim')
set emoji
set inccommand=split
set termguicolors
endif
if has('nvim')
lua <<EOF
-- TODO remove some of the unused sections
require('lualine').setup()
-- TODO this has additional options for CSS functions, rgb(), etc. if needed
require('colorizer').setup()
require('mason').setup()
require('mason-lspconfig').setup()
require('gitsigns').setup()
function on_attach()
vim.api.nvim_create_autocmd("CursorHold", {
buffer = bufnr,
callback = function()
local opts = {
focusable = false,
close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" },
border = 'rounded',
source = 'always',
prefix = ' ',
scope = 'cursor',
}
vim.diagnostic.open_float(nil, opts)
end
})
end
-- Add additional capabilities supported by nvim-cmp
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
require("mason-lspconfig").setup_handlers {
-- The first entry (without a key) will be the default handler
-- and will be called for each installed server that doesn't have
-- a dedicated handler.
function (server_name) -- default handler (optional)
require("lspconfig")[server_name].setup {
capabilities = capabilities,
on_attach = on_attach,
root_dir = require"lspconfig/util".find_git_ancestor,
}
end,
["eslint"] = function ()
require("lspconfig")["eslint"].setup {
capabilities = capabilities,
on_attach = on_attach,
root_dir = require"lspconfig/util".find_json_ancestor,
}
end,
["pylsp"] = function ()
require("lspconfig")["pylsp"].setup {
capabilities = capabilities,
on_attach = on_attach,
root_dir = require"lspconfig/util".find_json_ancestor,
settings = {
pylsp = {
configurationSources = {"flake8"},
plugins = {
pycodestyle = { maxLineLength = 99 },
}
}
}
}
end
}
-- nvim-cmp setup
local cmp = require 'cmp'
cmp.setup {
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
mapping = cmp.mapping.preset.insert({
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
else
fallback()
end
end, { 'i', 's' }),
}),
sources = {
{ name = 'nvim_lsp' },
},
}
-- vim.keymap.set('n', ',e', vim.diagnostic.open_float)
-- vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
-- vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
-- vim.keymap.set('n', ',q', vim.diagnostic.setloclist)
-- Use LspAttach autocommand to only map the following keys
-- after the language server attaches to the current buffer
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
callback = function(ev)
-- Enable completion triggered by <c-x><c-o>
-- vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
-- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { buffer = ev.buf }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
-- vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
-- vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
-- vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
-- vim.keymap.set('n', '<space>wl', function()
-- print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
-- end, opts)
vim.keymap.set('n', ',D', vim.lsp.buf.type_definition, opts)
vim.keymap.set('n', ',rn', vim.lsp.buf.rename, opts)
vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, opts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
vim.keymap.set('n', ',f', function()
vim.lsp.buf.format { async = true }
end, opts)
end,
})
EOF
endif
if has('nvim')
lua <<EOF
-- Provides the Format, FormatWrite, FormatLock, and FormatWriteLock commands
require("formatter").setup {
logging = true,
log_level = vim.log.levels.ERROR,
filetype = {
javascript = { require("formatter.filetypes.javascript").eslint_d },
typescript = { require("formatter.filetypes.typescript").eslint_d },
["javascript.jsx"] = { require("formatter.filetypes.javascript").eslint_d },
["typescript.jsx"] = { require("formatter.filetypes.typescript").eslint_d },
["typescriptreact"] = { require("formatter.filetypes.typescript").eslint_d },
sql = { require("formatter.filetypes.sql").pgformat },
["python"] = {
function()
return {
exe = "black",
args = { "-q", "-l", "100", "-" },
stdin = true,
}
end,
},
["*"] = {
function()
return { exe = 'sed', args = { '-i', "''", "'s/[ ]*$//'" } }
end
}
}
}
EOF
endif
" search when using gf
set suffixesadd=.md,.js,.jsx,.ts,.tsx
if has('nvim')
lua <<EOF
require'nvim-treesitter.configs'.setup {
highlight = {
enable = true,
},
indent = {
enable = true,
},
autotag = {
enable = true,
},
-- playground = {
-- enable = true,
-- disable = {},
-- updatetime = 25, -- Debounced time for highlighting nodes in the playground from source code
-- persist_queries = false, -- Whether the query persists across vim sessions
-- keybindings = {
-- toggle_query_editor = 'o',
-- toggle_hl_groups = 'i',
-- toggle_injected_languages = 't',
-- toggle_anonymous_nodes = 'a',
-- toggle_language_display = 'I',
-- focus_language = 'f',
-- unfocus_language = 'F',
-- update = 'R',
-- goto_node = '<cr>',
-- show_help = '?',
-- },
-- }
}
-- vim.builtin.treesitter.autotag.enable = true
-- require('nvim-ts-autotag').setup()
EOF
endif
let main_wiki = {}
let main_wiki.path = '~/Dropbox/Notes/'
let g:vimwiki_list = [main_wiki]
let g:markdown_enable_conceal = 1
let g:markdown_enable_insert_mode_mappings = 1
let g:markdown_enable_mappings = 1
let g:markdown_enable_spell_checking = 0
set updatetime=300
vmap <unique> <s-left> <plug>SchleppLeft
vmap <unique> <s-right> <plug>SchleppRight
vmap <unique> <s-up> <plug>SchleppUp
vmap <unique> <s-down> <plug>SchleppDown
vmap <unique> D <plug>SchleppDup
let g:Schlepp#dupTrimWS = 1
" let g:airline_powerline_fonts = 1
" let g:airline_theme = 'succulent'
let g:used_javascript_libs = 'jquery,underscore'
let g:javascript_plugin_flow = 1
set background=dark
colorscheme evening-dark
set spellfile=~/.vim/spell/words.utf8.add
" Don't check for sentence capitalization
set spellcapcheck=
set spelllang=en_us
" Don't enable folding by default, zc will enable though
set nofoldenable
set textwidth=79
" Wrapping
set wrap
set list
set listchars=tab:→\ ,trail:·,nbsp:␣
" Break at a sensible place instead of at any character
set linebreak
let &g:showbreak = '↪ '
if exists('&breakindent')
set breakindent
set breakindentopt=shift:-2
endif
" Map leader to comma
let g:mapleader = ','
" Move through display lines, not numbered lines
nnoremap k gk
nnoremap j gj
nnoremap <Up> gk
nnoremap <Down> gj
" TODO: add 'a' and remove 'c' for markdown and plain text files
set formatoptions=croqnl " add nl
" Add sudow for writing to read-only files
cnoremap sudow w !sudo tee % >/dev/null
" Soon
"noremap <Up> <nop>
"noremap <Down> <nop>
"noremap <Left> <nop>
"noremap <Right> <nop>
augroup vimrc
autocmd!
augroup END
" Disables paste mode when leaving insert mode
autocmd vimrc InsertLeave *
\ if &paste == 1 |
\ set nopaste |
\ endif
" Edit in place for crontab on OS X
autocmd vimrc FileType crontab setlocal nowritebackup
" When editing a file, always jump to the last cursor position
autocmd vimrc BufReadPost *
\ if line("'\"") > 0 && line ("'\"") <= line('$') |
\ exe "normal g'\"" |
\ endif
" Add support for comment toggling in git commits
autocmd vimrc FileType gitcommit set commentstring=#\ %s
" Fix slow exit from insert mode
if !has('gui_running')
set ttimeoutlen=10
augroup FastEscape
autocmd!
autocmd InsertEnter * set timeoutlen=0
autocmd InsertLeave * set timeoutlen=1000
augroup END
endif
autocmd vimrc BufNewFile,BufReadPost *requirements.txt setlocal filetype=conf
autocmd vimrc BufNewFile,BufReadPost *requirements.in setlocal filetype=conf
autocmd vimrc BufNewFile,BufReadPost .eslintrc setlocal filetype=json
autocmd vimrc BufNewFile,BufReadPost *.osascript setlocal filetype=applescript
autocmd vimrc BufNewFile,BufReadPost *.ts setlocal filetype=typescript
autocmd vimrc BufNewFile,BufReadPost *.ls setlocal filetype=leek
autocmd vimrc BufNewFile,BufReadPost *.leek setlocal filetype=leek
autocmd vimrc User GoyoEnter Limelight
autocmd vimrc User GoyoLeave Limelight!
let g:goyo_height = 100
set fillchars=vert:\ " So we don't get a trailing space error
let g:localvimrc_event = ['BufReadPre']
" Make decisions persistent
let g:localvimrc_persistent = 1
if has('persistent_undo')
set undofile
if has('nvim')
set undodir=~/.vim/.undo//
else
set undodir=~/.vim/.undo-old//
endif
endif
set backupdir=~/.vim/.backup//
set directory=~/.vim/.swap//
set backupcopy=yes
set ignorecase
set smartcase
set magic
set modelines=0
" Hide the default mode text
set noshowmode
set showtabline=2
" specified by nvim-cmp
set completeopt=menu,menuone,noselect
set browsedir=buffer
set wildignore=*.o,*.obj,*.bak,*.exe,*.jpg,*.gif,*.png,*.pyc,.git,.svn
" I don't really use the title and it contributes to iTerm2 slowness
set notitle
if exists('&colorcolumn')
set colorcolumn=+1
endif
set tabstop=2
set shiftwidth=2
set backspace=eol,start,indent
set complete=.,w,b,u,U,t,i,d
set number
set hlsearch
set showmatch
" <leader>space toggles search highlights
noremap <leader><space> :set hlsearch! hlsearch?<CR>
" <leader>r redraws the screen
noremap <leader>r :redraw!<CR>
" <leader>n goes to the next error
nmap <leader>n :lnext<CR>
" <leader>d goes to the definition
nnoremap <leader>d :FindDefinition<CR>
map <leader>l :exec &conceallevel ? "set conceallevel=0" : "set conceallevel=1"<CR>
" Toggle comments with the space key
nmap <space> gcc
vmap <space> gc
" Keep search results centered in the screen
nnoremap <silent> n nzz
nnoremap <silent> N Nzz
nnoremap <silent> * *zz
nnoremap <silent> # #zz
nnoremap <silent> g* g*zz
nnoremap <silent> g# g#zz
" Reselect visual block after indent/outdent
vnoremap < <gv
vnoremap > >gv
" Perl regexes
nnoremap / /\v
vnoremap / /\v
" Commonly-typed command alternatives
command! -bang W :w
command! -bang Wq :wq
command! -bang WQ :wq
command! -bang WQa :wqa
command! -bang Wqa :wqa
command! -bang Q :q<bang>
command! -bang QA :qa<bang>
command! -bang Qa :qa<bang>
" <Leader>j join without gap
nnoremap <expr> <Leader>j ':<C-U><BS>'
\. repeat('Ji <Esc>"_diw', v:count<=2 ? 1 : v:count-1)
" [count]<Leader>j and {Visual}<Leader>j
xnoremap <script> <Leader>j <Esc><SID>(NoGapJoin)
nnoremap <expr> <SID>(NoGapJoin) (line(".")>line("'<") ? "'<" : "")
\. repeat('Ji <Esc>"_diw', max([line("'>")-line("'<"), 1]))
" Ctrl-c copies to clipboard
map <C-c> "+y
let g:fzf_colors =
\ { 'fg': ['fg', 'Normal'],
\ 'bg': ['bg', 'Normal'],
\ 'hl': ['fg', 'Comment'],
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'border': ['fg', 'Ignore'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] }
" Ctrl-p opens fzf
nnoremap <C-p> :Files<CR>
map <C-g> :GFiles<CR>
let g:rg_command = '
\ rg --column --line-number --no-heading --fixed-strings --ignore-case --no-ignore --hidden --follow --color "always"
\ -g "*.{js,json,php,md,styl,jade,html,config,py,cpp,c,go,hs,rb,conf}"
\ -g "!{.git,node_modules,vendor}/*" '
command! -bang -nargs=* F call fzf#vim#grep(g:rg_command .shellescape(<q-args>), 1, <bang>0)
" cq instaed of ci'
onoremap q i'
onoremap Q i"
" Make Y behave like C and D
nnoremap Y y$
" let semicolon do colon commands
nnoremap ; :
call matchadd('Todo', '\vTODO(_\w+)*', 0)
call matchadd('Todo', '\vHACK(_\w+)*', 0)
highlight OverLength cterm=none ctermfg=1
call matchadd('OverLength', '\%>80v.\+', 0)
function HideHtml()
syntax match Entity "&lt;" conceal cchar=<
syntax match Entity "&gt;" conceal cchar=>
syntax match Entity "&amp;" conceal cchar=&
" XXX Entity
syntax match Entity /\v[<][a-zA-Z 0-9"\/=:{}-]+[>]/ conceal
set conceallevel=2
endfunction
set cinoptions=(0,W1s,m1
command! FZFMru call fzf#run({
\ 'source': v:oldfiles,
\ 'sink': 'e',
\ 'options': '-m -x +s',
\ 'down': '40%'})
" center result after searching
noremap <plug>(slash-after) zz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment