Search code examples
javajavacneovim

Display :make compiler output for a Java compiled program


I am trying to get NeoVim to compile a simple Java program. The program itself has no ideas but I am not able to exactly output the compiled program.

I have this in my config:

autocmd Filetype java set makeprg=javac\ %            
set errorformat=%A%f:%l:\ %m,%-Z%p^,%-C%.%#           
map <F9> :make<Return>:copen<Return>                  
map <F10> :cprevious<Return>                          
map <F11> :cnext<Return>

I am able to see errors and compile but don't know how to see the output directly in NeoVim. Any way I can do so because I couldn't figure it out nor could find any useful information online.


Solution

  • In Neovim you have 2 options:

    1. suspend the editor (Ctrl+Z), run your program and then return to editor with fg command
    2. use build-in terminal

    In Vim you would also have 3rd option: to use :!, but in Neovim it doesn't support input yet (see issue #1496)

    If you choose option 2 then you simply use command :term java %<

    But you would probably want it in a new window (in Neovim :term takes over the current one).
    In such case you would need to use command: :new term://java %<

    So in conclusion you would need to add to your init.nvim the following:

    autocmd Filetype java nnoremap <F8> :new term://java %<<CR>