25 Dec 2012

RCodeTools - How to get them working in VIM

RCodeTools is an add-on for popular neckbeard text editors such as VIM and Emacs. (My preference currently being VIM). I came across it through RubyTapas Screencasts by Avdi Grimm. He uses it extensively in his screencasts for crystal clear explanations and live displays of code execution.

RCodeTools adds hash comments (ie #=\>) to the text editor buffer. Then when another command is executed, the whole buffer is evaluated and the area beyond the hash comment is populated with the output from that specific line(s) of code.

It’s remarkably helpful for explaining and demonstrating code because it avoids any context shift. The comments serve to demonstrate the code’s state at any given moment!

Avdi Grimm uses RCodeTools inside Emacs in the screencasts and I was eager to begin using RCodeTools myself. I had difficulty getting the plugin to work in VIM, resulting in attempts to reinstall VIM, modify the $PATH, etc.

Turns out there is a simpler way: 1. Install RCodeTools into your ~/.vim/ folder. Specifically this means the vimscript files. 2. Install vim-rvm for managing path. 3. Gem install rcodetools inside your standard RVM ruby. 4. Add mappings to VIMRC. Included are my mappings (which are recommended by the README.vim)

I look forward to putting this addon to good use at future CodeRetreats! And it’s the perfect compliment to screencasting.

Thanks Avdi for drawing my attention to this wonderful tool.

15 Dec 2012

rcodetools and VIM

I’ve been listening to RubyRogues which introduced me to Avdi Grimm from the Ruby community. I’ve also been subscribed to his RubyTapas screencast series which is a 2x a week Ruby show.

He uses a neat tool called rcodetools to execute Ruby code from within an Emacs buffer. Unfortunately, it wasn’t working when I tried to use the VIM counterpart, with segfault codes showing up. Here’s the fix: ( I’m using RVM to manage my Ruby Versions ) *Install Tim Pope’s excellent rvm extension for VIM cd ~/.vim/bundle git clone git://github.com/tpope/vim-rvm.git

*Install rcodetools using RVM gem install rcodetools

*Remove keybindings in other programs (ie Dashboard & Expose) for F10, F11, F12 or rebind the keys per README.vim

Now enter a VIM file and type F12 on any lines that you want the output from followed by F11 to evaluate the whole file. If you want to only re-evaluate the current line use F10 instead of F11.

It’s a great tool for terminal screencasting! Thanks Avdi for letting me know that this tool is available.

19 Aug 2012

Swap out BAD line endings for Unix standard

:setlocal ff=Unix :w

Converts and saves current buffer as Unix standard line endings. n FTW!


brew install dos2unix Then use dos2unix to easily swap line endings into Unix format dos2unix \*.rb

31 Jul 2012

FASD - The Commandline Shortcuts I always wanted

FASD is a shell script that follows in the concept and footsteps of Autojump and Z. It extends the functionality of both of those systems to better differentiate between files and directories. FASD also allows for tacking on different commands to the beginning of a fasd reference such as using vim in an alias, ie: alias v='fasd -e vim'. This VIM alias calls up the most active file matching that pattern and opens it in Vim. Or a simple z searchterm will find the most often and recently used folder and ‘cd’ into it! This is amazing for nested folders. It’s like Vim’s Ctrl-P or Ctrl-T but on the commandline and with more flexibility.

It’s magic and I’ll post back if I keep having good success. Try it out with a brew install fasd or check the install instructions on their github page for more options - FASD.

Update: Still having very good success. ¬†Moving from ~/ to deeply nested folders is a breeze with ‘z SOMEPARTOFPATH’ and likewise using vim to edit a deeply nested file with ‘v SOMEPARTOFNAME’. ¬†It’s nothing short of magical after 2 months of use.

Update Jan 2013: Can’t imagine living in the shell without FASD. This is now included in my environmental setup script.

29 May 2012

Tmux, a reluctant love story

Tmux…a complicated love story.

In the beginning it was like other romance, flirt a little bit, brief moments of interaction, maybe compile from scratch and smell the roses on distant servers.

But it never really stuck. GNU Screen was quite the workhorse and I only needed it on remote servers because Terminator terminal emulator worked very well with multi-splits and session state maintenance. I had many “Oh that’s what I’ve been doing” type moments. At the time I didn’t see any great benefit to it on a local box.

I gave it another try on my recent Arch laptop because all the cool kids seemed to have a revived interest in tmux. The controls were nice, the look was nice, but it had more funky scrolling and mouse selecting issues than Terminator… so back I went. (Note: I remember having to choose my configuration between either a functional copy and paste w/ mouse or functional copy and paste with keyboard…but this is loosely based on my distant memories).

Fast forward to last night when I received a reminder about tmux. I thought, there’s probably something I’m missing. Lo and behold, the thing I’m missing is the awesome power of Slime.vim, Pry, and Terminal or Gvim (MacVIM).

Slime.vim allows you to program in your editor, then highlight a block of code to execute, mash C-c C-c (very Emacs), and have the code run in another split window (powered by Tmux). For me the code composition happens in VIM and is piped into a Pry session for execution and exploration. I foresee many more Slime/Pry/VIM sessions in my future and am excited about the fluidity of this setup.

The long and short of how to get it working, install tmux, add vimrc command telling it use tmux rather than screen, highlight and C-c x2 for execution.

Seems like a perfect workflow and I’m happy that I explored more about tmux.

Next is xmonad…. here I come (on linux boxes).

24 May 2012

VIM Movement command of the Day

The movment letter of today for VIM is G Using ‘G’ moves to the end of the file (or more specifically to the final line of the file).

The complimentary command is ‘gg’, to jump to top of file!

VIM: The more I learn, the better it gets.

21 May 2012

Using ZSH's History Incremental Search with Vi-Mode

I switched to ZSH a few months back and am spending more and more time in commandline + VIM/MacVIM.

Once I added the tag to my dotfile to force vi-mode on the commandline I lost the ability to do incremental searches of my zsh history. So here’s the fix which saves lots of typing:

First, the regular keybind to allow Ctrl-R to enter history search backward mode: bindkey "^R" history-incremental-search-backward

To fix the fact that the prior keymap no longer works in vi-mode zsh, add this to a zsh config: bindkey -M viins '^R' history-incremental-search-backward bindkey -M vicmd '^R' history-incremental-search-backward

Now I can ^R with aplomb…

This is thanks to the explanation from JDeBP over on superuser.com.

20 May 2012

Useful VIM cheetsheet

New VIM command of the day: d/(searchterm) This will delete up until the search term.

Source of this wisdom: VIM Commands

12 May 2012

Keeping Track of Config Files with Git and Dropbox

Dotfiles are all the rage right now on Github, and for a good reason. They’re the files that allow you to configure your Vim, Linux, Mac, etc. They’re simple textfiles written in a specific format for each given application. Being a textfile they’re easily added to a version control system like Git or Mercurial and changes can be tracked, commited, diffed, etc.

How does it work? Make a folder in your Dropbox folder and place config files there.

mkdir ~/Dropbox/dotfiles
mv ~/.vimrc ~/Dropbox/dotfiles/.
ln -s ~/Dropbox/dotfiles/\* ~/.

The first command creates the folder. The second command moves the .vimrc configuration file into that folder. The last command symbolically links all files/folders inside the dotfiles folder into the base of the home folder, ie /home/tevic/.

Add all those files into a git repository via a git init; git add .; git commit -m "Initial Commit with Vimrc". Now you can also use git for tracking changes on various branches.

I’ve been very happy with storing my vimrc, zshrc, ~/.config/zsh.d, ~/.vim/ configurations in Dropbox. Switching to a new computer or reconfiguring is no effort whatsoever.

12 May 2012

My current favorite VIMRC one-liner

Very handy for quickly swapping between prior file and current file in VIM:

Add the following to VIMRC: nnoremap <leader>, :b#<cr>

My current leader key is set to comma (,) so punching ,, switches between prior and current file, or back again.

Runner up for other good one liners: inoremap jk <esc> This one allows you to stay on the commandline and ESCAPE out of insert mode by using key combo ‘jk’!Note: I find this faster than a more common binding of ‘jj’ for this purpose. With jj the same finger needs to activate the key in quick succession. With j & k the right hand index and middle finger both activate at a similar time. Thus my preference goes to the slightly easier and faster option.

Source & Credit: Gary Bernhardt’s Dotfiles on Github (though escape sequence of jj swapped to j k)

PS - The only conflict I’ve had with j k being an ESC sequence is this blog post. In code and prose I haven’t run into problems.