Reputation: 2311
So I have my config file .vimrc that has this code which should save the file compile and run it when I press F3. This doesn't work.
map <F3> ^M:w^M:!gcc *.c -g; ./a.out^M
Upvotes: 0
Views: 2249
Reputation: 1587
also it's not necessary to compile *.c
and to run a.out
,
%
and %:r
can be used instead
map <F3> :w<enter>:!gcc % -o %:r;./%:r<enter>
or
map <F3> :w<enter>:!make;./%:r<enter>
Upvotes: 0
Reputation: 40499
The first ^M
is wrong. Change the others to <enter>
:
map <F3> :w<enter>:!gcc *.c -g; ./a.out<enter>
Upvotes: 3
Reputation: 25606
How are you writing ^M
? You can write it by pressing Ctrl+V Enter, or better still, change it to <CR>
which doesn't require any special tricks.
Upvotes: 1
Reputation: 791769
Your keymapping worked for me (assuming you type ^M
as e.g. Ctrl-V Ctrl-M).
If you have a makefile setup (and you probably should) you can just use :make
.
You can set the makeprg
option if you use something other than make
, e.g. cmake
scons
ant
or something else.
Upvotes: 3