Using Vim as your editor with Octopress works well enough except that you have to either exit out of the editor or open a second session in order to generate the site to see your new posting. Using Vimux you can run commands in a separate pane without losing focus in your Vim pane. This turns out to be perfect for creating or editing posts for an Octopress site.
First you need to add the Vimux bundle to your Vim configuration. Since I’m
using Vundle I just added this
line to my
And then installed the new bundle.
Bundle 'benmills/vimux' :BundleInstall
The Vimux help (
:h vimux) does a great job of explaining the various commands
and options provided by the bundle. Here are the settings I added to my
Bundle 'benmills/vimux' let g:VimuxHeight = "30" let g:VimuxOrientation = 'v' let g:VimuxUseNearestPane = 0
The height setting controls what percentage of your current pane will be
given over to the Vimux pane. The orientation settings controls whether the new
pane is vertically below the current one (
v) or horizontally to the right of
VimuxUseNearestPane when set to true (
1) will use the nearest
open tmux pane rather than space within the pane containing your Vim session.
With these settings in place I added some general Vimux mappings.
Bundle 'benmills/vimux' nmap <leader>vp :VimuxPromptCommand<cr>
This brings up a
Command? prompt where you can enter any command your shell
Bundle 'benmills/vimux' nmap <leader>vl :VimuxRunLastCommand<cr>
As the name suggests,
VimuxRunLastCommand reissues the last command.
Bundle 'benmills/vimux' nmap <leader>vq :VimuxCloseRunner<cr>
VimuxCloseRunner closes the Vimux pane.
Bundle 'benmills/vimux' nmap <leader>vx :VimuxInterruptRunner<cr>
The interrupt runner command halts the command in the runner.
Rather than have to bring up the Vimux command prompt with
,vp and then type
in my Octopress generate alias, I created some more mappings with Octopress
Bundle 'benmills/vimux' nmap <leader>vg :call VimuxRunCommand("gen")<CR> nmap <leader>vi :call VimuxRunCommand("ingen")<CR> nmap <leader>vz :call VimuxRunCommand("dz")<CR> namp <leader>vd :call VimuxRunCommand("deploy")<CR>
The first of these,
vg runs my alias for
rake generate, building what ever
is currently in the
source/_posts directory. I make heavy use of
rake isolate as my site contains over 2,000 entries and takes more than 8 minutes
Which explains the next mapping,
ingen is my alias that runs a
rake integrate followed by a
rake generate. Typically I only run this command
when a new posting has been proofread and is ready to be published.
I have two Octopress sites, one of which is
still on an much older version of Octopress. The
rake deploy task for this
older version doesn’t handle
.htaccess files, so my
dz alias chains
together the commands necessary to rsync my site and copy the
vd mapping issues my alias for a regular
rake deploy which
works for my new Octopress site.
Having Vimux in place allows me to work on a new page or posting, generating the site as I go, without losing focus in my Vim session. It has made creating new content for my sites simpler and more satisfying.