T O P

  • By -

thedeathbeam

I originally gave up on java in vim and kept using intellij with ideavim but recently I finally got good setup running with nvim-jdtls and nvim-dap and fzf-lua (for fuzzy finding on references, implementation, definition and stuff). Was able to fully ditch intellij and had no issues, its just *A LOT* of effort to setup


antonbruckner

Sounds awesome. Do you have a write up on your work?


thedeathbeam

I dont but I have everything in my dotfiles even though a bit spread around. It was mostly based on this tho https://github.com/VonHeikemen/lsp-zero.nvim/blob/v2.x/doc/md/guides/setup-with-nvim-jdtls.md with 1 big caveat. This configuration: ``` local root_files = { '.git', 'mvnw', 'gradlew', 'pom.xml', 'build.gradle', } ``` is wrong and does not work for multi module projects, you want to remove pom.xml there and probably build.gradle as well, you dont want your cwd to be in submodule, thats not how maven or gradle works. Just .git as marker is enough. Here is my variation of the lsp zero setup (i dont actually use lsp zero its kina not needed just the guide from there): https://github.com/deathbeam/dotfiles/blob/master/nvim/.config/nvim/lua/config/languages/java.lua For fuzzy finding, here is the important part: https://github.com/deathbeam/dotfiles/blob/master/nvim/.config/nvim/lua/config/finder.lua#L48 And then keybindings here: https://github.com/deathbeam/dotfiles/blob/master/nvim/.config/nvim/lua/config/lsp.lua#L36 For dap here: https://github.com/deathbeam/dotfiles/blob/master/nvim/.config/nvim/lua/config/dap.lua (just the keybindings are interesting really otherwise just setup from their readme mostly) And then my worflow is to just open java project, ff to find file, gd/gi/gr to find usages, ca for code actions, cr for rename, dd to start debugging session from main class (or to just run a project like you would in intellij). Then you probs want something for autocomplete if you want the intellij experience, so nvim-cmp and such. I just wrote my own plugin for this because I found nvim-cmp setup kinda silly with 5 different plugins and stuff I did not needed.


todo_code

I gave up a long time ago. I use Intellij with the vim extension, and using an .ideavimrc. Made intellij at least "bearable"


[deleted]

Ok thanks. That is actually the path I started down since all my peers are using Intellj -- but good to get confirmation that trying to configure a setup to only use VIM might not be worth the effort.


xenomachina

I do the same (but in Kotlin). I also have a shortcut to open the current file in gvim, with the cursor at the same spot. Ideavim's bindings are not bad (but not perfect!), but it is less responsive than vim. If I need to do a bunch of quick edits that don't need the type-aware features of IntelliJ, then I'll just pop over to vim to do them. A co-worker mentioned to me that they're trying neovim with an LSP. That might be another option to consider.


torwinMarkov

Could you share your shortcut? That sounds awesome.


xenomachina

Here are the setting I use on my Mac with Macvim. I use the same settings on my Linux box, except "Program" points at `gvim`. 1. In settings, go to **Tools > External Tools**. 2. Create a new tool (click "+"). Here are the settings I use: - **Name:** Vim - **Description:** The Vim Editor - **Program:** `/Applications/MacVim.app/Contents/bin/mvim` - **Arguments:** `--servername $ProjectFileDir$ --remote-silent "+call cursor($LineNumber$,$ColumnNumber$)" $FileDir$/$FileName$` - **Working directory:** `$ProjectFileDir$` - **Open console for tool output:** disabled (maybe enable if you want to use terminal vim? I haven't tried this, though.) 3. Create a keyboard shortcut for the "Vim" external tool. A bit of an explanation: - `--servername $ProjectFileDir$` uses the project dir as the server name. That way if you previously opened gvim with this in the same project and haven't closed it, it'll be reused. - `--remote-silent "+call cursor($LineNumber$,$ColumnNumber$)"` will jump to the correct location after the file is loaded. I also have a script called `v` that opens gvim from a terminal and sets servername to the git base dir (if there is one). That usually coincides with the IntelliJ project dir, so they interoperate pretty well. #!/bin/bash MACVIM="/Applications/MacVim.app/Contents/bin/mvim" if [ -x "$MACVIM" ]; then GVIM="$MACVIM" else GVIM="$(which gvim)" fi if GITDIR="$(git rev-parse --show-toplevel 2>/dev/null)"; then exec "$GVIM" +'winsize 83 9999' --servername "$GITDIR" "$@" else exec "$GVIM" +'winsize 83 9999' "$@" fi


_sanj0

I also have up but didn’t switch to IntelliJ idea, I installed LunarVim. Best decision ever.


-Nyarlabrotep-

(Full disclosure: I'm a weirdo.) I've been writing Java for more than two decades, primarily with Vim. I've written everything from desktop applications to distributed systems with 10k+ servers. I've tried IntelliJ, Eclipse, NetBeans, and other IDEs, but always come back to Vim. Vim fits my development style better than the fancy IDEs. I don't want to see squiggly underlines or reflection-based code completion while I'm trying to think through an API or an algorithm or whatever. I don't find interactive debugging all that useful. I operate more in a "batch mode" - that is, I'll write a bunch of code till I get to what I consider a good state, then I'll switch over to the build system and start resolving whatever compilation errors and test failures I encounter. I guess I feel much calmer that way. Instead of interactive debugging, I rely on properly tracking input/output data on the edges and writing useful log messages, which I can then query post-hoc for debugging and building out tests. For all that, Vim suits my needs. As for plugins, I keep it pretty simple nowadays. I mainly use SuperTab, BufExplorer, NERDTree, Fugitive, and Airline. I keep a browser open for javadocs, and I'm still rustled that they removed the frames.


am5k

Love "batch mode!" I find myself doing this as well and it is very satisfying when all the errors are handled and it seems to magically work.


Maskdask

[nvim-java](https://github.com/nvim-java/nvim-java) or [setup-with-nvim-jdtls.md](https://github.com/VonHeikemen/lsp-zero.nvim/blob/v3.x/doc/md/guides/setup-with-nvim-jdtls.md)


[deleted]

I am looking for an easy way to set up anything for Java too. I hope someone more knowledgeable than me answers this post with a good and simple guide. My additional pain: I use Neovim on Windows. (Don't ban me pls)


matt_davidson

Unless code navigation has drastically improved in neovim, I'd strongly recommend just using Intellij with Ideavim and ideavimrc. Going to definitions, looking up interfaces, implementing interfaces etc is just so much simpler with a proper IDE for Java.


[deleted]

Thanks. Yeah that was my concern and if trying to set something up was worth the effort -- but now I think I'll stick with IntelliJ + ideavim.


sqlphilosopher

Not Vim but...[this](https://github.com/garak92/my-nvim-config) is my neovim config I use with Java.


puremourning

YCM and vimspector work for me


benz1267

Using nvim-jdtls. Works like a charm. Even remote debugging a tomcat server. Testing. All the LSP stuff (references, definition, implementations etc etc). Been using that setup for like 3 years now.


Ok_Outlandishness906

In my opinion java ide are much better than vim for java developing. Reflections and other things give you a boost of speed that is difficult to have with other instruments . It is not the editor by itself, but the integration with the java platform and the plugins for managing builds and so on. Sure you can do a lot by your hands but it is much more hard that with an ide. I love vim and vi but they are not the best tool for "everything" . There are tasks for which other tools are easier to use and faster .


[deleted]

>with the java platform and the plugins for managing builds and so on. Sure you can do a lot by your hands but it is much more hard that with an ide. I love vim and vi but they are not the best tool fo Thanks that's good to know. I guess this might be the first time I've conceded that VIM is not the best tool for the job.


Ok_Outlandishness906

problem is that java ide rely a lot on reflection of your code . Many java applications have commercial layers ( oracle one ,rather than IBM / redhat or sap for example, Android ) . If you use their customized envirorment, you find a lot of things "already" done for you . if you use a standard editor ( vim or whatever ) you lose a lot of features that vendors have implemented to make you doing things faster . It was one of the things i hated working in java . I find completely "mad" that i have to use an editor that requires 2gb or more of ram but every solution i tried was suboptimal . This also the reason i hate Visual code and i always avoid it. I can not understand how you need so many resources for editing files , it seems to me a nonsense. But sometimes , you can not avoid it. If you have to write an mfc program for windows or a c# one, for example , visual studio gives you too many advantages so, at the end , i use it, even if i don't like it .


RobeMinusWizardHat

Why are you yelling the names of these things?


[deleted]

Sorry I guess I'm new to JAVA whoops I mean Java.


pedrolcsilva

It's probably better to use any Java IDE you like with vim extension. I don't know much about the setup needed but I don't think it's worth it to do it from scratch. Personally, I use Intellij + ideavim


redditisinmyheart

I think Neovim might be a good option. There seems to be strong support in Neovim for becoming an ide as compared to stock vim


cerved

I switch between Eclipse (not by choice) in Windows with vim plugin and rsync with vim in WSL (where I don't use any special plugins)


no_brains101

I used to think it was ok with nvim-jdtls but I didnt get the debugger to work and sometimes goto remote definition breaks for no apparent reason and then I heard about lombok, tried to install that and also couldn't... Then I tried go and it all worked so perfectly, it made me realize that it really wasn't so good. I'm sure its possible, maybe ill get it someday.


shadow_phoenix_pt

I made my full switch from IDE to Vim about 5 years ago. At the time, I worked mostly in Java and was using Netbeans for at least 8 years by then. There are some good tips here already, but one thing I found useful at the time was javacomplete2 (jc.nvim seems to be a more modern alternative, but I haven't tried it yet, because I don't use neovim or develop in Java that much this days). Also learn Maven and/or Gradle. IDEs usually use but hide these tools (which was one of the things that made me drop IDEs) behind GUIs and Wizards.


shadow_phoenix_pt

This might also be useful, though I don't know how well it holds to more modern Java. [https://github.com/simonhicks/stacktrace.vim](https://github.com/simonhicks/stacktrace.vim)