Skip to content

Instantly share code, notes, and snippets.

@NatWeiss
Last active August 12, 2022 22:39
Show Gist options
  • Save NatWeiss/57faf937f521d24b69f1267b90e21d15 to your computer and use it in GitHub Desktop.
Save NatWeiss/57faf937f521d24b69f1267b90e21d15 to your computer and use it in GitHub Desktop.
syntax enable
colorscheme xcode-dark
" attempt to fix issue
" :95;0c is already typed on starting vim (not nvim)
set t_u7=
set t_SH=
" no need to press shift to enter command mode
noremap ; :
noremap : ;
" paste before the current line by default
noremap p P
noremap P p
" insert new line before current line by default
noremap o O
noremap O o
" go to first char of current line by default
noremap _ -
noremap - _
" redo is just U
nnoremap U <C-r>
"iunmap U
" an extra way to hit the escape key for iterm2 keyboard shortcuts where \e doesnt work
"nnoremap <C-e> <esc>
inoremap <C-e> <esc>
vnoremap <C-e> <esc>
" word movement near the same as letter movement
noremap H B
noremap L W
"noremap H ^
"noremap L g_
noremap J 10j
noremap K 10k
"noremap w <nop>
"noremap W <nop>
noremap e <nop>
noremap E <nop>
" ignore a few things that are easy to accidentally strike
nnoremap wi <nop>
nnoremap wr <nop>
nnoremap q <nop>
nnoremap * <nop>
noremap . <nop>
noremap gx <nop>
" more convenient jump to function start / end
nnoremap { [[
nnoremap } ]]
vnoremap { [[
vnoremap } ]]
"nunmap <C-w>o
"nunmap [[
"nunmap ]]
"nunmap [#
"nunmap ]#
"nunmap ['
"nunmap ]'
"nunmap [(
"nunmap ](
"nunmap [*
"nunmap ]*
"nunmap [`
"nunmap ]`
"nunmap [/
"nunmap ]/
"nunmap [D
"nunmap ]D
"nunmap [I
"nunmap ]I
"nunmap [P
"nunmap ]P
"nunmap [c
"nunmap ]c
"nunmap [d
"nunmap ]d
"nunmap [f
"nunmap ]f
"nunmap [i
"nunmap ]i
"nunmap [m
"nunmap ]m
"nunmap [p
"nunmap ]p
"nunmap [s
"nunmap ]s
"nunmap [z
"nunmap ]z
"nunmap [{
"nunmap ]{
"nunmap [<C-D>
"nunmap ]<C-D>
"nunmap [<C-I>
"nunmap ]<C-I>
"nunmap [_<C-D>
"nunmap ]_<C-D>
"nunmap [_<C-I>
"nunmap ]_<C-I>
"nunmap [_<Tab>
"nunmap ]_<Tab>
"nunmap [<MiddleMouse>
"nunmap ]<MiddleMouse>
"nunmap Q
" unmap some more things that are easy to accidentally press
"nunmap b
au VimEnter * unmap [%
au VimEnter * unmap ]%
" switch to previous / next buffers
"noremap hl :bn!<ENTER>
"noremap lh :bp!<ENTER>
" disable the arrow keys
noremap <up> <nop>
noremap <down> <nop>
noremap <left> <nop>
noremap <right> <nop>
" remap some arrow keys
" (these aren't working and my suspicion is that a plugin overwrites them)
nnoremap <up> :!
nnoremap <down> <nop>
nnoremap <left> <nop>
nnoremap <right> <nop>
inoremap <up> <nop>
inoremap <down> <nop>
inoremap <left> <nop>
inoremap <right> <nop>
" copy to system cliboard is way easier to use
noremap Y "*yy
vnoremap Y "*y
" copy inner word or visual selection to clipboard
nnoremap Z "*yiw
vnoremap Z "*y
" re-select after indenting in visual mode
vnoremap < <gv
vnoremap > >gv
" build and run
noremap ∫ <esc>hl:up<return>:MyTerminal<return><C-w>k<C-w>hi<C-c>clear && make<return><C-\><C-n>G<C-w>l<C-w>k
inoremap ∫ <esc>hl:up<return>:MyTerminal<return><C-w>k<C-w>hi<C-c>clear && make<return><C-\><C-n>G<C-w>l<C-w>k
lnoremap ∫ <esc>hl:up<return>:MyTerminal<return><C-w>k<C-w>hi<C-c>clear && make<return><C-\><C-n>G<C-w>l<C-w>k
tnoremap ∫ <esc>hl:up<return>:MyTerminal<return><C-w>k<C-w>hi<C-c>clear && make<return><C-\><C-n>G<C-w>l<C-w>k
noremap ® <esc>hl:up<return>:MyTerminal<return><C-w>k<C-w>hi<C-c>clear && make buildrun<return><C-\><C-n>G<C-w>l<C-w>k
inoremap ® <esc>hl:up<return>:MyTerminal<return><C-w>k<C-w>hi<C-c>clear && make buildrun<return><C-\><C-n>G<C-w>l<C-w>k
lnoremap ® <esc>hl:up<return>:MyTerminal<return><C-w>k<C-w>hi<C-c>clear && make buildrun<return><C-\><C-n>G<C-w>l<C-w>k
tnoremap ® <esc>hl:up<return>:MyTerminal<return><C-w>k<C-w>hi<C-c>clear && make buildrun<return><C-\><C-n>G<C-w>l<C-w>k
noremap ‰ <esc>hl:up<return>:MyTerminal<return><C-w>k<C-w>hi<C-c>clear && make run<return><C-\><C-n>G<C-w>l<C-w>k
inoremap ‰ <esc>hl:up<return>:MyTerminal<return><C-w>k<C-w>hi<C-c>clear && make run<return><C-\><C-n>G<C-w>l<C-w>k
lnoremap ‰ <esc>hl:up<return>:MyTerminal<return><C-w>k<C-w>hi<C-c>clear && make run<return><C-\><C-n>G<C-w>l<C-w>k
tnoremap ‰ <esc>hl:up<return>:MyTerminal<return><C-w>k<C-w>hi<C-c>clear && make run<return><C-\><C-n>G<C-w>l<C-w>k
noremap ı <esc>hl:up<return>:MyTerminal<return><C-w>k<C-w>hi<C-c>clear && make ctags<return><C-\><C-n>G<C-w>l<C-w>k
inoremap ı <esc>hl:up<return>:MyTerminal<return><C-w>k<C-w>hi<C-c>clear && make ctags<return><C-\><C-n>G<C-w>l<C-w>k
lnoremap ı <esc>hl:up<return>:MyTerminal<return><C-w>k<C-w>hi<C-c>clear && make ctags<return><C-\><C-n>G<C-w>l<C-w>k
tnoremap ı <esc>hl:up<return>:MyTerminal<return><C-w>k<C-w>hi<C-c>clear && make ctags<return><C-\><C-n>G<C-w>l<C-w>k
" lldb debugging
" (to find out that ¡ means alt+1, just go into insert mode and hit the key)
" (else, check this: https://vimhelp.org/vim_faq.txt.html#faq-20.4)
noremap ¡ <esc><C-w>k<C-w>l:GdbNext<return>
inoremap ¡ <C-\><C-n><C-w>k<C-w>l:GdbNext<return>
lnoremap ¡ <C-\><C-n><C-w>k<C-w>l:GdbNext<return>
tnoremap ¡ <C-\><C-n><C-w>k<C-w>l:GdbNext<return>
noremap ™ <esc><C-w>k<C-w>l:GdbStep<return>
inoremap ™ <C-\><C-n><C-w>k<C-w>l:GdbStep<return>
lnoremap ™ <C-\><C-n><C-w>k<C-w>l:GdbStep<return>
tnoremap ™ <C-\><C-n><C-w>k<C-w>l:GdbStep<return>
noremap £ <esc><C-w>k<C-w>l:GdbFinish<return>
inoremap £ <C-\><C-n><C-w>k<C-w>l:GdbFinish<return>
lnoremap £ <C-\><C-n><C-w>k<C-w>l:GdbFinish<return>
tnoremap £ <C-\><C-n><C-w>k<C-w>l:GdbFinish<return>
noremap œ <esc><C-w>k<C-w>l:GdbFrameUp<return>
inoremap œ <C-\><C-n><C-w>k<C-w>l:GdbFrameUp<return>
lnoremap œ <C-\><C-n><C-w>k<C-w>l:GdbFrameUp<return>
tnoremap œ <C-\><C-n><C-w>k<C-w>l:GdbFrameUp<return>
noremap ∑ <esc><C-w>k<C-w>l:GdbFrameDown<return>
inoremap ∑ <C-\><C-n><C-w>k<C-w>l:GdbFrameDown<return>
lnoremap ∑ <C-\><C-n><C-w>k<C-w>l:GdbFrameDown<return>
tnoremap ∑ <C-\><C-n><C-w>k<C-w>l:GdbFrameDown<return>
noremap § <esc><C-w>k<C-w>l:GdbUntil<return>
inoremap § <C-\><C-n><C-w>k<C-w>l:GdbUntil<return>
lnoremap § <C-\><C-n><C-w>k<C-w>l:GdbUntil<return>
tnoremap § <C-\><C-n><C-w>k<C-w>l:GdbUntil<return>
"nnoremap ¢ <esc>hl:up<return>:MyStartDebug<return>
"nnoremap « <esc>hl:up<return>:MyBreakpoint<return>
if has('nvim')
nnoremap <expr> « HasBuffer('-- lldb') ? '<C-w>k<C-w>l:GdbBreakpointToggle<return>':'<esc>hl:up<return>:MyCloseBufIf<return><C-w>k<C-w>hiclear && make buildrundb<return><C-\><C-n>G<C-w>k<C-w>l'
inoremap <expr> « HasBuffer('-- lldb') ? '<C-w>k<C-w>l:GdbBreakpointToggle<return>':'<esc>hl:up<return>:MyCloseBufIf<return><C-w>k<C-w>hiclear && make buildrundb<return><C-\><C-n>G<C-w>k<C-w>l'
nnoremap <expr> ¢ HasBuffer('-- lldb') ? '<C-w>k<C-w>l:GdbContinue<return>':'<esc>hl:up<return><C-w>k<C-w>hiclear && make buildrund<return><C-\><C-n>G<C-w>k<C-w>l'
endif
tnoremap « <C-\><C-n>:MyBreakpoint<return>
tnoremap ¢ <C-\><C-n><C-w>k<C-w>l:MyStartDebug<return>
"
" print a variable while lldb debugging
"vnoremap W y<esc><C-w>jiv <C-\><C-n>pi<return><C-\><C-n><C-w>k
" print a variable while lldb debugging and set a watch on it
nnoremap W yiw<esc><C-w>jitarget stop-hook add --one-liner "v <C-\><C-n>pi"<return>v <C-\><C-n>pi<return><C-\><C-n><C-w>k<C-w>l
vnoremap W y<esc><C-w>jitarget stop-hook add --one-liner "v <C-\><C-n>pi"<return>v <C-\><C-n>pi<return><C-\><C-n><C-w>k<C-w>l
" stop using the control key
" lookup tag under cursor
nnoremap gl :up<return>g<C-]>
" go back
nnoremap gj :up<return><C-o>
"nnoremap gj g;
" go forward
nnoremap gk :up<return><C-i>
"nnoremap gk g,
" drop to shell
nnoremap mx <C-z>
" run shell command in vim
nnoremap m :silent! !
"nnoremap mf :!git commit
"nnoremap ma :!ga<enter>
"nnoremap mp :execute ':silent !gp'<enter>:execute ':redraw!'<enter>
"nnoremap md :!gd<enter>
"nnoremap mm :execute ':silent !gd'<enter>:execute ':redraw!'<enter>
"nnoremap mm :execute ':enew \| r ! gd'<enter>:execute ':silent! saveas! /tmp/d.diff'<enter>gg/diff --git<enter>
"nnoremap mm :execute ':enew \| r ! gd'<enter>:execute ':silent! saveas! /tmp/d.diff'<enter>gg
" git status, diff and commit
nnoremap mn :!gs<enter>
nnoremap mm :execute ':silent !gd > d.diff'<enter>:execute ':e d.diff'<enter>:execute ':redraw!'<enter>gg`"zz
"nnoremap m, :!gc<enter>
"nnoremap m, :execute ':!gc'<enter>:execute ':redraw!'<enter>
" svn status, diff
"nnoremap mk :!d11 connect; svn st<enter>
"nnoremap ml :execute ':silent !d11 connect; svn diff > d.diff'<enter>:execute ':e d.diff'<enter>:execute ':redraw!'<enter>gg`"zz
"nnoremap m; :!d11 connect; svn ci && svn up<enter>
" close current window
nnoremap wt :bd<return>
" window commands
nnoremap w <C-w>
noremap gw <nop>
" move windows left / right
nnoremap ˙ <C-w>hi<C-c>
inoremap ˙ <esc><C-w>hi<C-c>
vnoremap ˙ <esc><C-w>hi<C-c>
cnoremap ˙ <C-c><C-w>hi<C-c>
nnoremap ¬ <C-w>l
vnoremap ¬ <esc><C-w>l
tnoremap ¬ <C-\><C-n><C-w>l
cnoremap ¬ <C-c><C-w>l
" next / previous buffer
nnoremap ∆ :silent! MyPrevBuf<enter>
inoremap ∆ <esc>:silent! MyPrevBuf<enter>
vnoremap ∆ <esc>:silent! MyPrevBuf<enter>
cnoremap ∆ <C-c>:silent! MyPrevBuf<enter>
tnoremap ∆ <C-\><C-n>:silent! MyPrevBuf<enter>
nnoremap ˚ :silent! MyNextBuf<enter>
inoremap ˚ <esc>:silent! MyNextBuf<enter>
vnoremap ˚ <esc>:silent! MyNextBuf<enter>
cnoremap ˚ <C-c>:silent! MyNextBuf<enter>
tnoremap ˚ <C-\><C-n>:silent! MyNextBuf<enter>
" repeat last action
nnoremap s .
nnoremap S .
" find
nnoremap f /
nnoremap F ?
nnoremap ƒ *
nnoremap Ï #
" find tag
nnoremap gh :Tags<enter>
"nnoremap gh :tjump!
" find file
"nnoremap gf :FZF<enter>
"nnoremap gf wk<esc>:Tags<enter>
nnoremap gf :silent! MyTags<enter>
nnoremap gg 1G
"nnoremap g :Tags<enter>
"nnoremap gf :fin
"nnoremap gf :tjump!
" smart close buffer
nnoremap gt :MyCloseBuf<enter><esc>
nnoremap tt :MyCloseBuf<enter><esc>
" open ycom diagnostics location list (ie. the list of errors and warnings)
noremap ge :lopen<return>
noremap gE <nop>
" open BufferGator
noremap b <nop>
noremap B <nop>
noremap <C-b> <nop>
nnoremap gb :BuffergatorOpen<return>
" open Saves.txt
nnoremap gs <C-w>k:silent! e Saves.txt<return>
" paste in insert mode
inoremap <C-p> <C-r>"
" toggle fold at current line
"nnoremap <return> za
" show the currentline
set cursorline
" don't visually wrap lines
set nowrap
" but if we do, break them along word boundaries
set linebreak
" set tab width
set tabstop=4
set shiftwidth=4
" remember undo history
set undofile
set undodir=$HOME/.vim/undo/
" show cursor at the beginning of a tab character
set list listchars=tab:\ \
"set list listchars=tab:·\
" and set the background color for tabs to transparent
hi SpecialKey ctermbg=NONE
" keep the cursor at least X lines from edge of screen
set scrolloff=99
" auto-indent
set autoindent
set nocindent
set nosmartindent
set indentexpr=
" disable smart indent
filetype indent off
" disable automatic comment lines
au FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
au FileType c,cpp setlocal comments-=://
"set formatoptions-=cro
" wrap to the previous / next line when using left / right cursor movement
set whichwrap+=<,>,h,l,[,]
" ensure backspace works
set backspace=start,eol,indent
" case-insensitve search
set ignorecase
set smartcase
" highlight searched-for words
set hlsearch
" press escape to cancel highlight
nnoremap <esc> :noh<return><esc>
nnoremap <esc> :GitGutter<return>:noh<return><esc>
" press escape to exit terminal mode
if has('nvim')
"tnoremap <esc> <C-\><C-n>
tnoremap <expr> <esc> stridx(bufname(), 'FZF') >= 0 ? '<esc>':'<C-\><C-n><C-w>l'
tnoremap <C-v><esc> <esc>
endif
" dont jump the display to the search term before pressing enter
set noincsearch
" automatically read files that have been changed outside the editor
set autoread
" instead of the following, using vim-autoread
" cause autoread to trigger whenever moving the cursor
"au CursorMoved * silent! checktime
" this causes the autoread to happen by dropping to a shell automatically
"au FocusGained,BufEnter * :silent! !
"au FileChangedShell * :silent! !
" this causes vim to redraw after dropping to the shell
"au FocusGained,BufEnter * :redraw!
" default output encoding of terminal (see set filencoding...)
set encoding=utf-8
" show hybrid relative line numbers
set number
set relativenumber
" show the command being entered in the bottom right
set showcmd
" don't use backup / swap files
set nobackup
set nowritebackup
set noswapfile
" enable case-insensitve tab completion for switching buffers
set wildchar=<Tab> wildmenu wildmode=full
set wildignorecase
set wildmode=longest,list
" look for tags files in parent directories
set tags=tags,./tags
" always show powerline / airline
set laststatus=2
" disable showing a preview window when auto-completing
set completeopt-=preview
" disable some messages ('I' disables welcome message)
" other interesting: oOcF
set shortmess=atTWIF
" search path when using the "find" command
set path=src,data/**,.vimpath
" make gitgutter snappier
set updatetime=250
" ask for confirmation instead of warning about unsaved file
set confirm
" enable code folding based on indent level (zc to close, zo to open)
set foldmethod=indent
set foldnestmax=10
set nofoldenable
set foldlevel=2
" show colors in terminal
"set termguicolors
" set lldb syntax
au BufRead,BufNewFile *.lldb setfiletype lldb
au BufRead,BufNewFile *.list setfiletype list
" set hlsl syntax
au BufRead,BufNewFile *.fx,*.fxc,*.fxh,*.hlsl setfiletype hlsl
" load bash profile when executing external commands
let $BASH_ENV = "~/.profile"
" block cursor in command mode, underline cursor in insert mode
if $TERM_PROGRAM == "iTerm.app"
let &t_SI .= "\<Esc>[4 q"
let &t_EI .= "\<Esc>[2 q"
endif
" change folding text
function! MyFoldText()
"let nblines = v:foldend - v:foldstart + 1
"let w = winwidth(0) - &foldcolumn - (&number ? 8 : 0)
"let line = getline(v:foldstart)
"let comment = substitute(line, '/\*\|\*/\|{{{\d\=', '', 'g')
"let expansionString = repeat(".", w - strwidth(nblines . '"'))
"let txt = expansionString . nblines
let txt = ''
return txt
endfunction
set foldtext=MyFoldText()
" set autoformat program
set formatprg=astyle\ -A1
"set formatprg=astyle\ -T4pxby
"au BufNewFile,BufRead *.cpp set formatprg=astyle\ -T4pb
" don't move the cursor backwards after leaving insert mode
au InsertLeave * call cursor([getpos('.')[1], getpos('.')[2]+1])
" my grep command
let g:mygrep_path = ''
"command! -nargs=+ MyGrep execute 'silent grep! -R -i <args> src data' | copen | redraw!
command! -nargs=+ MyGrep execute 'silent grep! -p -i '.shellescape(<q-args>).' '.g:mygrep_path | copen | redraw!
"command! -nargs=+ MyGrep execute 'silent grep! -p -i '.shellescape(<q-args>).' *.cpp *.h */*.cpp */*.h */*/*.cpp */*/*.h */*/*/*.cpp */*/*/*.h data/*/*.txt projects/*/*.mm projects/*/*.plist projects/*/*.rc projects/*/*.txt projects/*/*.sh gog/*.json' | copen | redraw!
"command! -nargs=+ MyGrep execute 'silent grep! -p -i -R '.shellescape(<q-args>).' *.cpp *.h *.txt *.mm *.plist *.json *.hpp *.rc *.sh ' | copen | redraw!
"command! -bang -nargs=* MyGrep
" \ call fzf#vim#grep('git grep --line-number '.shellescape(<q-args>), 0, <bang>0)
"command! -bang -nargs=* MyGrep
" \ call fzf#vim#grep('ag '.shellescape(<q-args>), 0, <bang>0)
" my search and replace command
fun! FunMyReplace(search, replace)
execute ":'<,'>s/" . a:search . '/' . a:replace . '/gc'
endfunction
command! -nargs=+ MyReplace call FunMyReplace(<f-args>)
" switch to corresponding file
fun! FunMyAltFile(closed)
let l:path = expand("%:p")
let l:origpath = l:path
let l:replace = {
\ "kit/inc/kit": "kit/src",
\ ".cpp": ".h",
\ }
let l:cwd = getcwd() . '/'
" make substitutions
for l:key in keys(l:replace)
let l:val = get(l:replace, l:key)
if stridx(l:path, l:key) >= 0
"echo l:key
let l:path = substitute(l:path, '\V' . l:key, l:val, "")
elseif stridx(l:path, l:val) >= 0
"echo l:val
let l:path = substitute(l:path, '\V' . l:val, l:key, "")
endif
endfor
" simplify path
let l:path = substitute(l:path, '\V' . l:cwd, "", "")
if !filereadable(l:path)
"echo "Cannot read: " . l:path
return
endif
" if not closed then we have manually pressed 'gc'
" if closed then we are automatically called via autocmd
if a:closed >= 1
" already has?
if s:HasBuffer(l:path)
echo "Already has buffer: " . l:path
return
endif
echo "Adding buffer: " . l:path
execute "badd " . l:path
execute "bdel! " . l:path
"execute "bdel " . bufnr('%')
else
echo "Editing buffer: " . l:path
execute "silent! edit " . l:path
endif
" this is meant to work with the BufNewFile but it somehow blocks going to
" the last place in both of the opened files
"execute "badd " . l:path
"execute "buffer " . l:path
"execute "normal! g`\"zz"
"execute "buffer " . l:origpath
"execute "normal! g`\"zz"
endfunction
command! -nargs=* MyAltFile call FunMyAltFile(<f-args>)
nnoremap gc :silent! MyAltFile(0)<return>
au BufRead *.h silent! call FunMyAltFile(1)
au BufRead *.cpp silent! call FunMyAltFile(1)
" function returns 1 if has an lldb buffer
fun! s:HasBuffer(name)
let l:buffers = filter(range(1, bufnr('$')), 'bufloaded(v:val)')
for l:key in l:buffers
let l:name = bufname(l:key)
"echo l:name
if stridx(l:name, a:name) >= 0
return 1
endif
endfor
return 0
endfunction
" this version of the function for the conditional mappings above
fun! HasBuffer(name)
let l:buffers = filter(range(1, bufnr('$')), 'bufexists(v:val)')
for l:key in l:buffers
let l:name = bufname(l:key)
if stridx(l:name, a:name) >= 0
return 1
endif
endfor
return 0
endfunction
" close quickfix if it is open
fun! s:CloseQuickFix()
bufdo if &buftype=="quickfix" | execute "bdelete! " . bufnr('%') | endif
endfunction
" switch to prev / next buffer
fun! FunMyPrevBuf()
wincmd k
wincmd l
execute "bprev!"
if !&modifiable
execute "bprev!"
endif
if &buftype=="quickfix"
execute "bdelete!"
endif
"bufdo if &buftype=="quickfix" | execute "bdelete!" | endif
"call s:CloseQuickFix()
endfunction
command! -nargs=* MyPrevBuf call FunMyPrevBuf(<f-args>)
fun! FunMyNextBuf()
wincmd k
wincmd l
execute "bnext!"
if !&modifiable
execute "bnext!"
endif
"call s:CloseQuickFix()
endfunction
command! -nargs=* MyNextBuf call FunMyNextBuf(<f-args>)
" started this function in order to toggle left/right windows
" but moving to left window requires entering insert mode
" and havent figured out how to do this from vimscript
" (see build and run nnoremap ∫ above)
"fun! FunMyToggleBuf()
" try
" " if two windows, close the bottom
" " if one window, close it
" let l:win = winnr()
" let l:wincount = winnr('$')
" echo "window " . l:win . "/" . l:wincount
" catch /.*/
" finally
" endtry
"endfunction
"command! -nargs=* MyToggleBuf call FunMyToggleBuf(<f-args>)
function! FunMyCloseUnlistedBuffers()
" close any buffer that is unlisted
let l:tally = 0
for b in range(1, bufnr('$'))
if !bufloaded(b)
let l:tally += 1
exe 'silent! bwipeout! ' . b
endif
endfor
echon "Deleted " . l:tally . " buffers"
endfun
command! -nargs=* Only call FunMyCloseUnlistedBuffers()
fun! FunMyCloseBuf()
try
"call FunMyCloseUnlistedBuffers()
" if help view open, close it
if s:HasBuffer("runtime/doc/")
echo "Closing help docs"
wincmd k
wincmd l
execute "bdelete!"
return
endif
" if debugging, go to a different window
" then close the previous buffer
if s:HasBuffer("-- lldb")
echo "Closing lldb session"
wincmd k
wincmd l
let l:buf = bufnr('%')
execute "bprev!"
execute "bdelete! " . l:buf
return
endif
" if buffergator open, close it
" (for some reason this closes the entire vim session the next time gt is pressed)
"if s:HasBuffer("buffergator")
" echo "Closing buffergator"
" wincmd j
" wincmd j
" let l:buf = bufnr('%')
" wincmd k
" wincmd l
" execute "bdelete! " . l:buf
" return
"endif
" if two windows, close the bottom
" if one window, close it
let l:win = winnr()
let l:wincount = winnr('$')
"echo "window " . l:win . "/" . l:wincount
if l:win >= 3 || l:wincount >= 4
" close bottom right window
echo "Closing bottom-right window " . l:win . "/" . l:wincount
wincmd b
execute "bdelete!"
elseif l:win >= 2
" close top right window
echo "Closing top-right window " . l:win . "/" . l:wincount
wincmd l
wincmd k
let l:buf = bufnr('%')
execute "bprev!"
execute "bdelete! " . l:buf
else
" close main code window
echo "Closing main window " . l:win . "/" . l:wincount
execute "bdelete!"
endif
catch /.*/
finally
endtry
endfunction
command! -nargs=* MyCloseBuf call FunMyCloseBuf(<f-args>)
fun! FunMyCloseBufIf()
let l:win = winnr()
let l:wincount = winnr('$')
"echo "window " . l:win . "/" . l:wincount
if l:win >= 3 || l:wincount >= 4
call FunMyCloseBuf()
endif
endfunction
command! -nargs=* MyCloseBufIf call FunMyCloseBufIf(<f-args>)
fun! FunMyTags()
let l:win = winnr()
if l:win > 2
wincmd b
execute "bdelete!"
endif
execute "Tags"
endfunction
command! -nargs=* MyTags call FunMyTags(<f-args>)
fun! FunMyTerminal()
let l:win = winnr()
if l:win == 1
execute "55vsplit"
execute "term"
execute "set norelativenumber"
execute "setlocal nobuflisted"
execute "set syntax=term"
execute "set modifiable"
wincmd H
execute "vertical resize 55"
let b:myterminal = 1
wincmd l
endif
endfunction
command! -nargs=* MyTerminal call FunMyTerminal(<f-args>)
au VimEnter * MyTerminal
fun! FunMyTerminalAutoClose()
try
if winnr('$') == 1 "&& exists("b:myterminal") && b:myterminal == 1
quit!
endif
catch /.*/
finally
endtry
endfunction
au WinEnter * call FunMyTerminalAutoClose()
" store / restore buffer
fun! FunMyStoreBuffer()
let g:storedbuf = bufnr('%')
let g:storedline = line('.')
endfunction
command! -nargs=* MyStoreBuffer call FunMyStoreBuffer(<f-args>)
fun! FunMyRestoreBuffer()
execute "buffer! " . g:storedbuf
execute g:storedline
endfunction
command! -nargs=* MyRestoreBuffer call FunMyRestoreBuffer(<f-args>)
" build and run
fun! FunMyBuild()
execute "AsyncRun pwd && make"
endfunction
command! -nargs=* MyBuild call FunMyBuild(<f-args>)
fun! FunMyAltBuild()
execute "AsyncRun pwd && make ctags"
endfunction
command! -nargs=* MyAltBuild call FunMyAltBuild(<f-args>)
fun! FunMyBuildRun()
execute "AsyncRun pwd && make buildrun"
endfunction
command! -nargs=* MyBuildRun call FunMyBuildRun(<f-args>)
fun! FunMyRun()
execute "AsyncRun pwd && make run"
endfunction
command! -nargs=* MyRun call FunMyRun(<f-args>)
" lldb debugging functions
fun! s:FunMyBreakpointOnExit(job_id, code, event) dict
if a:code == 0
close
endif
endfunction
fun! FunMyBreakpoint()
if s:HasBuffer("-- lldb")
wincmd k
execute "GdbBreakpointToggle"
return
endif
" start debugging in vim with breakpoint
if winnr() > 1
wincmd l
wincmd k
endif
execute "!pwd && make buildrundb"
wincmd l
wincmd k
endfunction
command! -nargs=* MyBreakpoint call FunMyBreakpoint(<f-args>)
fun! FunMyStartDebug()
if s:HasBuffer("-- lldb")
wincmd l
wincmd k
execute "GdbContinue"
return
endif
" start debugging in vim
call FunMyCloseBuf()
wincmd l
wincmd k
execute "!pwd && make buildrund"
endfunction
command! -nargs=* MyStartDebug call FunMyStartDebug(<f-args>)
"function! s:GetDefinitionInfo()
" exe 'normal ma'
" " Get class
" call search('^\s*\<class\>', 'b')
" exe 'normal ^L"ayw'
" let s:class = @a
" echo s:class
" "let l:ns = search('^\s*\<namespace\>', 'b')
" "" Get namespace
" "if l:ns != 0
" " exe 'normal ^w"ayw'
" " let s:namespace = @a
" "else
" " let s:namespace = ''
" "endif
" " Go back to definition
" "exe 'normal `a'
" "exe 'normal "aY'
" "let s:defline = substitute(@a, ':\n', '', '')
" "echo s:defline
"endfunction
"command! CopyDefinition :call s:GetDefinitionInfo()
"
"function! s:ImplementDefinition()
" call append('.', s:defline)
" exe 'normal j'
" " Remove keywords
" s/\<virtual\>\s*//e
" s/\<static\>\s*//e
" if s:namespace == ''
" let l:classString = s:class . "::"
" else
" let l:classString = s:namespace . "::" . s:class . "::"
" endif
" " Remove default parameters
" s/\s\{-}=\s\{-}[^,)]\{1,}//e
" " Add class qualifier
" exe 'normal ^f(bi' . l:classString
" " Add brackets
" exe "normal $o{\<CR>\<TAB>\<CR>}\<CR>\<ESC>kkkk"
" " Fix indentation
" exe 'normal =4j^'
"endfunction
"command! ImplementDefinition :call s:ImplementDefinition()
" reorganize buffer list
" this method turned out to either forget the last place in each buffer
" or else reload all the buffers in the same order as before despite the
" correct argument list
"fun! FuncAlphabetizeBuffers()
" set eventignore=BufReadPost
" "let tn=tempname()
" let tn="/tmp/yep"
" " redirect all output of commands to temp file
" exec "redir! > ".tn
" " list buffers
" ls
" " stop redirect
" redir END
" " edit temp file
" exec "e ".tn
" "exec "sp ".tn
" " replace no names with empty
" %s/\[No Name\]//
" " delete all empty lines
" v/./d
" " delete all text outside of double quotes
" %s/.*"\(.*\)".*/\1
" " sort based on basename of file on each line
" sort /[^/]*$/ r
" " replace space with slash-space
" "%s/ /\\ /g
" " reduce to one line
" %j
" " prepend with argadd
" s/^/argadd /
" " write
" exec "w"
" " remove existing arguments
" %argdelete
" " execute this file (all sorted files become arguments listable with :ar)
" so %
" " close this buffer
" bd!
" " close all buffers
" "%bw!
" "%bd!
" " load buffers from arguments list
" "argdo! e | execute "normal! g`\"zz"
" "call delete(tn)
" "unlet tn
" set eventignore=""
"endfunction
"command! Alpha silent! call FuncAlphabetizeBuffers()
"command! AlphaPrev silent! call FuncAlphabetizeBuffers() | 0prev
"command! AlphaNext silent! call FuncAlphabetizeBuffers() | 0next
"au BufReadPost * noautocmd silent!call FuncAlphabetizeBuffers()
" configure fzf
set rtp+=/usr/local/opt/fzf
"let g:fzf_history_dir = '~/.local/share/fzf-history'
let $FZF_DEFAULT_OPTS = '--bind btab:down,tab:up'
let $FZF_DEFAULT_COMMAND = 'ag "" src/*.cpp src/*.h data/**/*.txt projects/*/*.mm src/fmod/mac/*/inc/*.h* src/OIS/includes cocos2d-x/cocos/*/*.h cocos2d-x/cocos/*/*.cpp src/steam/*.h .vimpath/* -l | sed "/xbone_events_manifest/d"'
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'] }
" configure ctrlp
"let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files -co --exclude-standard']
"let g:ctrlp_custom_ignore = {
" \ 'dir': '\v[\/]\.(git|svn)$',
" \ 'file': '\v\.(exe|so|dll|lib|zip|aiff|wav|png|mp4)$',
" \ 'link': '',
" \ }
" configure youcompleteme (auto-completion)
let g:ycm_python_binary_path = '/usr/local/bin/python3'
let g:ycm_confirm_extra_conf = 0
"let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py'
"let g:ycm_key_list_select_completion = ['<TAB>', '<Enter>']
"let g:ycm_key_list_select_completion = ['<Enter>']
let g:ycm_key_list_select_completion = ['<TAB>']
let g:ycm_error_symbol = 'E'
let g:ycm_warning_symbol = 'W'
let g:ycm_complete_in_comments = 1
let g:ycm_complete_in_strings = 1
let g:ycm_collect_identifiers_from_comments_and_strings = 1
"let g:ycm_collect_identifiers_from_tags_files = 1
let g:ycm_seed_identifiers_with_syntax = 1
let g:ycm_always_populate_location_list = 1
let g:ycm_filetype_specific_completion_to_disable = {}
" let g:ycm_filetype_whitelist = { '*': 1 }
let g:ycm_filetype_blacklist = {
\ 'markdown' : 1,
\ 'vimwiki' : 1,
\}
"
" trying to get ycm's preview window to popup...
" seems that neovim doesnt support completeopt=popup
" because g:ycm_add_preview_to_completeopt = 1 does create a window
" https://github.com/ycm-core/YouCompleteMe#options
"
"let g:ycm_max_num_candidates_to_detail = 10
"let g:ycm_add_preview_to_completeopt = 1
"let g:ycm_auto_hover = 'CursorHold'
"nnoremap ˆ <plug>(YCMHover)
"augroup MyYCMCustom
" autocmd!
" autocmd FileType c,cpp let b:ycm_hover = {
" \ 'command': 'GetDoc',
" \ 'syntax': &filetype
" \ }
"augroup END
" configure airline to use powerline fonts
let g:airline_powerline_fonts = 1
" disable airline's word count
let g:airline#extensions#wordcount#enabled = 0
" disable airline's whitespace checking
"let g:airline#extensions#whitespace#checks = [ 'indent', 'trailing', 'long', 'mixed-indent-file' ]
let g:airline#extensions#whitespace#checks = [ ]
" configure airline's status bar
"let g:airline_section_a = '%#__accent_bold#%{airline#util#wrap(airline#parts#mode(),0)}%#__restore__#%{airline#util#append(airline#parts#crypt(),0)}%{airline#util#append(airline#parts#paste(),0)}%{airline#util#append(airline#parts#spell(),0)}%{airline#util#append("",0)}%{airline#util#append(airline#parts#iminsert(),0)}'
"let g:airline_section_b = '%{airline#util#wrap(airline#extensions#hunks#get_hunks(),0)}%{airline#util#wrap(airline#extensions#branch#get_head(),0)}'
let g:airline_section_b = ''
"let g:airline_section_c = '%<%f%m %#__accent_red#%{airline#util#wrap(airline#parts#readonly(),0)}%#__restore__#'
"let g:airline_section_x = '%{airline#util#prepend(airline#extensions#tagbar#currenttag(),0)}%{airline#util#wrap(airline#parts#filetype(),0)}'
let g:airline_section_x = '%{airline#util#wrap(airline#extensions#tagbar#currenttag(),0)}'
"let g:airline_section_y = '%{airline#util#wrap(airline#parts#ffenc(),0)}'
let g:airline_section_y = ''
"let g:airline_section_z = '%3p%% %#__accent_bold#%{g:airline_symbols.linenr}%#__accent_bold#%4l%#__restore__#%#__restore__#%#__accent_bold#%#__accent_bold#/%L%{g:airline_symbols.maxlinenr}%#__restore__#%#__restore__# :%3v'
let g:airline_section_z = '%l/%L %c'
" show current class and function in airline section x
let g:airline#extensions#tagbar#enabled = 1
let g:airline#extensions#tagbar#flags = 'f'
" Enable the list of buffers
let g:airline#extensions#tabline#enabled = 1
" just show the filename (no path) in the tab
let g:airline#extensions#tabline#formatter = 'unique_tail'
" buffer gator settings
" use the bottom of the screen
let g:buffergator_viewport_split_policy = 'B'
" make the buffer list window this high
let g:buffergator_hsplit_size = 10
" sort buffer list by file basename
" actually don't do this, instead prefer buffer ordering to use gator for
" removing unneeded buffers
"let g:buffergator_sort_regime = "basename"
" use my own keymappings
let g:buffergator_suppress_keymaps = 1
" configure lastplace plugin (remembers last location in file)
let g:lastplace_ignore = "gitcommit,gitrebase,svn,hgcommit,diff"
" setup plugin to automatically refresh ctags
let g:autotagCtagsCmd = "ctags --extra=+q --languages=+ObjectiveC --langmap=ObjectiveC:+.mm --langmap=C++:+.inl"
let g:autotagExcludeSuffixes = "mm"
" options for ~/.vim/after/cpp.vim (https://github.com/bfrg/vim-cpp-modern)
let g:cpp_class_scope_highlight = 1
let g:cpp_class_member_highlight = 1
" allow as many git hunks as needed
let g:gitgutter_max_signs=9999
" targets.vim
" make default `cia` (change inner argument) behavior
" leave the space at the beginning of a text object
let g:targets_aiAI = 'aIAi'
" vim-minimap
let g:minimap_highlight='Visual'
" set vimade inactive buffer dimming level
let g:vimade = {}
let g:vimade.fadelevel = 0.5
" make AsyncRun automatically open a quickfix window
let g:asyncrun_open = 10
" gitgutter functions to jump to next hunk regardless of buffer
function! NextHunkAllBuffers()
let line = line('.')
GitGutterNextHunk
if line('.') != line
return
endif
let bufnr = bufnr('')
while 1
execute "up"
bnext
if bufnr('') == bufnr
return
endif
if !empty(GitGutterGetHunks())
normal! 1G
GitGutterNextHunk
return
endif
endwhile
endfunction
function! PrevHunkAllBuffers()
let line = line('.')
GitGutterPrevHunk
if line('.') != line
return
endif
let bufnr = bufnr('')
while 1
execute "up"
bprevious
if bufnr('') == bufnr
return
endif
if !empty(GitGutterGetHunks())
normal! G
GitGutterPrevHunk
return
endif
endwhile
endfunction
" enable vertical scrollbar
augroup ScrollbarInit
au!
au CursorMoved,VimResized,QuitPre * silent! lua require('scrollbar').show()
au BufEnter,FocusGained * silent! lua require('scrollbar').show()
au BufLeave,FocusLost * silent! lua require('scrollbar').clear()
augroup end
" create text object for c++ member functions
" 202111-01-02
"call textobj#user#plugin('ckeyword', {
"\ 'keyword': {
"\ 'pattern': '\<\[0\-9\]\+-\d\d-\d\d\>',
"\ 'select': ['ak', 'ik'],
"\ },
"\ })
"\ 'pattern': '^[a-zA-Z_][a-zA-Z0-9_]*$',
"let g:textobj_clang_more_mappings = 1
" load pathogen (auto-loads plugins in ~/.vim directory) "a poor man's vundle"
execute pathogen#infect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment