Text-editing as a power user : from vim to spacemacs. Or how to Get Things Done.

in #vim8 years ago

TLDR

Learn how you can use a powerful text-editor to Get Things Done (an improvement over TODO-lists) in org-mode.

Also: Spacemacs might end the eternal vim vs. emacs-war.

Intro

If you are a developer (or perhaps a writer or simply someone who edits a lot of text-files) you probably know about vim : the IMproved version of the (age-old) standard unix vi-text-editor. A vim user myself for some years, I can confirm it has sped up significantly certain text-editing tasks. Even on my Windows-box I regularly use gvim.

If you know vim, you most likely have heard about the age-old rivalry with emacs. It is bigger and clunkier (e.g. in startup-time) but has much better extensibility support in its elisp-programming language. Vim is extensible too but vimscript is a rather ugly language with which you can do nothing outside of vim. The biggest difference between the two is that vim is a modal editor : the user interface is divided into seperate modes for navigating your text-file and actually editing it. Emacs on the other hand is much more RSI-prone since all its commands make use of many combinations of modifier keys. As the joke goes: EMACS stands for Escape, Meta, Alt, Control, Shift.

The time is now finally here to solve this age-old dispute (perhaps) once and for all : http://spacemacs.org/. It's built around the excellent evil-mode, which is a very good simulation of vim inside emacs. But it's much more than that. It comes preconfigured with many plugins. Its name is coming from the spacebar-key which serves as the starting point of many powerful commands, including file-browsing, undo'ing and just generally - you know - laying out text- and source-code-files and managing your projects.

Do you really need such a powerful text-editor?

Before venturing into vim- or emacs-land you should ask yourself if you really need a text editor that gives you more than 40 years of text-editing experience.

For some people notepad++ might do. Of course you already know about CUT, COPY and PASTE (CTRL-X, CTRL-C and CTRL-V). I also recommend at least learning the CTRL+LEFT-ARROW and CTRL+RIGHT-ARROW combinations to jump between words. Or to hold SHIFT while navigating around to select text. I regularly use SHIFT-HOME and SHIFT-END to select a piece of text from my cursor-position to the end of a line. (All these key-combinations work in most Windows/OSX-programs).

But what if you want to center text? Or want your text automatically cut off at 80 characters and reformat your paragraphs? Have you ever seen an undo-feature that is so powerful it visualizes your whole editing history in a tree : https://www.emacswiki.org/emacs/UndoTree?

Of course learning a decent text-editor takes some time but this process can be very fun and engaging. Customizing and personalizing your editor takes even more time but here spacemacs comes to the rescue!
Only after some time-investment, you will start to realize what an improvement a customizable editor (and perhaps vim's normal-mode) can make!

These editors are so powerful that many programmers prefer them above complete IDE's like Visual Studio or Eclipse. Some people seem to like SublimeText but that one comes with all the downsides of closed software.

Some words about vim

Modal editing

When you start up vim (for example vi myfile.md from a Linux-shell), you are in normal mode which allows you to navigate around without moving your hands from the typing area of your keyboard : the cursor keys are replaced with j, k, h and l. If you want to insert text, you have to enter insert mode with i. To leave insert mode, you press ESC (or, as many power-users do, in your .vimrc-file you make a binding to a key-combination like fd or jj so you have to move your hands even less - since reaching for that <ESC>-key slows you down - yes, we are that puristic).

The first step to vim-mastery is realizing that normal mode is your main mode and you start to use commands to jump from word to word (w, b, e), sentence to sentence ((, )) and paragraph to paragraph ({, }).

The second step is that you start to use commands like cw (change word) to replace one word, or the mighty powerful ct. (change till next .) which allows you to change anything from the current cursor position until the first ..

Then there are also macro's you can record with q and execute with @. The .-command repeats your last command. I regularly use this to quickly put a - in front of a bunch of words, to create a list.

Check for example this talk if you want to see some of it in action.

Plugins

The next level of vim-mastery you will reach with plugins.

As a developer I've found https://github.com/tpope/vim-commentary to be indispensable : selecting a piece of text (in visual mode) with v and then pressing gcc puts code in comments (depending on which programming language you're working in).
Also https://github.com/tpope/vim-surround has at many occasions drastically improved my workflow : with a few keypresses I am able to surround a piece of text with characters like (, ", ' and even to quickly change something surrounded with ' to ".

And then one day I tried https://github.com/dhruvasagar/vim-table-mode which really got me realizing how much power vim has. It goes as far as to basically have a mini-Excel (with ascii-art tables) inside your text-editor!
In fact, It was a simple mail to the author of this plugin from which I learned the inspiration for it had come from emacs' org-mode. For me this ultimately led to the discovery of http://spacemacs.org/ (more about this later).

Writing my own plugin

After some time I became quite proficient in editing/personalizing my .vimscript-file (or rather: using Vundle to install plugins and copy/paste some stuff from the README.md's into my own config) and got interested in learning a bit of vimscript myself. I soon discovered my time would be better spent learning some elisp in stead. Or rather: to achieve many more cool things, I wouldn't even have to learn vimscript but could just start using http://spacemacs.org/.

Emacs

I had tried emacs before (i.e. I did the included tutorial) but the modal-style of editing of vim still had my preference. (Vi being the de-facto standard editor on Linux-shells is how I got into it.) As I told you before it was org-mode (http://orgmode.org/) which renewed my interest in emacs. I played around with emacs for a few hours, configuring my .emacs.d-file as I had learned to do with vim. I stumbled upon this talk, which made me realize I had to give emacs a serious chance before deciding switching back to vim with its ugly vimscript :

Major- and minor-modes

Editing a buffer (a text-file) in emacs always happens with exactly one major-mode and many minor-modes active. The sole thing I want to tell about it here is that the major text-mode together with the minor auto-fill-mode already provided me with (pure emacs out-of-the-box!) functionality I had spent quite some time fine-tuning on vim. This was my first +1 for emacs.

Another +1 is the help-system and how it automatically shows which keybindings a command has, even if you have changed it in your .emacs-file. In standard emacs (and also in spacemacs, since it is largely compatible) you can press CTRL-h k followed by a key-comination to learn about the command attached to that key combination.

I like that to learn emacs, I can spend most of my time inside it and only occasionally have to ask Google for help.

Org-mode

And so we arrive at one of the killer-plugins of emacs, especially if you are a TODO-list fanatic : the major org-mode.
This talk gives you one of the best overviews of what's possible, by the creator of org-mode himself (meanwhile showing that emacs can also be a life-saver for computer-users with bad vision):

After this, I also got to know GTD (http://gettingthingsdone.com/) which basically teaches you how you have been managing your TODO-lists the wrong way all-along...

Enter spacemacs

Personally I found it rather enjoyable to look for emacs-plugins, configure my .emacs.d-file and then testing some new feature my text-editor had just gotten. I learned about many interesting plugins which were all easily installable as MELPA-packages from inside emacs : try ALT-x (or M-x as emacs-users call it) with which you can execute any command and then execute package-list-packages which gives you an idea how many plugins you can install.

It was in my quest for interesting packages that I stumbled upon the main topic of this post : http://spacemacs.org/. All of a sudden I am now not looking for new packages, but rather learning about the packages the spacemacs-team chose to include. So far I am loving their choices and it became clear to me that emacs really is a superior editor. It's a bit harder to find good documentation about the spacemacs-configuration of some packages specifically, since you will often find the pure-emacs-version first. That said : with a bit of google-fu and a lot of exploration inside spacemacs itself, I'm sure you too will find some killer-feature! It is a quest I'm currently very much engaged in...

In my .spacemacs.d-file I have so far activated several amazing spacemacs layers : git, markdown, autocomplete not to mention some of the programming layers. Besides those layers, I have not yet felt the need to configure much since the spacemacs-defaults are mostly very good. One minor problem with the default configuration for me is that fd is the standard key-combination to exit evil-insert-mode, which happens to be a character-combination which is common in my mothertongue (Dutch) and therefore occasionally annoys me when writing text in Dutch. I have yet to change it to jj which I prefer. The little vimscript imap jj <ESC>l used to be the first thing I added to an empty .vimrc-file. After the discovery of spacemacs, I wonder if I will still use vim often enough to make it worthwhile to add this basic vim-configuration when (and if!) installing it on a new system.

Emacs as your only tool?

It is said that emacs is not so much a text-editor as it is a complete working environment, even an OS. I don't see it that way yet.

I was pleasantly surprised with the included IRC-package (erc) and LaTeX-editing and -previewing is something I haven't seen any other text-editor do. It renders me hopeful that Emacs 25 (not out yet) will even let me (graphically) browse the web : https://www.reddit.com/r/emacs/comments/4srze9/watching_youtube_inside_emacs_25/.

That said, these days I still use a lot of other tools like FAR manager (http://www.farmanager.com/) with its built-in editor (which is just a F4-press away) for a lot of quick modifications. It remains to be seen if spacemacs with it's HELM file-browser will make me (partially) change this workflow in the foreseeable future.

For Windows-users that want to have the joy of having something like Ubuntu's sudo apt-get installto install software, I recommend https://chocolatey.org/packages which is how I install most of my Windows-tools. Unfortunately spacemacs isn't included there yet.

I also recommend ConsoleZ (https://chocolatey.org/packages?q=consolez) for an improved shell on Windows.

Installation

To conclude, let me quickly get you up to speed on how to try it yourself on Windows.

First of all : install emacs itself. For Windows I would recommend https://sourceforge.net/projects/emacsbinw64/.
On my Xubuntu 14.04 I found that the 24.3 version in the apt-repository was a bit outdated, so I compiled my own from source. I believe OS X users can use brew.

Next you will have to install spacemacs, which basically means you have to git clone the spacemacs-repository in the emacs-configuration-directory .emacs.d. You can read about it here : https://simpletutorials.com/c/2758/How+to+Install+Spacemacs+on+Windows

I would recommend installing chocolatey (mentioned above) to quickly install git (with choco install git).

After the first launch you will be asked if you want evil- or emacs-mode. If you already know a bit of vim, I recommend evil-mode. If not, perhaps you should first install vim (or gvim) (choco install vim) and do :h to do a very basic vim-tutorial. Of course there is heaps of vim-learning-material on the web, as it is currently a very popular editor, especially for developers using OS X or Linux.

But remember: once you start modifying your vim-configuration, perhaps it's better to try spacemacs instead!

Happy hacking!

Sort:  

dayum son...

Very interesting! I like it! Good Luck To You!

Coin Marketplace

STEEM 0.37
TRX 0.12
JST 0.040
BTC 70162.45
ETH 3540.43
USDT 1.00
SBD 4.79