Skip to content

Instantly share code, notes, and snippets.

@zorchp
Created August 1, 2024 09:26
Show Gist options
  • Save zorchp/da392e69c8606d32606ef90895f9af8b to your computer and use it in GitHub Desktop.
Save zorchp/da392e69c8606d32606ef90895f9af8b to your computer and use it in GitHub Desktop.
one key to run in vim9
" use quick fix window to run
" use AsyncRun plugin
"for asyncRun
" open quickfix window auto,height
let g:asyncrun_open = 9
" bell when task done.
let g:asyncrun_bell = 1
" set open/close Quickfix window
nnoremap <F9> :call asyncrun#quickfix_toggle(6)<cr>
" Define a function to set key mappings for Python files
function! SetPythonKeymaps()
nnoremap <F8> :w<CR>:AsyncRun python3 %:p <CR>
inoremap <F8> <ESC>:w<CR>:AsyncRun python3 %:p<CR>
endfunction
" Set up an autocmd for the FileType event for Python files
autocmd FileType python call SetPythonKeymaps()
function! SetCKeymaps()
nnoremap <F7> :w<CR>:AsyncRun gcc -Wshadow -Wall -o %:p:r.out %:p <CR>
inoremap <F7> <ESC>:w<CR>:AsyncRun gcc -Wshadow -Wall -o %:p:r.out %:p <CR>
nnoremap <F8> :AsyncRun %:p:r.out <CR>
endfunction
autocmd FileType c call SetCKeymaps()
function! SetCXXKeymaps()
nnoremap <F7> :w<CR>:AsyncRun g++ -Wshadow -Wall -std=c++17 -o %:p:r.out %:p <CR>
inoremap <F7> <ESC>:w<CR>:AsyncRun g++ -Wshadow -Wall -std=c++17 -o %:p:r.out %:p <CR>
nnoremap <F8> :AsyncRun %:p:r.out <CR>
endfunction
autocmd FileType cpp call SetCXXKeymaps()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment