Spacemacs Basics

TODO: Expand following content into sections

Editor styles - Evil or Holy modes

You have the choice of using either Vim or Emacs keybindings for your edior. Or you can have both and switch between the two with C-z.

Regardless of your choice, you can still use all of the features of Spacemacs via the command menu M-x.

Vim is arguably faster, especially once you get used to multi-mode editing (switching between normal & insert mode). This speed is in part due to simpler keybinding when in normal mode as you are not typing content into the editor, simply running commands with each key press. This means you can have single characters to do many of the common commands, eg l instead of C-f for moving the cursor forward.

If you are familiar with Emacs keybindings, then probably best to stick to holy mode. If you are new to Emacs or you just want to take advantage of Vim, then select Evil mode.

Why Vim ?

Positives

  • Cut the Mouse - One of the main wins for Vim has always been that it is an editor that lets you keep your hands on the keyboard. Reaching for the mouse slows you down, and while I never really had a problem with that in the past (I spend more time thinking and reading than I do writing code), now that I’ve experienced 2 months with my hands on the keyboard I do find myself noticing (annoyingly) when I am forced to reach for the mouse.
  • Fast Navigation - Moving around inside files in most windows editors involves a lot of home/end/up/down arrow key. Having search and tag based navigation makes getting around within a file much faster. Finding the right file is also easier with the commandt plugin, influenced by Textmate on the Mac, this fuzzy file finder is not typically available in traditional windows editors (last time I looked)
  • Split Windows - Splitting windows into panes and navigating around them is a killer feature that I use all the time to see multiple files at once, or multiple areas of the same file at once. In the past I used tabs heavily, but I now prefer split panes that I can manage without reaching for the mouse.

Negatives

HJKL - Sorry, call me a heretic but I just cannot get used to using these keys for up/down/left/right. 20+ years of using the arrow keys is completely and utterly embedded in my brain. Besides, I’m pretty sure J (down) and K (up) are bass-ackwards. Western languages, and presumably most programming languages, read from TOP LEFT to BOTTOM RIGHT so shouldn’t UP be next to LEFT and DOWN be next to RIGHT ??? I know I could remap the keys, but plugins that follow similar patterns would also have to be remapped and I just could not get used to it.

Mode Struggles - The modal nature of Vim is both a blessing and a curse. Its the feature that allows us to keep our hands on the keyboards without the wrist breaking key combo’s of Emacs but its also far too easy to forget which mode you are in and start typing code only to discover you just executed 5 random commands. The people who recommend you ESC constantly back into command mode are absolutely correct. You have to shift your thinking into being primarily command based with short sharp bursts of INSERT.

Breaking Windows - One of the side effects of the modal nature of vim is that it trains you to constantly hit ESCAPE to go back to command mode…. but when you do this in more traditional windows apps its quite possible you will end up dismissing a dialog while you are in the middle of typing! How frustrating! I hit this mostly when using Tortoise SVN for my code commits.

Disappointing Plugins - Whilst some plugins are awesome, some are surprisingly disappointing. While I was really looking forward to them, the following plugins just didn’t get as much use as I expected session (doesn’t work well with NERDTree or quickfix window), taglist (doesn’t work well with dynamic languages - at the moment I use primarily Ruby and Javascript), Conque Shell - (nice idea, but doesn’t feel natural, just easier to use :shell or have another terminal open)

Effort vs Reward

Ok. So I have a theory…

Vim proponents will tell you that the effort you spend learning vim will pay dividends in the long run once you know how to use it properly. After 60 days I can say that I agree with that opinion.

However, if I spent this much effort learning any editor I think it would pay dividends in the long run. The difference is that Vim forces you to go through this pain, whilst other editors work ‘out the box’ and so most programmers are not inclined to learn the power of those editors.

For example, I think UltraEdit, TextMate, even Visual Studio are pretty good editors, but since they all pretty much just work out of the box, its easy to ignore their advanced features and not spend the time customizing and configuring them.

I wonder if I spent 60 days really learning UltraEdit if I couldn’t get the same positives I described here ? Hmmm, a future article maybe? Conclusion

I’m still using Vim after 60 days, and I plan to continue using it for the foreseeable future as long as I can keep taking a little time here and there to dig deeper, customize a bit more, learn how to overcome the negatives and build upon the positives.

Vim seems to be so powerful that I could be learning it forever. Here’s a list of some of the things I want to spend time on in the future.

Movement - I need to learn more code related movement commands like % match
Sessions - Both sessions.vim and sessionman.vim seem to struggle with NERDTree and the quickfix window
Cut & Paste - I need to learn more about vim registers so I can manage my cut & paste better, errr, sorry, I mean yank & put
Undo & Redo - I think I spend too much time in insert mode so when I undo it tends to be more than I’d like
HJKL - Maybe I should remap to swap the J and K keys and try again!
More Plugins - There are many more plugins I would like to take the time to check out, and perhaps build some of my own.

Working with Buffers

To work with files in Emacs, they are first loaded into a Buffer.

So when you open a file with M-x find file or SPC f f a new buffer is created so you can manage that file.

Buffers are displayed in a window and you can change the window to show any of the current buffers.

Here are the most commonly used buffer commands

Keybinding Command Description
SPC b b helm-mini List current buffers
SPC b d kill-this-buffer Kill current buffer
SPC b h home Switch to Spacemacs home page
SPC b n next-buffer Switch to next buffer
SPC b p previous-buffer Switch to previous buffer
SPC b s switch-to-scratch-buffer Switch to the scratch buffer
SPC b Y copy-whole-buffer-to-clipboard Copy current buffer contents to kill ring

See the full buffer menu via SPC b

Spacemacs Buffer Menu

Managing Files

Spacemacs Emacs Evil Command
SPC f R M-m f R , f R rename-current-buffer-file

Also consider using:

  • dird
  • neotree
  • projectile

Editing text (especially in Evil mode)

See Vim section

Working with Windows

Keybinding Command Description
C-x 1 Close current window
C-x 2 Vertically split current window
C-x 3 Horizontally split current window
SPC number Jump to window number

You can also create layouts that are a collection of windows

results matching ""

    No results matching ""