1

I have a simple makefile as follow:

all: A.cpp
    g++ -o A.exe A.cpp 
    .\A

In A.cpp,

#include <iostream>
using namespace std;
int main() {
    cout << "Hello World!\n" << '\n';
    return 0;
}

In Neovim, if I run :!make, I get what I expect:

:!make
g++ -o A.exe A.cpp
.\A
Hello World!

But :make gives

:!make  >C:\Users\yeung\AppData\Local\Temp\nvimHfW5tI\3 2>&1

(1 of 5): <ff><fe>g

Although it also compiled A.cpp but the output is not seen. How to make :make to output "Hello World"?

Another question is what should I do so that Neovim can take input from stdin when I run :make?

My init.vim

call plug#begin(stdpath('data') . '/plugged')

Plug 'Valloric/YouCompleteMe'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'Raimondi/delimitMate'
Plug 'preservim/nerdtree'
"Plug 'vim-scripts/c.vim'

call plug#end()

set number
set tabstop=4
set shiftwidth=4
set expandtab
set termguicolors
set mouse=a
set foldmethod=syntax
set nofoldenable

let g:airline_powerline_fonts = 1
let g:ycm_autoclose_preview_window_after_completion = 1
let g:delimitMate_expand_cr = 1 
let mapleader = "\<Space>"

"enable powershell in nvim
let &shell = has('win32') ? 'powershell' : 'pwsh'
set shellquote= shellxquote= 
set shellcmdflag=-NoLogo\ -NoProfile\ -ExecutionPolicy\ RemoteSigned\ -Command
set shellredir=\|\ Out-File\ -Encoding\ UTF8


inoremap <C-Z> <C-O>u

nnoremap <C-Z> u
nnoremap <Leader>o o<Esc>
nnoremap <Leader>O O<Esc>
nnoremap <C-J> i<CR><Esc>  
nnoremap <F9> :YcmCompleter FixIt<CR>
nnoremap <F10> :w<CR>:!make %<<CR>
nnoremap <leader>to :YcmCompleter GoToDeclaration<CR>
nnoremap <leader>n :NERDTreeFocus<CR>
nnoremap <C-t> :NERDTreeToggle<CR>
nnoremap <C-f> :NERDTreeFind<CR>

autocmd FileType makefile set noexpandtab.
9
  • 1
    Welcome to Vi and Vim! The <ff><fe> sequence is the Unicode BOM, commonly used on Windows, so this suggests a possible encoding issue... Do you set any of the encoding options explicitly in your vimrc? (Maybe try under vim --clean to see if you can still reproduce the issue.)
    – filbranden
    Commented Jan 7, 2021 at 15:51
  • 1
    Couldn't it be an issue with 'shellquote' default value? Ages ago I had to change them to the following: github.com/LucHermitte/vim-system-tools/blob/master/plugin/… So far, it's still working, with gvim under Windows. Commented Jan 7, 2021 at 15:55
  • @filbranden I am using nvim and nvim --clean displays correctly. How do I get it work in normal nvim?
    – Y.T.
    Commented Jan 7, 2021 at 16:01
  • 1
    @filbranden setting 'shellpipe' works like a charm!
    – Y.T.
    Commented Jan 8, 2021 at 0:07
  • 1
    yes adding it works
    – Y.T.
    Commented Jan 8, 2021 at 2:08

2 Answers 2

3

This happens because a 'shellpipe' of the default of > (which is the default on Windows) doesn't really work on Powershell. It seems to have it produce a file that uses UTF-16 encoding and then NeoVim has trouble parsing the Unicode BOM character at the beginning of it.

The 'shellredir' setting gives us a good clue of how to solve it... So just setting 'shellpipe' to the same should fix it:

set shellpipe=\|\ Out-File\ -Encoding\ UTF8

It seems that the NeoVim recommendations for 'shellpipe' when using Powershell are incorrect, so I opened Issue #13713 to report this documentation problem to the NeoVim project.

1

When you run your code with :make, the result is put into the quickfix list, you can open it with :cope

See help :make See help quickfix

You can also make your own command that show immediatelly your results:

command! -nargs=* Make :make <args> | cope

You just have to use :Make instead of :make to run your programm and be prompted to the quickfix list.

See :help command

1
  • This is not the problem. I still see the same thing "<ff><fe>g" in my quickfix list. But thanks for your help.
    – Y.T.
    Commented Jan 7, 2021 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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