Vim, the only editor I use.

  about 701 words   4 min

vim

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.

Vim adventures

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

PacVim

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.org


vim editor terminal CLI
STORIES BASED ON SAME TAGS

Using Timewarrior With Taskwarrior

Terminals have always been a thing that I loved to use. I spend a lot of times using and tweaking them. i My daily use include a lot of this little programs that help you to improve your productivity. Keybindings and customizations is also one thing that I love about terminals compared to GUI. That's also why I awesomewm. For those who don't know what it is, it's a lightweight tiling window manager like Ion.

Read more

Goodbye Writefreely Hello Hugo

Finally, I ditched Writefreely, the fediverse blogging framework in favor of Hugo. why ? I love terminals and vim like … a lot ! I wanted something where I could use my beloved editor to write a post in Markdown, commit it and that could be automatically posted using a post-commit. Ideally, I wanted a thing that involves the fediverse to be able to get comments directly from Mastodon or Pleroma.

Read more

Delete Letsencrypt certificates

Letsencrypt allows you to get a free certificate that you will need to renew each three months. There are a lot of tutorials online on how to get one or more and I would like more to focus on how to delete them when you don't need it anymore. Deleting a SSL certificate is not about just deleting one file only.

Read more