0

In Vim I enter the command :w | make. My Makefile looks like this:

all:
    g++ -o main main.cpp
    ./main

main.cpp looks like this:

#include <iostream>
using namespace std;

int main(){
    cout << "Hello world!";
}

Vim output says:

"main.cpp" 6L, 88C written
:!make 2>&1| tee /tmp/ve16mwu/0
g++ -o main maincpp
./main
(1 of 3): g++ -o main main.cpp
Press ENTER or type command to continue_

Now after I quit Vim and run the executable: $ ./main then the output shows up fine in the terminal.

If I put add a newline \n to the line like this: "Hello world!\n" then it shows in Vim's output just fine.

Apparently, in Vim, the output won't show your last line of text if it doesn't have \n on the end. Is there a workaround for this?

adabo
  • 87
  • 7
  • 2
    You forgot to flush. Hopefully you remembered to wipe though. – Captain Obvlious Aug 07 '15 at 20:51
  • Hah, ok. You'll have to forgive me. What is and how do I flush? – adabo Aug 07 '15 at 20:55
  • @Slyps **no**. `\n` [does not flush](http://stackoverflow.com/questions/213907/c-stdendl-vs-n) – scohe001 Aug 07 '15 at 20:58
  • My apologies. Always assumed it does. I'm ever using `\n` in console context. I may accept my death penalty now – Slyps Aug 07 '15 at 21:02
  • I apologize. I left out that I actually write this in vim command:`w | make` – adabo Aug 07 '15 at 21:03
  • This worked just fine for me (after I fixed the indentation in the Makefile) with vim 7.4 on Ubuntu 14.04 and g++ 4.8.2. – Gene Aug 08 '15 at 00:06
  • @Gene I'm not sure what worked for you. Are you referring to the configuration in my post? If so, please help me! haha What part of the indentation should I fix? – adabo Aug 08 '15 at 02:45
  • The indentation was wrong when copying and pasting the makefile from here. I got a completely different error. -- Do you have a custom .vimrc? If so can you include it in your post? – Gene Aug 08 '15 at 02:50
  • Thanks, Gene. Here are the files I'm using in this post (I hope 7z is ok): https://drive.google.com/file/d/0B1ObkUHX0n2YVXo1R0g3bU9Pdm8/view?usp=sharing – adabo Aug 08 '15 at 05:21
  • I noticed I forgot return 0; but that wasn't the fix. I found the "endl" function to flush. – adabo Aug 08 '15 at 15:51

1 Answers1

0

endl From cplusplus.com:

Insert newline and flush

Inserts a new-line character and flushes the stream.

So the code would look like this:

#include <iostream>
using namespace std;

int main(){
    cout << "Hello world!" << endl;
    return 0;
}
adabo
  • 87
  • 7