Learning VIM with Spacemacs

2018/04/18

Tags: emacs

I just don’t grok the vi (yet).

Spacemacs

Three weeks ago, I’ve ditched most of my emacs config and installed spacemacs. The main driver was that I wanted to try modal editing instead of emacs key chords. I could’ve tried vim of course, but I’m already invested in emacs and feel at home there.

Evil-mode #

Luckily, there is a brilliant vim emulation in emacs, called evil mode. I didn’t want to spend too much time configuring it though plus I have no idea which vim plugins ported to emacs are worth looking at, so I’ve given spacemacs a go. Spacemacs is a distribution of emacs preconfigured with evil and with an extensive documentation.

Actually, I’m positively surprised how polished it is. Note: I’m using develop branch. Whether you’re an emacs user who wants to try vim-style editing or a vim user who wants to switch to emacs and its superior package ecosystem (well, I just <3 magit) then spacecmacs is worth giving a shot.

Note to future self: doom-emacs is another evil-preconfigured distribution which gets a lot of good feedback recently.

Zen of Vim #

The only problem is that I just don’t know vim :) Of course, I can change a config option on a remote server or scroll through a config file. But my vim knowledge is super limited, I don’t know useful shortcuts or even the philosophy.

I’ve found this a nice post on StackOverflow about the Zen of vim. This motivated me to go through the first series of wonderful vim screencast by Derek Wyatt. My notes form the videos are below in case I’ve ever need to reference them.

How do I like it so far? #

Well, the modal editing is quite a change. I think that after three weeks I’m still a bit less efficient. Actually, the navigation in normal mode feels quite efficient, even if I don’t have the muscle memory yet. I struggle a bit more with writing (like this blog post), the mental shift from modeless, chord-full editing is a bit harder.

On the upside, there is a good IntelliJ plugin emulating vim, so I can work on my muscle memory more :) I use IntelliJ to write Java / Scala at work.

Again, the Derek Wyatt’s set of videos was super helpful (I’ve checked the novice, for now, once I’m comfortable with that I’ll probably go further).

What’ve started as an experiment, to see if there is a better way may become may permanent mode of operation. Stay tuned.

Learning to vi #

Favorites #

Some of my favorite vi / spacemacs tricks

Vim Videos by Derek Wyatt #

http://derekwyatt.org/vim/tutorials/

BASIC Movement (Screencast 1) #

KeyDescription
h  j  k  larrows
0  $start / end of line
w  Wnext word / WORD
e  Eend of word / WORD
b  Bstart of word / WORD backwards
ge  gEend of previous word / WORD
f<char>follow — search for next occurrence of
F<char>follow backwards
t<char>until — similar to f but places the cursor before
T<char>until backwards
;repeat f/F/t/T movement
gggo to the top

BASIC Movement (Screencast 2) #

KeyDescription
C-f  C-bfull page forward / backward
C-u  C-dhalf page up / down
H  M Lhead / middle / last line on screen
gg  Gtop / bottom
17Ggo to line 17
*  #search for word under cursor forward / backward (then n / N)
/<term>  ?<term>search for forward / backwards
zzcenter on screen

Basic Movement (Screencast 3) #

KeyDescription
]]  [[next / previous { in 0th column
][  []next / previous } in 0th colunn
%matching parentesis
:markslist current marks
m<char>mark position as
'<char>jump to line of mark at ^
\<char>jump to line and column of mark
''jump to previous location

Basic Editing (Screencast 1) #

KeyDescription
i  Istart inserting under the cursor / at the beginning of the line
a  Aappend after the cursor / the line
o  Oopen line below / above current
x  Xdelete / backspace
d<motion>delete (e.g. dw delete word)
dddelete line
.repeat last editing command
c<motion>change (e.g. cw change word)
Cchange to the end of the line
Rreplace (overwrite) mode
rreplace character under cursor
ssubstitute (replace a character and put you into insert mode)
Schange whole line

Basic Editing (Screencast 2) #

KeyDescription
yy  Yyank line
y<motion>yank
ppaste after (cursor / line)
Ppaste before (cursor / line)
J  gJjoin line / without space
v  Vvisual selection by character / line
C-vvisual block (then I to insert at the beginning, etc.)
gvre-do last visual selection

Working with many files #

A bit less useful from spacemacs perspective, but surprisingly most of the keys still work; I’ve aggregated the screencasts here

Vimeo #1

Vimeo #2 (not applicable to spacemacs)

Vimeo #3 (about windows, surprisingly applicable)

KeyDescription
:lslist buffers (helm in spacemacs)
:b <name>switch to (w/o name to alt buffer, in vim this is :b#)
:bd <name>delete (current buffer without name)
C-wleader key for windows, usually equivalent to SPC w in spacemacs, noted otherwise
C-w o  SPC w monly buffer (maximize buffer in spacemacs)
:sp  :split  (<fname>)split horizontally
C-w s  SPC w -.same
:vsp  :vsplit (<fname>)split vertically
C-w v  SPC w /.same
SPC w Mexchange windows (the closes equivalent to C-w x in vim)
C-w hjklswitch to window right / down / up / left (accepts count)
C-w HJKLmove window right / down / up / left
C-w c  SPC w dclose window (delete window in spacemacs)
C-w p  SPC w wprevious window (other window in spacemacs)

Why, oh WHY, do those #?@! nutheads use vi? #

Another zen-of-vim style article.

Spacemacs #

KeyDescription
SPC f e dopens ~/.spacemacs
SPC t Lenables line wrapping
SPC f fopens file
SPC t nshows line number
SPC bshows action for buffer
SPC b dkills current buffer
SPC TABcycle between open buffers
SPC SPCM-x

Org mode #

KeyDescription
SPC a o oshows org mode agenda
, dset deadline for the current TODO
, sset schedule for the current TODO
SPC m RETinsert headline (inherit from above)
C-c C-ttoggle status for TODO
C-c [add this buffer to agenda list
C-c ]remove this file from agenda list
, Aarchive a TODO item
, Rrefile an archived item

Doom emacs #

KeyDescription
SPC p popen project
SPC SPCopen other file in the same project
SPC ,switch to workspace buffer
SPC w vsplit windows side-by-side
C h/j/k/lmove between windows
SPC w cclose the window
SPC o nneotree
SPC o tterminal
>> Home