Created
January 27, 2021 06:06
-
-
Save hwayne/2a6c85f1a69b73bfe5da7a756f440834 to your computer and use it in GitHub Desktop.
My vimrc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" vim: ft=vim:fdm=marker | |
" This must come first or else | |
" the local mappings for plugins | |
" won't use the mapleader? | |
let mapleader="\<Space>" | |
" Using powershell messes up Gutentags, temporarily disable | |
" TODO make a way to quickly enter powershell | |
" set shell=powershell shellquote=( shellpipe=\| | |
" "set shellcmdflag=-NoLogo\ -NoProfile\ -ExecutionPolicy\ RemoteSigned\ -Command | |
" set shellcmdflag=-NoLogo\ -NoProfile\ -ExecutionPolicy\ RemoteSigned\ -NoExit\ -Command | |
" set shellredir=\|\ Out-File\ -Encoding\ UTF8 | |
" PLUGINS {{{ | |
call plug#begin('~/AppData/Local/nvim/plugged') | |
" Surround motions | |
Plug 'tpope/vim-surround' | |
" Terminal integration | |
Plug 'kassio/neoterm' | |
let g:neoterm_eof="\r" | |
"let g:neoterm_shell=&shell . ' ' . substitute(&shellcmdflag, '[-]Command', '-NoExit\ -Command\ ', '') | |
"let g:neoterm_shell=&shell . ' ' . &shellcmdflag | |
let g:neoterm_default_mod = 'vert' | |
command! TT :T powershell | |
nmap gx <Plug>(neoterm-repl-send) | |
xmap gx <Plug>(neoterm-repl-send) | |
nmap gxx <Plug>(neoterm-repl-send-line) | |
Plug 'tpope/vim-unimpaired' | |
" Repeat stuff | |
Plug 'tpope/vim-repeat' | |
" Run things at root of projects | |
Plug 'dbakker/vim-projectroot' | |
let g:rootmarkers = ['.projectroot', '.git', '.vscode'] | |
" NERDTREE!!11 | |
Plug 'preservim/nerdtree' | |
nnoremap <silent> <leader>n :ProjectRootExe NERDTreeToggle<cr> | |
nnoremap <silent> <leader>f :ProjectRootExe NERDTreeFind<cr> | |
" FZF??h | |
"Plug 'junegunn/fzf.vim' | |
Plug 'C:/Users/hwayn/.fzf' | |
command! F :ProjectRootExe FZF | |
" Add swap function g> g< gs | |
Plug 'machakann/vim-swap' | |
" Signature line in code | |
Plug 'kshenoy/vim-signature' | |
Plug 'ludovicchabant/vim-gutentags' | |
let g:gutentags_define_advanced_commands = 1 | |
let g:gutentags_ctags_exclude = ["_build", "public", "mypy", ".mypy_cache", "__pycache__", "themes", "assets", "_static"] | |
let g:gutentags_project_root = ["conf.py"] | |
" Undotree | |
Plug 'mbbill/undotree' | |
nnoremap <leader>u :UndotreeToggle<CR> | |
let g:undotree_SetFocusWhenToggle = 1 | |
let g:undotree_ShortIndicators = 1 | |
let g:undotree_DiffAutoOpen = 0 | |
" TLA+ | |
Plug 'D:/Software/GitHub/tla.vim' | |
" For dealing with dragon being bad | |
Plug 'AndrewRadev/switch.vim' | |
let g:switch_mapping = "-" | |
let g:switch_custom_definitions = | |
\ [ | |
\ {'\<two\>': 'too', | |
\ '\<too\>': 'to', | |
\ '\<to\>': 'two'}, | |
\ {'\<are\>': "aren't", | |
\ "\<aren't\>": 'are'}, | |
\ ['except', 'accept'], | |
\ ['right', 'write'], | |
\ ['then', 'than'], | |
\ ['is', 'has'], | |
\ ['its', "it's"], | |
\ ['were', "we're", "where"], | |
\ ['there', "they're", "their"], | |
\ ['trad', "triad"], | |
\ ] | |
" More dragon stuff | |
" See https://github.com/kana/vim-textobj-user/wiki | |
Plug 'kana/vim-textobj-user' | |
Plug 'fvictorio/vim-textobj-backticks' | |
"outlines for rst and markdown | |
Plug 'vim-voom/VOoM' | |
let g:voom_ft_modes = {'markdown': 'markdown', 'rst': 'rest'} | |
" TODO use VoomToggle instead of Voom | |
"LaTeX functionality | |
" Plug 'lervag/vimtex' | |
"Z3! | |
" Plug 'bohlender/vim-smt2' | |
", {'branch': 'release'} | |
"nnoremap <leader>a <Cmd>CocCommand<CR> | |
call plug#end() | |
" }}} | |
" SETTINGS {{{ | |
set termguicolors | |
set guifont=consolas:h16 | |
set tabline=%{strftime('%c')} | |
set hidden | |
set splitright | |
set number | |
set relativenumber | |
set cursorline | |
set ignorecase | |
set smartcase | |
set shiftwidth=2 | |
set tabstop=2 | |
set softtabstop=2 | |
set expandtab | |
set undofile | |
set completeopt-=preview | |
set lazyredraw | |
set noswapfile | |
set clipboard=unnamedplus | |
set inccommand=nosplit | |
set autochdir | |
set foldcolumn=3 | |
set foldlevelstart=2 | |
set foldmethod=syntax | |
set fillchars=fold:\ | |
set wildmode=list:full | |
"set rtp+="C:\Users\hwayn\.fzf" | |
" }}} | |
" MAPPINGS {{{ | |
inoremap jk <esc> | |
inoremap JK <esc> | |
noremap \\ :wa<return> | |
nnoremap \w :b#<cr> | |
" navigation | |
noremap ^ H | |
noremap $ L | |
noremap H ^ | |
noremap L $ | |
noremap <expr> k (v:count == 0 ? 'gk' : 'k') | |
noremap <expr> j (v:count == 0 ? 'gj' : 'j') | |
nnoremap <c-j> <c-w>j | |
nnoremap <c-k> <c-w>k | |
nnoremap <c-h> <c-w>h | |
nnoremap <c-l> <c-w>l | |
tnoremap <c-j> <c-\><c-n><c-w>j | |
tnoremap <c-k> <c-\><c-n><c-w>k | |
tnoremap <c-h> <c-\><c-n><c-w>h | |
tnoremap <c-l> <c-\><c-n><c-w>l | |
nnoremap gp `[v`] | |
inoremap ;r <c-R>+ | |
inoremap ;d <c-R>=strftime('%D') | |
inoremap <c-BS> <c-W> | |
" Find/replace under cursor | |
nnoremap <Leader>rw :%s/\<<C-r><C-w>\>/ | |
nnoremap Y y$ | |
nnoremap s "_d | |
nnoremap ss "_dd | |
"nnoremap S "_D | |
map <F1> <nop> | |
imap <F1> <nop> | |
command! Vimrc :vs $MYVIMRC | |
command! Source :source $MYVIMRC | |
noremap Q @@ | |
nnoremap ZA :wqa!<cr> | |
nnoremap ZC :qa!<cr> | |
vnoremap 0 "0 | |
nnoremap S 1z= | |
noremap <leader>s zg | |
" }}} | |
" exobrain stuff {{{ | |
nnoremap <silent> <leader>e :exe getline(line('.'))<cr> | |
" expand can't expand variables, use fnamemodify instead | |
" output looks weird because mixes windows + unix paths | |
" But it works fine in scripts | |
let g:exo=fnamemodify($MYVIMRC, ":h") . "/exo/" | |
" Currently just finds the scratch for the current file. | |
" TODO make less janky | |
function! s:Scratch() | |
" close if we're already in a scratch file | |
" a =~ b checks if b regex-matches a | |
" we have to expand exo to expand the ~ | |
if expand("%:p") =~ expand(g:exo) | |
execute "b#" | |
else | |
" format: rootname.extension | |
let s:scratchfile = expand("%:r") . "." . expand("%:e") | |
execute "e " . g:exo . "scratch/" . s:scratchfile | |
endif | |
endfunction | |
"create a delscratch function | |
command! Scratch :call s:Scratch() | |
"nnoremap <leader>s :Scratch<cr> | |
" Macro Handling {{{ | |
let s:macro_file = g:exo . 'macros.json' | |
function! s:macro_list(ArgLead, CmdLine, CursorPos) | |
let macros = json_decode(readfile(s:macro_file)) | |
return join(keys(macros), "\n") | |
endfunction | |
function! s:GetMacro(macro_name) | |
let macros = json_decode(readfile(s:macro_file)) | |
echom macros[a:macro_name] | |
endfunction | |
command! -nargs=1 -complete=custom,s:macro_list GetMacro call s:GetMacro(<f-args>) | |
function! s:SetMacro(macro_name, reg) | |
let macros = json_decode(readfile(s:macro_file)) | |
call setreg(a:reg, macros[a:macro_name]) | |
endfunction | |
command! -nargs=+ -complete=custom,s:macro_list SetMacro call s:SetMacro(<f-args>) | |
function! s:SaveMacro(macro_name, reg) | |
let macros = json_decode(readfile(s:macro_file)) | |
let macros[a:macro_name] = getreg(a:reg) | |
" Avoid clobbering the file if invalid | |
let s = json_encode(macros) | |
if s !=? "" | |
call writefile([s], s:macro_file) | |
endif | |
endfunction | |
command! -nargs=+ SaveMacro call s:SaveMacro(<f-args>) | |
" writefile() | |
" json_encode() | |
" json_decode() | |
" }}} | |
" Post Inserter {{{ | |
let s:post_file = 'D:\website\data\posts.json' | |
function! s:post_list(ArgLead, CmdLine, CursorPos) | |
let bookmarks = json_decode(readfile(s:post_file)) | |
return join(keys(bookmarks), "\n") | |
endfunction | |
function! s:GetPost(...) | |
let posts = json_decode(readfile(s:post_file)) | |
if a:0 == 1 | |
let @+ = posts[a:1] | |
else | |
for key in keys(posts) | |
echo key . ": ". posts[key] | |
endfor | |
endif | |
endfunction | |
command! -nargs=? -complete=custom,s:post_list P call s:GetPost(<f-args>) | |
" Ref inserter | |
function! s:ShortCode(name) | |
let @m = '{{% '.a:name.' %}}' | |
norm "mp | |
endfunction | |
let s:ref_file = 'D:\website\data\person.json' | |
function! s:ref_list(ArgLead, CmdLine, CursorPos) | |
let bookmarks = json_decode(readfile(s:ref_file)) | |
return join(keys(bookmarks), "\n") | |
endfunction | |
function! s:PutRef(...) | |
let refs = json_decode(readfile(s:ref_file)) | |
if a:0 == 1 | |
let @m = '{{% person '.refs[a:1].' %}}' | |
norm "mp | |
else | |
for key in keys(refs) | |
echo key . ": ". refs[key] | |
endfor | |
endif | |
endfunction | |
command! -nargs=? -complete=custom,s:ref_list Ref call s:PutRef(<f-args>) | |
" }}} | |
" Bookmarks {{{ | |
let s:bookmark_file = g:exo . 'bookmarks.json' | |
function! s:bookmark_list(ArgLead, CmdLine, CursorPos) | |
let bookmarks = json_decode(readfile(s:bookmark_file)) | |
return join(keys(bookmarks), "\n") | |
endfunction | |
function! s:GetBookmark(...) | |
let bookmarks = json_decode(readfile(s:bookmark_file)) | |
if a:0 == 1 | |
echom bookmarks[a:1] | |
else | |
for key in keys(bookmarks) | |
echo key . ": ". bookmarks[key] | |
endfor | |
endif | |
endfunction | |
command! -nargs=? -complete=custom,s:bookmark_list Bookmarks call s:GetBookmark(<f-args>) | |
function! s:GotoBookmark(bookmark_name) | |
let bookmarks = json_decode(readfile(s:bookmark_file)) | |
execute "e " . bookmarks[a:bookmark_name] | |
endfunction | |
command! -nargs=1 -complete=custom,s:bookmark_list To call s:GotoBookmark(<f-args>) | |
function! s:SaveBookmark(bookmark_name) | |
set shellslash "to make windows play nice | |
let bookmarks = json_decode(readfile(s:bookmark_file)) | |
let bookmarks[a:bookmark_name] = expand('%:p') | |
" Avoid clobbering the file if invalid | |
let s = json_encode(bookmarks) | |
if s !=? "" | |
call writefile([s], s:bookmark_file) | |
endif | |
" | |
set noshellslash | |
endfunction | |
command! -nargs=1 -complete=custom,s:bookmark_list SaveBookmark call s:SaveBookmark(<f-args>) | |
command! JSONify :%!python -m json.tool | |
" }}} | |
" }}} | |
" AUGROUPS {{{ | |
setglobal statusline=%<(%n)\ %t\ %m | |
augroup every | |
autocmd! | |
au InsertEnter * set norelativenumber | |
au InsertEnter * set shellslash | |
au InsertLeave * set relativenumber | |
au InsertLeave * set noshellslash | |
" cmd buffer | |
au CmdLineEnter * set norelativenumber | redraw | |
au CmdlineLeave * set relativenumber | |
augroup END | |
" We need to do it as a normal mode injection | |
" Because %! uses the active buffer, not the local one | |
" IDEA: what about using let &statusline? | |
function! SetStatus(statusline) | |
exe "setlocal statusline=" . a:statusline | |
endfunction | |
" visual_words_or_all | |
" Have to make global because statuslines are weird | |
" Can't use <SID> for some reason??? | |
function! g:Exo_vwal() | |
let s:worddict = wordcount() | |
if has_key(s:worddict, "visual_words") | |
return s:worddict["visual_words"] | |
else | |
return s:worddict["words"] | |
endif | |
endfunction | |
" MARKDOWN {{{ | |
let g:markdown_folding = 1 | |
augroup md | |
autocmd! | |
"TODO make statusline blue | |
function! s:BufRead() | |
let s:sl = '%<%n)\ %t\ %m' . | |
\ '%=%1*%{g:Exo_vwal()}%*' | |
call SetStatus(s:sl) | |
syntax keyword todo TK | |
noremap <buffer> gO :VoomToggle markdown<cr> | |
if expand('%') =~? '\.talk' | |
setlocal statusline+=/%{g:Exo_vwal()/130} | |
endif | |
setlocal linebreak | |
setlocal suffixesadd=.md | |
endfunction | |
au BufNewFile,BufRead *.md call s:BufRead() | |
augroup END | |
" }}} | |
augroup mbox | |
autocmd! | |
au BufNewFile,BufRead *.mbox setlocal inccommand= | |
augroup END | |
augroup exobrain | |
autocmd! | |
augroup END | |
"g:rst_syntax_code_list | |
g:rst_fold_enabled = 1 | |
augroup rst | |
autocmd! | |
function! s:rstBufRead() | |
let s:sl = '%<%n)\ %t\ %m' . | |
\ '%=%1*%{g:Exo_vwal()}%*' | |
call SetStatus(s:sl) | |
syntax keyword todo TK | |
noremap <buffer> gO :VoomToggle rest<cr> | |
hi clear rstExDirective | |
setlocal indentexpr="" | |
" ^^ removes the annoying autoindent | |
setlocal linebreak | |
iabbrev MM :math: | |
iabbrev RA \Rightarrow | |
endfunction | |
au BufNewFile,BufRead,BufEnter *.rst call s:rstBufRead() | |
" vv Why is this not in the bufread function? | |
au BufNewFile,BufRead *.rst setlocal suffixesadd=.rst | |
augroup END | |
augroup tweetstorm | |
autocmd! | |
au BufNewFile,BufRead tweetstorm setlocal cc=280 | |
augroup END | |
" }}} | |
" Did not take??? | |
nnoremap ]t :tabn<cr> | |
nnoremap [t :tabp<cr> | |
" | |
" TODO add a to create a markdown line | |
" REMAP U to not move where you are! | |
" HIGHLIGHTING {{{ | |
colorscheme default | |
hi SignatureMarkText guibg=NONE ctermbg=NONE | |
hi SignColumn guibg=NONE ctermbg=NONE | |
hi User1 guifg=Gray guibg=NONE ctermbg=NONE | |
hi Folded guibg=NONE guifg=Gold | |
hi FoldColumn guibg=NONE guifg=Gold ctermbg=NONE | |
hi Pmenu guibg=DarkGrey guifg=Black | |
hi PmenuSel guibg=Violet guifg=Black | |
hi Conceal guibg=NONE | |
set pumblend=15 | |
" }}} | |
"Windows terminal maps <c-h> to BS before vim sees it | |
"So map it back | |
" Has to be AFTER <c-h> hnoremap | |
if $TERM == "vtpcon" | |
nmap <BS> <c-h> | |
endif | |
" Functions {{{ | |
function! GetSynStack() | |
" todo make this a lambda | |
echo map(synstack(line("."), col(".")), 'synIDattr(v:val, "name")') | |
endfunction | |
com! GetSyn call GetSynStack() | |
function! CodeSnippet(...) | |
let out = '```' | |
if a:0 == 1 | |
let out = out . a:1 | |
endif | |
" vvv makes it easier to %s OPENING set of code fences | |
put = ' '.out | |
" vvv outputs clipboard | |
put + | |
put ='```' | |
endfunction | |
command! -nargs=? C call CodeSnippet("<args>") | |
" }}} | |
" nicer highlighted indentation | |
vnoremap < <gv | |
vnoremap > >gv | |
" let url="url: \"/" . expand("%:r") . "/\"" | put = url | |
" | |
" Conceal {{{ | |
syntax match Normal '\v<[[:alpha:]_]+0>'ms=e conceal cchar=₀ | |
syntax match Test /\\A/ conceal cchar=∀ | |
function! ToggleConcealLevel() | |
if &conceallevel == 0 | |
setlocal conceallevel=2 | |
else | |
setlocal conceallevel=0 | |
endif | |
endfunction | |
nnoremap <silent> U :call ToggleConcealLevel()<CR> | |
" }}} | |
" | |
" TODO move this somewhere in context | |
nnoremap R i_<Esc>r | |
function! ReplaceFile() | |
normal! ggVGP | |
endfunction | |
" {{{ Markdown helpers | |
vmap ` S` | |
vmap m S]%a()jk | |
nmap <leader>` ysiw` | |
nmap <leader>~ ysiW` | |
function! s:MdFootnote(note) | |
let s:footnote = "[^".a:note."]" | |
let @m = s:footnote | |
norm "mpmm | |
$put = s:footnote.':' | |
norm `m | |
endfunction | |
command! -nargs=1 Footnote call s:MdFootnote("<args>") | |
function! s:ShortCode(name) | |
let @m = '{{% '.a:name.' %}}' | |
norm "mp | |
endfunction | |
function! s:ShortCodeBlock(name) | |
let s:sc = split(a:name)[0] | |
put ='{{% '.a:name.' %}}' | |
put ='{{% /'.s:sc.' %}}' | |
endfunction | |
command! -nargs=1 Hs call s:ShortCode("<args>") | |
command! -nargs=1 Hb call s:ShortCodeBlock("<args>") | |
" }}} | |
" TODO for rst make _ move to index or up a folder if already on the index | |
" TODO something horrible with mousebuttons |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment