I started using VIM as my editor for programming and general use. That also meant switching my command line environment shortcuts to VI rather than Emacs.
This post highlights a few interesting problems I had and how I solved them. For a shell I use ZSH and my terminal emulator is Gnome-terminal. I should probably start using Tmux as well but haven’t yet really gotten into the habit.
- VI mode in ZSH (perhaps BASH for others)
- Remap
escape
key- xmodmap
- xmodmap command in .*rc files didn’t work as expected
- script to customize gnome terminal
- xmodmap
- command history search
control R
VI keybindings
I put the following in my .zshrc
file.
# VI mode
bindkey -v
Command History Search
If you use VI keybindings, then control r
command history is broken. I found a fix on SO as I recall, here it is:
# enable Cnt R for search history: required with VI mode bindings on
bindkey "^r" history-incremental-search-backward
Xmodmap
I put the following code into a file named .Xmodmap
.
remove Lock = Caps_Lock
keycode 66 = Escape
keycode 9 = Caps_Lock
add Lock = Caps_Lock
Xmodmap in a script
#!/bin/zsh
# Check if Escape has been mapped to Caps_Lock
bool=$(xmodmap -pm | grep lock | grep -c "\(0x9\)")
if [ $bool -eq 0 ]; then
source /home/daniel/.zprofile
# log located in "/var/log/syslog"
logger -i -t "remap Escape" "Escape key re-mapped to Caps-Lock"
fi
Terminal Short Cut
When I open a terminal I like the dimsenions of the screen to be full height of the screen and an 80 character width. Gnome terminal has command line arguments for this.
After the terminal is opened, I want xmodmap to remap my keys for me.
gnome-terminal --geometry=80x1000
caps_map
Now I have a working VI mode where Escape is mapped to the Caps Lock key, my terminal opens to decent dimensions and my command history search works. I’m pleased for mow.
Next up, Tmux configuration that I like.