diff --git a/bin/scmindent.rkt b/bin/scmindent.vim.rkt similarity index 100% rename from bin/scmindent.rkt rename to bin/scmindent.vim.rkt diff --git a/vimrc b/vimrc index 3584647..183fb5f 100644 --- a/vimrc +++ b/vimrc @@ -411,7 +411,7 @@ augroup campoCmds autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif " Properly indent schemes (scheme, racket, etc). - autocmd BufRead,BufNewFile *.{lisp,scm,rkt} setlocal equalprg=scmindent.rkt + autocmd BufRead,BufNewFile *.{lisp,scm,rkt} setlocal equalprg=scmindent.vim.rkt " Elixir indent autocmd FileType elixir setlocal tabstop=2 | setlocal shiftwidth=2 | setlocal softtabstop=2 @@ -615,6 +615,9 @@ imap jj " Suspend vim process and return to the shell. Can return to vim with `fg`. nnoremap z +" edit a file +nnoremap e :e + " Open the vimrc file for editing / reload vimrc file. nnoremap ev :vsp $MYVIMRC nnoremap pv :vsp ~/.vimrc.private @@ -732,7 +735,7 @@ noremap Q " Open a terminal within vim. Use `exit` to close it. if exists(':terminal') noremap t :terminal - tnoremap e + tnoremap te tnoremap h tnoremap j tnoremap k @@ -1305,48 +1308,56 @@ function! StopRunTask() call HideAsyncResults() endfunction -function! Build(optimized=0) - let l:params = "" +function! Build(optimized=0, silent=0) let l:ext = tolower(expand('%:e')) - if l:ext == "jai" - " Jai build + let l:parent_dir = expand('%:p:h') + let l:async_cmd = "AsyncRun! -save=2 " + if a:silent + let l:async_cmd .= "-post=call\\ HideAsyncResults() " + endif + let l:cmd = "" + if filereadable(l:parent_dir . "/build.jai") + " Jai build file + let l:cmd = "jai " . l:parent_dir . "/build.jai " + if a:optimized == 1 + echo "Compiling release build.jai" + let l:cmd .= "-release " + else + echo "Compiling debug build.jai" + endif + elseif l:ext == "jai" let l:cmd = "jai % " if a:optimized == 1 + echo "Compiling release " . expand('%:t') let l:cmd .= "-release " + else + echo "Compiling debug " . expand('%:t') endif " If there's a local modules/ directory then we'll import it. - if isdirectory(expand('%:p:h') . "/modules") + if isdirectory(l:parent_dir . "/modules") let l:cmd .= "-import_dir modules " endif - exec "AsyncRun! -save=2 " . l:cmd else + let l:cmd .= './build* ' if a:optimized == 1 - let l:params .= '-o ' + let l:cmd .= '-o ' endif - exec "AsyncRun! -save=2 ./build* " . l:params - endif -endfunction - -function! SilentBuild(optimized=0) - AsyncStop - let l:params = '' - let l:extension = tolower(expand('%:e')) - if l:extension == "jai" - if a:optimized == 1 - let l:params .= '-release ' - endif - exec "AsyncRun! -save=2 -post=call\\ HideAsyncResults() jai % " . l:params - else - if a:optimized == 1 - let l:params .= '-o ' - endif - exec "AsyncRun! -save=2 -post=call\\ HideAsyncResults() ./build* " . l:params endif + exec l:async_cmd . l:cmd endfunction function! RunExe() if tolower(expand('%:e')) == "jai" - exec "AsyncRun! " . expand('%:p:r') . ".exe" + if filereadable(expand('%:p:r') . '.exe') + exec "AsyncRun! " . expand('%:p:r') . ".exe" + else + let l:files = systemlist('ls ' . expand('%:p:h') . '/*.exe 2>/dev/null') + if len(l:files) > 0 + exec "AsyncRun! " . l:files[0] + else + call PrintError("No exe found. Compile first?") + endif + endif else exec "AsyncRun! -post=call\\ StopRunTask() ./run %" endif @@ -1359,22 +1370,22 @@ augroup asyncPluginCmds augroup END " Toggle build results -noremap :call ToggleBuildResults() nnoremap bc :call ToggleBuildResults() - +noremap :call ToggleBuildResults() " Hide build results and clear errors noremap :call HideBuildResultsAndClearErrors() -" Execute build script -nnoremap b :call Build(0) -nnoremap :call SilentBuild(0) +" Execute build script and keep results. +nnoremap b :call Build(0) +" Execute build and hide results. +nnoremap :call Build(0, 1) " Execute optimized build script nnoremap bb :call Build(1) " Execute run script -nnoremap br :call RunExe() -nnoremap :call RunExe() +nnoremap br :call RunExe() +nnoremap :call RunExe() nnoremap bs :AsyncStop @@ -1410,17 +1421,35 @@ function! Search(path, search_args, case_insensitive=0) exec 'Rg ' . l:rg_args . ' -e "' . l:term . '"' . ' ' . a:path endfunction -" Case insensitive +""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Search in current directory. +""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Case insensitive: noremap s :call Search('.', g:campo_custom_search_args, 1) -noremap :call Search('.', g:campo_custom_search_args, 1) -" Jai search -noremap sm :call Search(g:campo_jai_path, g:campo_custom_search_args, 1) - -" Case sensitive +" Case sensitive: noremap ss :call Search('.', g:campo_custom_search_args) -noremap :call Search('.', g:campo_custom_search_args) -" Jai module search -noremap ssm :call Search(g:campo_jai_path, g:campo_custom_search_args) + +""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" # Search in directory containing the active file. +""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Case insensitive: +noremap sf :call Search(expand('%:p:h'), g:campo_custom_search_args, 1) +" Case sensitive: +noremap ssf :call Search(expand('%:p:h'), g:campo_custom_search_args) + +""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Search in Jai folders +""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Case insensitive: +noremap sg :call Search(g:campo_jai_path, g:campo_custom_search_args, 1) +noremap sm :call Search(g:campo_jai_path . '/modules', g:campo_custom_search_args, 1) +noremap sh :call Search(g:campo_jai_path . '/how_to', g:campo_custom_search_args, 1) +noremap se :call Search(g:campo_jai_path . '/examples', g:campo_custom_search_args, 1) +" Case sensitive: +noremap ssg :call Search(g:campo_jai_path, g:campo_custom_search_args) +noremap ssm :call Search(g:campo_jai_path . '/modules', g:campo_custom_search_args) +noremap ssh :call Search(g:campo_jai_path . '/how_to', g:campo_custom_search_args) +noremap sse :call Search(g:campo_jai_path . '/examples', g:campo_custom_search_args) " Navigation for the vim-ripgrep search results. " Hit o on a result line to open the file at that line. @@ -1432,6 +1461,11 @@ nnoremap p (&buftype is# "quickfix" ? "\|:copen" : "p") " SEARCH & REPLACE """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" @warning I've stopped using this because it sometimes locks up vim and I +" have to force exit the process then clean up the swap files. +" @improve Figure out what's causing vim to freeze and fix it. Seems to happen +" when it quickly changes and saves a handful of buffers. + " Replace text in a git repo's committed files. " The range identifier allows us to run this once when multiple lines are selected in a file. function! GlobalReplaceIt(confirm_replacement) range