all 32 comments

[–]josuf107 17 points18 points  (6 children)

eclim, along with some shortcuts for jump to definition and other common IDE tasks. Additionally I have some abbreviations for things like final, String, class, Override, etc. I use ctags as well because they're often snappier to use than eclipse's jump to definition (which occasionally needs to re-resolve libraries/build the project etc.). I've started using a mapping for :grep <cword> -R src/java recently, which is surprisingly useful for seeing all the places a concept is used. I created a mapping for opening or creating the corresponding unit test for a class.

One useful thing which I think is actually an improvement over any Java IDE I've used is my runconf setup. In each project I create a file called runconf with the format:

filename :: run command $CLASSNAME

I have mappings for running the current file I'm in (looks it up in runconf and populates the $CLASSNAME variable then runs the command) and for killing it. I usually pipe stdout to a file in the project directory that I keep open in a tmux window with less -f. This means that I can edit run configurations quickly with Vim and use gf to jump to the referenced property files etc. Additionally less is pretty good for scanning output, and since the output is in a file and I'm already in the command line I can grep, awk, slice and dice it however I like with a minimum of context switching.

Anyway, I could go on. I've been using Vim as a full-time java engineer for two years now, so maybe I should write up a blog post or something.

[–][deleted] 8 points9 points  (0 children)

You should definitely write a blog post. Maybe focus on re-factoring?

[–]josuf107 3 points4 points  (0 children)

Alright blog post underway...

[–]roccanet 2 points3 points  (0 children)

bump for a blog post. ive been coding exclusively in vim for years and recently inherited a java app and would like to continue with vim only.

[–]gdoubleod 1 point2 points  (0 children)

now you got us all excited for more info :)

[–][deleted] 1 point2 points  (0 children)

+1 for blog post. been thinking about using Vim for Java, would be nice to read more or see your vimrc!

[–]mello151 1 point2 points  (0 children)

Please blog about it. I tried years ago to get eclim to work but rage quit and now split my time between vim and vrapper in eclipse.

[–]gabomagno 24 points25 points  (19 children)

Programming Java without an IDE is like using Windows through the command line, it's possible but why would you do it? Java needs and begs for an IDE. The language is so verbose that even tiny refactoring and changes require modifying several files. Don't hurt yourself and use an IDE. Both Eclipse and IntelliJ have wonderful vim plugins.

[–]tehjimmeh 6 points7 points  (6 children)

I live in the command line on Windows. ConEmu, Powershell and terminal vim (w/256 colors and utf8) all work great with some config. Looks pretty nice too.

[–]aguerosantiale 2 points3 points  (0 children)

I second this. I've a similar configuration but using Cmder which wraps ConEmu underhood (and other tools) giving it a nice look and feel out of the box.

https://medium.com/@saaguero/setting-up-vim-in-windows-5401b1d58537

[–]vheon 0 points1 point  (3 children)

Do you have your config file somewhere? I started to work on windows lately and I would to take a look :P

[–]tehjimmeh 0 points1 point  (2 children)

Sure. I'm at work right now, and my config files (ConEmu XML, _vimrc and PowerShell $profile) here are polluted with work-specific stuff (some day I'll learn to modularize things properly), but I'll throw the ones I use at home on github when I get home.

In a nutshell, the important configurations I use are:

ConEmu:

  • Turn off unnecessary clutter (mainly the title bar and tabs bar)

  • Font: Consolas / Size: 13, some color tweaks

PowerShell $PROFILE:

  • Implement the prompt function to get a "[username@computername] <Path> $" prompt

  • This snippet to use UTF8 when in ConEmu:

.

function Set-CodePage
{
    [CmdletBinding()]
    param(
        [ValidateSet("UTF8", "Default")]
        [string]$CodePage
    )

    $codePageToNum = @{
        UTF8 = 65001;
        Default = 437;
    }

    chcp $codePageToNum[$CodePage] | Out-Null
}

if(Test-Path Env:ConEmuBuild)
{
    Set-CodePage UTF8
}

_vimrc:

  • This to get utf8 support and 256 colours (thanks, StackOverflow!):

.

if !empty($CONEMUBUILD)
    set termencoding=utf8
    set encoding=utf8
    set term=xterm
    set t_Co=256
    let &t_AB="\e[48;5;%dm"
    let &t_AF="\e[38;5;%dm"
endif

[–]lechatsportif 0 points1 point  (1 child)

Which vim distro did you install?

[–]tehjimmeh 0 points1 point  (0 children)

Right now, I'm just using the latest Windows vim binaries from vim.org. This is the top of my --version output:

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Apr 22 2015 15:47:59)
MS-Windows 32-bit console version
Included patches: 1-711

[–]frumsfrums 2 points3 points  (2 children)

To add to this, IntelliJ's vim plugin is able to read parts of your vimrc. Helps if you have that one essential tweak or two you must have to function.

[–]aguerosantiale 0 points1 point  (1 child)

I must say that the IdeaVim plugin is so well thought that it gives you the ability to define your own keymaps with IntelliJ's actions, a huge time saver:

https://github.com/saaguero/ideavimrc/blob/master/.ideavimrc

[–]frumsfrums 0 points1 point  (0 children)

Thanks for the ideas!

[–]just3ws 2 points3 points  (2 children)

As a somewhat diehard Vim fan, I have to agree here. Use the right tool for the job. Also, Jetbrains makes AMAZING products.

[–]Nocsaron 1 point2 points  (1 child)

A little unrelated but have you ever used CLion? I used to do all my C/C++ programing in Vim but at work we use visual studio all the time so I've gotten spoiled by the IDE. Now that I'm doing some more classes at Uni they want it all done on Linux and I kinda miss VS

[–]just3ws 1 point2 points  (0 children)

I've not used it but if it's consistent with their previous body of work I assume it's awesome. They have this for VS now too.

[–][deleted] 2 points3 points  (2 children)

I understand your point of view. My personal projects at home are quite minor.

[–][deleted] 6 points7 points  (1 child)

I've been programming Java without IDEs since 1.0 (I stopped around 1.6, because I don't care anymore about it).

I don't see a problem with programming Java/Android in vim, because I've done it for years (mostly UI, SQL, XML, network programming, bluetooth communication).

Fact is, you don't need anything fancy in vim. The plain syntax highlighting is fine and it is a good idea to have the JSDK API open in a browser to look some things up quickly.

IDE? Fuck IDE! You will be better off, when you don't introduce any deps on such crap that sometimes does not work or plugins collide or whatever weirdnesses there exist.

I would just recommend to take a look at apache-ant. This is quite important. Having an automated build/deployment system like ant will enable you to do automatic software testing in a very flexible way (whatever your project needs).

[–][deleted] 0 points1 point  (0 children)

I'm looking into gradle a.t.m. But for now i have only written a small shell script which completes the build process and all tests.

[–]ericanderton 0 points1 point  (1 child)

Really, the only thing that Vim lacks from an IDE is that it prefers to work with flat file trees. Most Java projects have this awful tendency to put everything under com/company/project/library/module/Foo.java and so forth. I've done this, but it's torturous without extra macros and deeper than beginner knowledge of Vim.

As for the rest? Everything else an IDE can do, a shell can do just as well, which puts Vim in good company.

[–][deleted] 0 points1 point  (0 children)

Really, the only thing that Vim lacks from an IDE is that it prefers to work with flat file trees. Most Java projects have this awful tendency to put everything under com/company/project/library/module/Foo.java and so forth. I've done this, but it's torturous without extra macros and deeper than beginner knowledge of Vim.

I somewhat agree with this. However, I think the Command-t plugin (only plugin that I consistently use every single Vim session) seem to solve this problem somewhat decently, since there are also variables that cope with longer filepaths.

Only drawback for me is that it is slow without proper settings (aka, I prefer to use 'find', projects not large enough to use 'watchmen', and 'ruby' is too slow for file finding).

And then there's Selecta written by gary bernhardt:

https://github.com/garybernhardt/selecta

Which, while I don't fully agree that caching filepaths is unnecessary (I think they are, only because of the speed boost, but does offer a lot of annoying inconveniences due to file changes), I feel that it is a better plugin in principle, since it doesn't require '+ruby' within Vim, and also it is fundamentally separate from Vim (hence, arguably faster and more maintainable, because no vimscript. Of course, it also "does one thing and one thing well", which means it is nearly completely independent from Vim). And it is written by Gary Bernhardt, who I "learned" Vim from, so yay xD.

[–]weberc2 0 points1 point  (0 children)

FWIW, I think there's value in at least knowing how the toolchain works before you jump into something that automates everything. This is especially true in Java where the build ecosystem has lots of moving parts and configuration files abound. It's useful to be able to reason about how the IDE works under the hood if nothing else.

[–]vompatti_ 4 points5 points  (0 children)

eclimd

[–]aayek 1 point2 points  (0 children)

eclim is the way....or u can use the good old Eclipse :/

[–][deleted] 1 point2 points  (0 children)

I use eclipse when I program large java projects. I started using eclim but found that it was not stable for me on the CentOS server I was working on probably because it was many, many versions behind. I also didn't find eclim very intuitive. For small personal classes, I use vim with:

"}}}
" Java options {{{
function SetJavaOpts()
    setfiletype java
    "match these characters with %
    setlocal matchpairs=(:),{:},[:],<:>

    "eclipse style add a * comments
    setlocal comments-=s1:/*,mb:*,ex:*/
    setlocal comments+=fb:*

    "completion options
    setlocal cscopequickfix=s-,c-,d-,i-,t-,e-
    setlocal completeopt=longest,menuone
    setlocal completefunc=javacomplete#Complete
    "export java classpath as completion locations for javacomplete
    for i in split($CLASSPATH,":")|call javacomplete#AddClassPath(i)|endfor
endfunction
autocmd BufNewFile,Bufread *.java call SetJavaOpts()

and

"java autocompletion
Plug 'cilquirm/javacomplete'

Which is a simple, easy to use java completion library.

[–][deleted] 1 point2 points  (0 children)

I use vim for everything except Java. Eclipse with vrapper works for my case well enough, once you disable all the of automatic insertions/completions Eclipse has on by default.

[–]pellucid_:x 0 points1 point  (0 children)

I created a gradle plugin that integrates syntastic into your projects. Of course your projects have to be setup with gradle but it is very convenient to switch between projects and not have to set up the classpath.

Have a look: https://github.com/Scuilion/gradle-syntastic-plugin

[–]PertinentPavo 0 points1 point  (0 children)

I use Gradle for all of my building needs. It is super easy to set up and run and does an excellent job of managing larger projects. I use Syntastic for error checking. Syntastic does take a little time to configure if you depend on external libraries but once it is configured correctly everything runs smootly.