0

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

alvinMemphis
  • 185
  • 2
  • 14

1 Answers1

0

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

alvinMemphis
  • 185
  • 2
  • 14
  • On Windows cmd single dot with backslash .\ before program name is not necessary, like in Linux, but possible. Note - it is backslash, not slash. – Dmitry Aug 16 '20 at 16:13
  • By the way. Why do you need one hotkey for build and run? What if program build ends with error? It will then run your old version of executable. Dont think it's what you want. I suggest you to use two separate hotkeys: one for :make command and one to run the batch file, which runs program with desired arguments. – Dmitry Aug 16 '20 at 16:23
  • thanks for the tip. As I'm new to c++ development i will keep that in mind . Although i should point out i have a plugin that checks my syntax before i compile so sofar ive been able to avoid errors in compilation – alvinMemphis Aug 17 '20 at 07:21