Tuesday, 18 November 2014

Edit bashrc, vimrc, tmux.conf and zshrc from vim

I have found that I am playing a lot with vim, tmux, zsh and bash, and I needed a fast way to edit this files as well as source them (reload them). So I added the following lines to vimrc:

let mapleader = " "
nmap ev :e $MYVIMRC             " edit vimrc
nmap sv :so $MYVIMRC           " source vimrc
nmap eb :e ~/.bashrc               " edit bashrc
nmap sb :! source ~/.bashrc   " source bashrc
nmap ez :e ~/.zshrc                  " edit zshrc
nmap et :e ~/.tmux.conf          " edit tmux
nmap st :!tmux source-file ~/.tmux.conf  " source tmux


Leader key is but it can be configured to any key. So, for example, to edit tmux config file I press et. To source it, I press st. Simple as that. I save a lot of time when fiddling and testing new ideas in these configuration files.

Auto install Pathogen (Vundle) plugin from .vimrc

The Pathogen (formerly knows as Vundle) plugin for vim is an extremely useful plugin manager. It can automatically download other plugins from github (and other locations). One downside is that Pathogen must be manually downloaded and copied in the correct folder. However, I added the following lines in .vimrc to check if Pathogen is already installed on the system, and if not, to download it.

let vundleInstalled=0
let vundle_readme=expand('~/.vim/bundle/vundle/README.md')
if !filereadable(vundle_readme)
     silent !mkdir -p ~/.vim/bundle/
     silent !git clone https://github.com/gmarik/vundle ~/.vim/bundle/vundle
     let vundleInstalled=1
endif
filetype off
set rtp+=~/.vim/bundle/vundle
call vundle#rc()
...
if vundleInstalled == 1
     :PluginInstall
endif


I have my .vimrc on github and whenever I move to a new system I simply copy the file in my home folder. The first time I run vim, it will read .vimrc and will install Pathogen alongside with all the other plugins specified.

Tmux and Terminator key bindings

Tmux and Terminator key bindings

I have discovered Terminator before I learned about Tmux, and I must say that the feature of dividing a terminal was mind blowing. Afterwards I discovered that, unfortunately, Terminator only works in X server, so I found tmux, which also works in the absence of an X server. The problem then was that I would have 2 multiplexing applications, each with different key bindings. So, below is my setup to use similar key bindings.

TmuxTerminator
Vertical splitCtrl a vCtrl-Alt v
Horizontal splitCtrl a hCtrl-Alt h
Next paneCtrl a aCtrl-Alt a
New window/tabCtrl a wCtrl-Alt w
Switch window/pane*Ctrl a xCtrl-Alt x

Tmux uses windows and panes, while Terminator is using tabs and windows. It can be quite confusing in this regard, as the window from one application has a different meaning in the other.
The key bindings are easy to remember and intuitive.

Note: x represents a number from 0 to 9