Improve jai search and compiling in vim
This commit is contained in:
parent
8eccc9659a
commit
9371817937
122
vimrc
122
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 <Esc>
|
|||
" Suspend vim process and return to the shell. Can return to vim with `fg`.
|
||||
nnoremap <leader>z <c-z>
|
||||
|
||||
" edit a file
|
||||
nnoremap <leader>e :e
|
||||
|
||||
" Open the vimrc file for editing / reload vimrc file.
|
||||
nnoremap <silent> <leader>ev :vsp $MYVIMRC<cr>
|
||||
nnoremap <silent> <leader>pv :vsp ~/.vimrc.private<cr>
|
||||
|
@ -732,7 +735,7 @@ noremap Q <Nop>
|
|||
" Open a terminal within vim. Use `exit` to close it.
|
||||
if exists(':terminal')
|
||||
noremap <leader>t :terminal<cr>
|
||||
tnoremap <leader>e <C-\><C-n>
|
||||
tnoremap <leader>te <C-\><C-n>
|
||||
tnoremap <A-h> <C-\><C-n><C-w>h
|
||||
tnoremap <A-j> <C-\><C-n><C-w>j
|
||||
tnoremap <A-k> <C-\><C-n><C-w>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 <F11> :call ToggleBuildResults()<cr>
|
||||
nnoremap <leader>bc :call ToggleBuildResults()<cr>
|
||||
|
||||
noremap <F11> :call ToggleBuildResults()<cr>
|
||||
" Hide build results and clear errors
|
||||
noremap <F10> :call HideBuildResultsAndClearErrors()<cr>
|
||||
|
||||
" Execute build script
|
||||
nnoremap <leader>b :call Build(0)<cr>
|
||||
nnoremap <F8> :call SilentBuild(0)<cr>
|
||||
" Execute build script and keep results.
|
||||
nnoremap <silent><leader>b :call Build(0)<cr>
|
||||
" Execute build and hide results.
|
||||
nnoremap <silent><F8> :call Build(0, 1)<cr>
|
||||
|
||||
" Execute optimized build script
|
||||
nnoremap <leader>bb :call Build(1)<cr>
|
||||
|
||||
" Execute run script
|
||||
nnoremap <leader>br :call RunExe()<cr>
|
||||
nnoremap <F9> :call RunExe()<cr>
|
||||
nnoremap <silent><leader>br :call RunExe()<cr>
|
||||
nnoremap <silent><F9> :call RunExe()<cr>
|
||||
|
||||
nnoremap <leader>bs :AsyncStop<cr>
|
||||
|
||||
|
@ -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 <leader>s :call Search('.', g:campo_custom_search_args, 1)<cr>
|
||||
noremap <F2> :call Search('.', g:campo_custom_search_args, 1)<cr>
|
||||
" Jai search
|
||||
noremap <leader>sm :call Search(g:campo_jai_path, g:campo_custom_search_args, 1)<cr>
|
||||
|
||||
" Case sensitive
|
||||
" Case sensitive:
|
||||
noremap <leader>ss :call Search('.', g:campo_custom_search_args)<cr>
|
||||
noremap <F3> :call Search('.', g:campo_custom_search_args)<cr>
|
||||
" Jai module search
|
||||
noremap <leader>ssm :call Search(g:campo_jai_path, g:campo_custom_search_args)<cr>
|
||||
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
" # Search in directory containing the active file.
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
" Case insensitive:
|
||||
noremap <leader>sf :call Search(expand('%:p:h'), g:campo_custom_search_args, 1)<cr>
|
||||
" Case sensitive:
|
||||
noremap <leader>ssf :call Search(expand('%:p:h'), g:campo_custom_search_args)<cr>
|
||||
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
" Search in Jai folders
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
" Case insensitive:
|
||||
noremap <leader>sg :call Search(g:campo_jai_path, g:campo_custom_search_args, 1)<cr>
|
||||
noremap <leader>sm :call Search(g:campo_jai_path . '/modules', g:campo_custom_search_args, 1)<cr>
|
||||
noremap <leader>sh :call Search(g:campo_jai_path . '/how_to', g:campo_custom_search_args, 1)<cr>
|
||||
noremap <leader>se :call Search(g:campo_jai_path . '/examples', g:campo_custom_search_args, 1)<cr>
|
||||
" Case sensitive:
|
||||
noremap <leader>ssg :call Search(g:campo_jai_path, g:campo_custom_search_args)<cr>
|
||||
noremap <leader>ssm :call Search(g:campo_jai_path . '/modules', g:campo_custom_search_args)<cr>
|
||||
noremap <leader>ssh :call Search(g:campo_jai_path . '/how_to', g:campo_custom_search_args)<cr>
|
||||
noremap <leader>sse :call Search(g:campo_jai_path . '/examples', g:campo_custom_search_args)<cr>
|
||||
|
||||
" 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 <expr> p (&buftype is# "quickfix" ? "<CR>\|:copen<CR>" : "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
|
||||
|
|
Loading…
Reference in New Issue
Block a user