People around me know that I love to spend time in terminals. For them, I am probably a nerd that do a lot of obscure stuff in these little black windows. A lot of friends that look at my screen have the same reaction :
- Your computer doesn't work
- What the hell are you doing ? Can't you just have a normal laptop
Since I'm using awesome as a window manager it keeps them even more dubious about how I'm using a computer. But a lot of times, I just read my mails (OK OK in mutt but still…), playing around with some scripts or writing some posts in Vim.
I started to read te second edition of Practical Vim, a book that I recommend to everyone who wants to be fluent with that editor.
I love a lot that book since it helps you to be better at using vim, a software that a lot of young, and not so young, programmers hate.
A colleague said to me once that he prefers nano to edit files but ironically that morning he didn't succeed to do a research/replace with it and finally did it manually 😉.
Vim and its philosophy
The Vim commands are not difficult, they have been thought with mnemonic technique to be able to remember keybindings. For some, you already know them :
To undo, type u. To find the next t from your cursor position, type ft. To delete a word, type daw. To change a sentence, type cas.
More often than not, you can guess the correct command by thinking of an operation you want to execute and an object to execute it on. Then just take the first character of every word. Try it! If anything goes wrong, you can always hit ESC and type u for undo.
Operations: delete, find, change, back, insert, append,…
Objects: word, sentence, parentheses, (html) tag,…
Inserting text is just another editing operation, which can be triggered with i. That's why, by default, you are in normal mode — also called command mode — where all those operations work.
Once you know this, Vim makes a lot more sense, and that's when you start to be productive.
Shells and vim mode
In Zsh, bash and other shells you have a vi mode that you can set with :
% set -o vi
A lot of users don't even know that this mode exist. What that command does ? That gives you the same commands that you use in vim to move around your shell commands. You have the command and insert mode, you can use almost all the keybindings you know from your editor to your shell.
And I like that … a LOT.
The only thing I borrowed from the default emacs way of doing it is for a back search of previous commands.
I added this to my zsh config to be able to do a Ctr-R. Here is my history config for zsh :
# ~/.cfg/zsh/history.zsh HISTFILE=$HOME/tmp/.zhistory # store history to ~/tmp/.zhistory HISTSIZE=10000 # number of lines kept in session history SAVEHIST=10000 # number of lines saved in history after logout setopt hist_ignore_all_dups # if a new line is a duplicate, remove the older line setopt histignoredups setopt hist_ignore_space # ignore lines that begin with a space (useful for secrets) setopt inc_append_history # add line to history immediately after execution setopt share_history # easily share history between concurrent sessions setopt hist_verify # don't immediately execute an expanded command unsetopt global_rcs bindkey '^R' history-incremental-pattern-search-backward # __ END __
The line that is interesting is the one with the bindkey. I just prefer to use Ctr-R to go through my history.
Fun ways to learn it
Just check that little web browser game to learn the basics.
If you're old enough, you probably played the famous game : Pacman ! Here is a little game that you can in you terminal to learn vim
Vim offers really a lot of features and plugins that you can customize or use. The link below offers a lot of them :
Vimawesome.com - plugins from across the universe
You can also check, the official website :
vim editor terminal CLI