How can I Create single vim regular expression map to compile and run c++ program in windows

108 Views Asked by At

in linux i used something like

autocmd FileType cpp nmap <buffer> <F5> :w<bar>!g++ -o %:r % && ./%:r<CR>

but since windows uses back slashes i thought i should try something like

autocmd FileType cpp nmap <buffer> <F5> :w<bar>!g++ -o %:r % && .\\%:r<CR>

or

autocmd FileType cpp nmap <buffer> <F5> :w<bar>!g++ -o %:r % && ./\%:r<CR>

but none of them seem to give desired results .can someone who understands vim scripts better help me figure this out . I've also tried other combinations but nothing seems to work .rather than gamble some more thought I might ask

1

There are 1 best solutions below

3
alvinMemphis On BEST ANSWER

so the solution i ended up going with, was to not put any preceding backslashes . See the idea was to run a command terminal command like .\hello for program called hello i assumed its the linux equivalent of ./hello for any executable. turns out a hello.exe file gets created when one compiles so the solution is just to call hello.exe with by just typing hello in terminal

therefore my final command was with no slashes at all

autocmd FileType cpp nmap <buffer> <F5> :w<bar>!g++ -o %:r % && %:r<CR>

as for a regular expression that creates the previous desired result. Thats still a mystery to me .cheers