How do I compile my C program within Vim, but not to the current directory?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












So the command I've been using in Vim for a while is:



map <F10> :w<CR> :!clear; make %<<CR> :!./%<<CR>


Which takes the current name of the file, compiles and then runs it. However this pollutes my directory and when I want to upload them to github it makes it so that I have to delete all the files without extensions before I upload.



What I want to do is compile them all to a bin directory, so I tried to modify my command to the following:



map <F10> :w<CR> :!clear; make -C bin %<<CR> :!./bin/%<<CR>


I saw that the -C command changes the directory but this doesn't work as I get the error:



*** no rule to make target '17'. Stop. 


What can I do to make this command work correctly?



map <F10> :w<CR> :!clear; make -C bin %<<CR> :!./bin/%<<CR>






share|improve this question


















  • 2




    Why not just put the things-that-are-not-for-github into a .gitignore file?
    – thrig
    Oct 28 '17 at 17:08














up vote
2
down vote

favorite












So the command I've been using in Vim for a while is:



map <F10> :w<CR> :!clear; make %<<CR> :!./%<<CR>


Which takes the current name of the file, compiles and then runs it. However this pollutes my directory and when I want to upload them to github it makes it so that I have to delete all the files without extensions before I upload.



What I want to do is compile them all to a bin directory, so I tried to modify my command to the following:



map <F10> :w<CR> :!clear; make -C bin %<<CR> :!./bin/%<<CR>


I saw that the -C command changes the directory but this doesn't work as I get the error:



*** no rule to make target '17'. Stop. 


What can I do to make this command work correctly?



map <F10> :w<CR> :!clear; make -C bin %<<CR> :!./bin/%<<CR>






share|improve this question


















  • 2




    Why not just put the things-that-are-not-for-github into a .gitignore file?
    – thrig
    Oct 28 '17 at 17:08












up vote
2
down vote

favorite









up vote
2
down vote

favorite











So the command I've been using in Vim for a while is:



map <F10> :w<CR> :!clear; make %<<CR> :!./%<<CR>


Which takes the current name of the file, compiles and then runs it. However this pollutes my directory and when I want to upload them to github it makes it so that I have to delete all the files without extensions before I upload.



What I want to do is compile them all to a bin directory, so I tried to modify my command to the following:



map <F10> :w<CR> :!clear; make -C bin %<<CR> :!./bin/%<<CR>


I saw that the -C command changes the directory but this doesn't work as I get the error:



*** no rule to make target '17'. Stop. 


What can I do to make this command work correctly?



map <F10> :w<CR> :!clear; make -C bin %<<CR> :!./bin/%<<CR>






share|improve this question














So the command I've been using in Vim for a while is:



map <F10> :w<CR> :!clear; make %<<CR> :!./%<<CR>


Which takes the current name of the file, compiles and then runs it. However this pollutes my directory and when I want to upload them to github it makes it so that I have to delete all the files without extensions before I upload.



What I want to do is compile them all to a bin directory, so I tried to modify my command to the following:



map <F10> :w<CR> :!clear; make -C bin %<<CR> :!./bin/%<<CR>


I saw that the -C command changes the directory but this doesn't work as I get the error:



*** no rule to make target '17'. Stop. 


What can I do to make this command work correctly?



map <F10> :w<CR> :!clear; make -C bin %<<CR> :!./bin/%<<CR>








share|improve this question













share|improve this question




share|improve this question








edited Oct 28 '17 at 20:09









Ortomala Lokni

2,07511240




2,07511240










asked Oct 28 '17 at 16:57









James Liu

161




161







  • 2




    Why not just put the things-that-are-not-for-github into a .gitignore file?
    – thrig
    Oct 28 '17 at 17:08












  • 2




    Why not just put the things-that-are-not-for-github into a .gitignore file?
    – thrig
    Oct 28 '17 at 17:08







2




2




Why not just put the things-that-are-not-for-github into a .gitignore file?
– thrig
Oct 28 '17 at 17:08




Why not just put the things-that-are-not-for-github into a .gitignore file?
– thrig
Oct 28 '17 at 17:08










1 Answer
1






active

oldest

votes

















up vote
1
down vote













You're confusing Vim's command :make with the OS executable make(1). When you type make at Vim's command line you're running Vim's :make command. One of the effects of this is to run the OS command defined by Vim's option makeprg.



Now, makeprg happens to have the value make by default, so the OS command make(1) also gets run. But Vim's command :make doesn't take options, so passing -C bin on Vim's command line doesn't translate to make -C bin being run. If you want to change the OS command that gets run you need to do something like this:



let &makeprg = 'make -C /path/to/bin'


Then running :make in Vim will run the OS command make -C /path/to/bin.



However, as pointed out in comments, the better way to deal with this is to avoid the problem in the first place, and add all irrelevant files to .gitignore. Otherwise sooner or later you'll still commit object files and what not to your Git repository.






share|improve this answer




















  • Thanks, the reason I don't want to use a git ignore is that I'm going through a book and doing lots of exercises, so I'd have to do something like: stackoverflow.com/questions/19023550/… which seems messy to me. Seems more sensible to compile all files to a specfic directory and then ignore that.
    – James Liu
    Oct 28 '17 at 18:33










  • Which is why writing a useful .gitignore is not completely trivial, either.
    – Satō Katsura
    Oct 28 '17 at 18:35










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f401098%2fhow-do-i-compile-my-c-program-within-vim-but-not-to-the-current-directory%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













You're confusing Vim's command :make with the OS executable make(1). When you type make at Vim's command line you're running Vim's :make command. One of the effects of this is to run the OS command defined by Vim's option makeprg.



Now, makeprg happens to have the value make by default, so the OS command make(1) also gets run. But Vim's command :make doesn't take options, so passing -C bin on Vim's command line doesn't translate to make -C bin being run. If you want to change the OS command that gets run you need to do something like this:



let &makeprg = 'make -C /path/to/bin'


Then running :make in Vim will run the OS command make -C /path/to/bin.



However, as pointed out in comments, the better way to deal with this is to avoid the problem in the first place, and add all irrelevant files to .gitignore. Otherwise sooner or later you'll still commit object files and what not to your Git repository.






share|improve this answer




















  • Thanks, the reason I don't want to use a git ignore is that I'm going through a book and doing lots of exercises, so I'd have to do something like: stackoverflow.com/questions/19023550/… which seems messy to me. Seems more sensible to compile all files to a specfic directory and then ignore that.
    – James Liu
    Oct 28 '17 at 18:33










  • Which is why writing a useful .gitignore is not completely trivial, either.
    – Satō Katsura
    Oct 28 '17 at 18:35














up vote
1
down vote













You're confusing Vim's command :make with the OS executable make(1). When you type make at Vim's command line you're running Vim's :make command. One of the effects of this is to run the OS command defined by Vim's option makeprg.



Now, makeprg happens to have the value make by default, so the OS command make(1) also gets run. But Vim's command :make doesn't take options, so passing -C bin on Vim's command line doesn't translate to make -C bin being run. If you want to change the OS command that gets run you need to do something like this:



let &makeprg = 'make -C /path/to/bin'


Then running :make in Vim will run the OS command make -C /path/to/bin.



However, as pointed out in comments, the better way to deal with this is to avoid the problem in the first place, and add all irrelevant files to .gitignore. Otherwise sooner or later you'll still commit object files and what not to your Git repository.






share|improve this answer




















  • Thanks, the reason I don't want to use a git ignore is that I'm going through a book and doing lots of exercises, so I'd have to do something like: stackoverflow.com/questions/19023550/… which seems messy to me. Seems more sensible to compile all files to a specfic directory and then ignore that.
    – James Liu
    Oct 28 '17 at 18:33










  • Which is why writing a useful .gitignore is not completely trivial, either.
    – Satō Katsura
    Oct 28 '17 at 18:35












up vote
1
down vote










up vote
1
down vote









You're confusing Vim's command :make with the OS executable make(1). When you type make at Vim's command line you're running Vim's :make command. One of the effects of this is to run the OS command defined by Vim's option makeprg.



Now, makeprg happens to have the value make by default, so the OS command make(1) also gets run. But Vim's command :make doesn't take options, so passing -C bin on Vim's command line doesn't translate to make -C bin being run. If you want to change the OS command that gets run you need to do something like this:



let &makeprg = 'make -C /path/to/bin'


Then running :make in Vim will run the OS command make -C /path/to/bin.



However, as pointed out in comments, the better way to deal with this is to avoid the problem in the first place, and add all irrelevant files to .gitignore. Otherwise sooner or later you'll still commit object files and what not to your Git repository.






share|improve this answer












You're confusing Vim's command :make with the OS executable make(1). When you type make at Vim's command line you're running Vim's :make command. One of the effects of this is to run the OS command defined by Vim's option makeprg.



Now, makeprg happens to have the value make by default, so the OS command make(1) also gets run. But Vim's command :make doesn't take options, so passing -C bin on Vim's command line doesn't translate to make -C bin being run. If you want to change the OS command that gets run you need to do something like this:



let &makeprg = 'make -C /path/to/bin'


Then running :make in Vim will run the OS command make -C /path/to/bin.



However, as pointed out in comments, the better way to deal with this is to avoid the problem in the first place, and add all irrelevant files to .gitignore. Otherwise sooner or later you'll still commit object files and what not to your Git repository.







share|improve this answer












share|improve this answer



share|improve this answer










answered Oct 28 '17 at 18:28









Satō Katsura

10.7k11533




10.7k11533











  • Thanks, the reason I don't want to use a git ignore is that I'm going through a book and doing lots of exercises, so I'd have to do something like: stackoverflow.com/questions/19023550/… which seems messy to me. Seems more sensible to compile all files to a specfic directory and then ignore that.
    – James Liu
    Oct 28 '17 at 18:33










  • Which is why writing a useful .gitignore is not completely trivial, either.
    – Satō Katsura
    Oct 28 '17 at 18:35
















  • Thanks, the reason I don't want to use a git ignore is that I'm going through a book and doing lots of exercises, so I'd have to do something like: stackoverflow.com/questions/19023550/… which seems messy to me. Seems more sensible to compile all files to a specfic directory and then ignore that.
    – James Liu
    Oct 28 '17 at 18:33










  • Which is why writing a useful .gitignore is not completely trivial, either.
    – Satō Katsura
    Oct 28 '17 at 18:35















Thanks, the reason I don't want to use a git ignore is that I'm going through a book and doing lots of exercises, so I'd have to do something like: stackoverflow.com/questions/19023550/… which seems messy to me. Seems more sensible to compile all files to a specfic directory and then ignore that.
– James Liu
Oct 28 '17 at 18:33




Thanks, the reason I don't want to use a git ignore is that I'm going through a book and doing lots of exercises, so I'd have to do something like: stackoverflow.com/questions/19023550/… which seems messy to me. Seems more sensible to compile all files to a specfic directory and then ignore that.
– James Liu
Oct 28 '17 at 18:33












Which is why writing a useful .gitignore is not completely trivial, either.
– Satō Katsura
Oct 28 '17 at 18:35




Which is why writing a useful .gitignore is not completely trivial, either.
– Satō Katsura
Oct 28 '17 at 18:35

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f401098%2fhow-do-i-compile-my-c-program-within-vim-but-not-to-the-current-directory%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay