From f35f62e9a53fb6e008f5e47eec459187abd7d88a Mon Sep 17 00:00:00 2001 From: Some Person Date: Mon, 8 Feb 2021 14:50:20 -0600 Subject: [PATCH] Fix the wrong makeprg cmd --- ch19_compile.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ch19_compile.md b/ch19_compile.md index 57c55f6..aae3a16 100644 --- a/ch19_compile.md +++ b/ch19_compile.md @@ -104,19 +104,19 @@ makeprg=make The default `:make` command is the `make` external command. To change the `:make` command to execute `g++ {your-file-name}` each time you run it, run: ``` -:set makeprg=g++\\ % +:set makeprg=g++\ % ``` -The `\\` is to escape the space after `g++` (you need to escape the escape). The `%` symbol in Vim represents the current file. The command `g++\\ %` is equivalent to running `g++ hello.cpp`. +The `\` is to escape the space after `g++`. The `%` symbol in Vim represents the current file. The command `g++\\ %` is equivalent to running `g++ hello.cpp`. Go to `./hello.cpp` then run `:make`. Vim compiles `hello.cpp` and creates `a.out` because you didn't specify the output. Let's refactor it so it will name the compiled output with the name of the original file minus the extension. Run or add this to vimrc: ``` -set makeprg=g++\\ %\\ -o\\ %< +set makeprg=g++\ %\ -o\ %< ``` The breakdown: -- `g++\\ %` is the same as above. It is equivalent to running `g++ `. +- `g++\ %` is the same as above. It is equivalent to running `g++ `. - `-o` is the output option. - `%<` in Vim represents the current file name without an extension (`hello.cpp` becomes `hello`).