The previous video demonstrates a simple hack using a custom version of the vim plugin vimsh. The new features are:

  1. An option g:vimsh_filetype to customize the syntax coloration in the prompt buffer;

  2. Another option g:vimsh_split_method to control where the prompt pops. Cf. the vim functions :below and :above.

  3. Improve g:vimsh_sh_arg parsing using the python module shlex.

The whole thing is very hackish and rely on additional vim shortcuts in the $HOME/.vim/ftplugin/*.vim files. See for examples the first lines of my $HOME/.vim/ftplugin/python.vim file:

""" VIMSH (highly experimental)
if !exists(':LoadREPL')
    let g:vimsh_sh="/usr/bin/python"
    let g:vimsh_filetype="python"
    let g:vimsh_split_method="below"
    " Keep the python filename in memory for later use …
    let g:vimsh_filename=expand('%')
    " Start python with the "from FILENAME import *" statement.
    let g:vimsh_sh_arg = '-i "'.expand(g:vimsh_filename).'"'

    command! LoadREPL call LoadREPL()
    function! LoadREPL()
        runtime vimsh/vimsh.vim
    endfunction

    " open vimsh buffer
    map <F12> :LoadREPL<CR>
    " save the current buffer, switch to vimsh buffer, force file reload
    " and return back to our original position.
    map <F5> <Esc>:w<CR>:below sb _vimsh_<CR>GAexecfile("<C-R>=expand(g:vimsh_filename)<CR>")<CR><Esc><C-W><C-W>
    " Copy-and-paste the last selection to REPL and return back to our
    " original buffer.
    map ,e y<Esc>:below sb _vimsh_<CR>G$pA<CR><Esc><C-W><C-W>
endif

The pros:

  • vimsh allows you to reuse your vim configuration, including syntax coloration and auto-completion systems.

  • Easily and quickly extensible to simples shells available outta here.

The cons:

  • hackish, but you would not be using vim if this bothers you ,-)

  • does not support fancy outputs (as with ncurses or color terminals)

  • far worse than the HaskellMode or SlimV plugins for Haskell and CommonLisp.

If you want to test the beast, a quick-and-dirty package is available here.

/DS, yet another useless year ☻