Currently, after writing a scala program I have to invoke the three commands:
- File save
- compile the file
- run the program
How to assign a shortcut for steps 2 and 3 above?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityCurrently, after writing a scala program I have to invoke the three commands:
How to assign a shortcut for steps 2 and 3 above?
If your command to compile is: :scalac -classpath . %
and your command to run is :terminal scala -classpath . %:r
to associate them to the shortcuts F7 and Ctrl-F5 respectively you could add the following lines in your init.vim
file:
nnoremap <F7> :scalac -classpath . %<CR>
nnoremap <C-F5> :terminal scala -classpath . %:r<CR>
You could also configure Vim to associate :make
to scalac that allow you to get the compiler error in the Neovim Quicklist (and to make use of the autowrite
feature)
If you add the following lines to ~/.config/nvim/ftplugin/scala.vim
" Make that calling make automatically save the change in your buffers
setlocal autowrite
setlocal makeprg=scalac\ -classpath\ .
setlocal errorformat=%A--\ [%t%n]\ %m:%f:%l:%c\ -%#,%C%\\d%#\ %#\|%.%#,%C%\\d%\\+\ error%.%#
I had to transform the scalac
output with sed
(| sed s/\x1B\[[0-9]\+m//g
) to remove the color escape characters for the errorformat
to work.
And the following line in your init.vim
:
nnoremap <F7> :make %<CR>
nnoremap <C-F5> :terminal scala -classpath . %:r<CR>