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

Clash 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>
vim c
add a comment |Â
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>
vim c
2
Why not just put the things-that-are-not-for-github into a.gitignorefile?
â thrig
Oct 28 '17 at 17:08
add a comment |Â
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>
vim c
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>
vim c
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.gitignorefile?
â thrig
Oct 28 '17 at 17:08
add a comment |Â
2
Why not just put the things-that-are-not-for-github into a.gitignorefile?
â 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
add a comment |Â
 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.
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.gitignoreis not completely trivial, either.
â Satà  Katsura
Oct 28 '17 at 18:35
add a comment |Â
 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.
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.gitignoreis not completely trivial, either.
â Satà  Katsura
Oct 28 '17 at 18:35
add a comment |Â
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.
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.gitignoreis not completely trivial, either.
â Satà  Katsura
Oct 28 '17 at 18:35
add a comment |Â
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.
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.
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.gitignoreis not completely trivial, either.
â Satà  Katsura
Oct 28 '17 at 18:35
add a comment |Â
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.gitignoreis 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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
Why not just put the things-that-are-not-for-github into a
.gitignorefile?â thrig
Oct 28 '17 at 17:08