2

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>
  • 2
    Why not just put the things-that-are-not-for-github into a .gitignore file? – thrig Oct 28 '17 at 17:08
1

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 .gitignore is not completely trivial, either. – Satō Katsura Oct 28 '17 at 18:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.