This repository has been archived on 2024-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/apps/neovim/commands.vim
2020-01-22 17:25:47 -06:00

85 lines
2.4 KiB
VimL

" TODO: need a way to toggle this and maybe make it on by default except in
" files where space indentation is expected
fun! ShowSpaceIndentation()
hi LeadingWhiteSpaces ctermfg=black ctermbg=8
endfunction
fun! HideSpaceIndentation()
hi LeadingWhiteSpaces ctermfg=black ctermbg=black
endfunction
hi LeadingWhiteSpaces ctermfg=black ctermbg=black
:command! SpaceIndents call ShowSpaceIndentation()
:command! ShowSpaceIndents call ShowSpaceIndentation()
:command! HideSpaceIndents call HideSpaceIndentation()
" jump to last opened position in file except in git commits
let jump_to_pos_blacklist = ['gitcommit']
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") && index(jump_to_pos_blacklist, &ft) | exe "normal! g'\"" | endif
endif
" make any necessary directories in the path when saving a file
fun! <SID>AutoMakeDirectory()
let s:directory = expand("<afile>:p:h")
if !isdirectory(s:directory)
call mkdir(s:directory, "p")
endif
endfun
autocmd BufWritePre,FileWritePre * :call <SID>AutoMakeDirectory()
" run make from vim smartly
if !exists("g:make_args")
let g:make_args="default"
endif
fun! RunMake()
split
if has('nvim')
" run from the root of the current git repository
let path = system("git rev-parse --show-toplevel | tr -d '\\n'")
" TODO: handle non-git situations
execute 'terminal cd ' . path . ' && make ' . g:make_args
startinsert
else
execute '!make ' . g:make_args
endif
endfun
" kill the terminal buffer when the process exits
autocmd TermClose * call feedkeys('<cr>')
fun! NERDProjectViewer()
let path = system("git rev-parse --show-toplevel | tr -d '\\n'")
execute 'NERDTree' path
endfun
" a toggle-able minimalistic distraction-free text editing mode
let s:distractionFreeMode = 0
fun! DistractionFreeModeFunc()
if s:distractionFreeMode == 0
let s:distractionFreeMode = 1
AirlineToggle
Goyo
else
let s:distractionFreeMode = 0
Goyo!
AirlineToggle
AirlineRefresh
endif
endfunction
" prevents normal window navigation and closing while in DistractionFreeMode
fun! CheckCloseDistractionFreeMode()
if s:distractionFreeMode == 1
call DistractionFreeModeFunc()
endif
endfunction
" run the previous checking function every time we leave a window
if has('autocmd')
" autocmd WinLeave * call CheckCloseDistractionFreeMode()
endif
" AddTabularPattern! ssv /\s/r0c0l0
command! DistractionFreeMode call DistractionFreeModeFunc()