Your g++
command contains -o %:r
; the -o
flag for g++
sets the output filename, the %
expands to the current buffer name in the Vim commandline, and :r
is a modifier to remove any file extension. So for file.cpp
it would be file
. I assume the .exe
part is added by g++ automatically on Windows.
To use a different path, well, specify a different path in there 😅 :help filename-modifiers
contains a list of all modifiers you can use with %
; and you can test this with expand()
or :!echo
(don't forget the !
! I prefer expand()
because it's so easy to forget):
:echo expand('%')
file.cpp
:echo expand('%:r')
file
I don't know what makes sense for you or your projects, but to store files in a .obj
directory you could for example use:
!g++ -std=c++14 % -o .obj/%:r
The downside of this is that it won't work if the .obj
directory doesn't exist yet, so you may want to add that to your keybind:
nnoremap <F9> :w <bar> call mkdir('.obj', 'p') <bar> !g++ -std=c++14 % -o %:r -Wl,--stack,268435456<CR>
With the 'p'
as the second argument to mkdir()
you won't get an error if the directory doesn't exist.
You can also store something in your user profile, temp directory, or some other global location on your system:
!g++ -std=c++14 % -o $TEMPDIR/%:r
I think $TEMPDIR
will expand to the temporary directory on Windows, but I'm not 100% sure so you may want to verify this; but the idea should be clear.