January 01, 2016
Vim and Emacs

vim

vim is great.

I started with learning vim as it’s straightforward to use. vim, although not often included in default tools offered by Unix OS’s, can be accessed as vi. Learning how to edit in vim - and I’m still learning - has sped up programming. I’ve added vim to every editor I have, including my IDE.

emacs

emacs was something that I’ve always wanted to learn, but struggled to do so. I like the core concept of extensibility and self-documenting:

At its core is an interpreter for Emacs Lisp, a dialect of the Lisp programming language with extensions to support text editing.

It is essentially just a Lisp programme. It’s insanely configurable. As I was learning Clojure, I thought this would familiarise me faster to the world of Lisp languages.

I have yet to be comfortable with emacs, but I’ll get there one day.

Org mode

In another editing-tools-universe, I’ve come across Org mode, a plugin for emacs. I was looking for a tool that could unify the various note taking tools I was using. At this point, I was jumping between notebooks, Evernote, Airtables, Todoist, and more, and I was getting tired of jumping between tool. Org mode seemed like the best thing that could merge all of the things.

Learning emacs proved to have a steep learning curve, especially after I’ve familiarised myself with vim.

Spacemacs

This distribution of emacs gives you emacs and vim. I started using it, I liked it for a bit. But since the corporate proxy gave me a huge headache, I stopped using it eventually. It is the most popular distribution for emacs and vim.

Doom

This is a different distribution that I found potentially more vim-friendly and faster than Spacemacs


Shortcuts

For vim

Command Description
:! Run Shell command
: jumping to line
:w Save
:! rm Remove
:w other_filename Saving to a new file
Esc Normal Mode
i Insert Mode
I Insert before word
hjkl left down up right
w Start of word
b Beginning of word
e end of word
o open line after
O open line before
f<m> forward to character m
F<m>
gg to the beginning of file
G to the end of file
<n>G to line n
, to the next sentence
;
u undo changes in the current command
Ctrl+R redo changes in the current command
d<m> delete in direction m
dd delete line
r replace
R overwrite
/<w> search mode, search for w
n search mode, next
N search mode, previous
. Repeat last command
% Matching parenthesis
p paste from d
0 Beginning
$ End of line
x delete under cursor
X delete left of cursor
v visual mode

Notes

  • insert numbers to do [n] * [action]
  • To insert multiple of the same in each row:
    1. Select all N row lines of block by pressing V and then j 4 times.
    2. Indent with >.
    3. Go back one letter with h.
    4. Go to block visual mode with ctrl + v.
    5. Select down N rows by pressing j N times. At this point you have selected a Nx1 visual block of whitespace (N rows, 1 cols).
    6. Press c. Notice this pretty much indented to the left by one column.
    7. Type out the desired text. Notice the extra space we had to put back.
    8. Press esc. This is one of the very few times I use esc to get out of insert mode. ctrl + c would only edit the first line.

For emacs

A list of the shortcuts for Doom is in this file: evil-bindings

Packages

M-x package-refresh-contents

M-x package-list-packages

To get some commands running, always start with Ctrl + X

buffers

Ctrl-x-b creates buffers

Ctrl-x-k kills buffers

files

C-x C-f (C meaning Ctrl) opens file

C-x C-s saves the file

Meta

M-x means Alt + X

Org-mode

C-c C-t toggle task states

Resources