Compiling Java code in Vim more efficiently

后端 未结 5 1360
鱼传尺愫
鱼传尺愫 2021-01-30 03:34

I come from an Eclipse background, but I love Vim as a text editor. I\'m currently experimenting with Vim as a Java IDE. Currently I do this to compile:

! javac          


        
5条回答
  •  攒了一身酷
    2021-01-30 04:11

    If you run linux(use bash), here is my setup: to compile and run the class with your main file just include this in your vimrc file

    nnoremap ac :cd %:p:h  :! javac %:t :! java %:t:r
    

    Let me run you through how this code works. When you press the leader key followed by a and c (\ac), the code changes to the directory of the current file that is open in vim(presumably your main). Then, the code compiles yourfile.java (%:t). Finally, the code runs your main file yourfile (%:t:r). < CR > stands for carriage return, which is the equivalent of enter. This approach would work for developing projects with multiple classes as well, because you could add more code to the above line to make it compile other classes before running main.

提交回复
热议问题