Working with java subprocess from vim

First of all, we need Conque vim plugin: http://code.google.com/p/conque/ (If you are using git, github and Pathogen: https://github.com/rygwdn/vim-conque).

This plugin allows us to create subprocesses and communicate with them.

Let’s write simple Java program:


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class VIMIOTest {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        while (true) {

            String command = br.readLine();
            if (command.equalsIgnoreCase("exit")) {
                break;
            }else if (command.equalsIgnoreCase("test")) {
                System.out.println("test answer");
            }
        }
    }
}

And vim script for working with it:

let g:jp = conque_term#subprocess('java VIMIOTest')

function! SendTest()
    call g:jp.writeln('test')
    let output = g:jp.read()
    echo 'output:'.output
endfunction

function! CloseTest()
    call g:jp.writeln('close')
    call g:jp.close()
endfunction

Thats all!
More docs about conque: http://code.google.com/p/conque/wiki/Usage

Refresh html page from vim on mac

For doing this just add these lines to project .vimrc or global .vimrc:

function! s:OpenHTML(path)
    exec('silent !open -a Safari '.a:path)
    exec("silent !osascript -e 'tell application "iTerm" to activate'")
    exec('redraw!')
endfunction                                                                      

command! OpenHTML call s:OpenHTML(expand('%'))
nmap <silent> <F5> :OpenHTML<CR>

You can replace expand(‘%’) to custom path for refreshing project html file.
For example:

command! OpenHTML call s:OpenHTML(s:projectPath.'/html-tests/chartView.html')

Also you need to replace iTerm to terminal you are using.

Key binding for refresh – F5.

Google Closure Linter: vim integration


0. Install google closure linter (http://code.google.com/closure/utilities/
1. Install google-closure-linter-for-vim vim plugin:
https://github.com/batsuev/google-closure-linter-for-vim
Using pathogen:

git clone git@github.com:batsuev/google-closure-linter-for-vim.git ~/.vim/bundle/google-closure-linter

Or manual:

cd ~/.vim/ftplugin
wget https://raw.github.com/batsuev/google-closure-linter-for-vim/master/ftplugin/javascript.vim

2. Now you can call :make in normal mode and use general error navigation (e.g. :cprev :cnext :clist)