mizlan / vim-and-cp

Some helpful bits and pieces for your vimrc
43 stars 11 forks source link

[optional feature] putting the cursor in between `" "` quotation signs #3

Closed j0k4rX closed 3 years ago

j0k4rX commented 3 years ago

When I trigger CompileAndRunWithFile via F5 , the cursor comes after "" sign (in command mode)

I wonder if there's a feature which puts cursor in between quotation signs.

command! -nargs=1 CompileAndRunWithFile call TermWrapper(printf('g++ -std=c++17 %s && ./a.out < %s', expand('%'), <args>))
autocmd FileType cpp nnoremap <F5> :CompileAndRunWithFile ""


PS: in Facebook HackerCup contest, multiple input files with different name is given. If I had the cursor in between "" signs, I could just type the first character, press tab to autocomplete and enter

mizlan commented 3 years ago

I have an even better solution than that :)

diff --git a/cp.vim b/cp.vim
index 5a82aad..2d2f742 100644
--- a/cp.vim
+++ b/cp.vim
@@ -34,7 +34,7 @@ function! TermWrapper(command) abort
 endfunction

 command! -nargs=0 CompileAndRun call TermWrapper(printf('g++ -std=c++11 %s && ./a.out', expand('%')))
-command! -nargs=1 CompileAndRunWithFile call TermWrapper(printf('g++ -std=c++11 %s && ./a.out < %s', expand('%'), <args>))
+command! -nargs=1 -complete=file CompileAndRunWithFile call TermWrapper(printf('g++ -std=c++11 %s && ./a.out < %s', expand('%'), <q-args>))
 autocmd FileType cpp nnoremap <leader>fw :CompileAndRun<CR>

 " For those of you that like to use the default ./a.out

Note the -complete=file and <q-args> instead of args. Let me know if this works.

j0k4rX commented 3 years ago

it works!

mizlan commented 3 years ago

Cool! Can you confirm that tab-completing filenames works as well?

j0k4rX commented 3 years ago

yup.. tab-completing works too