How to be productive with almost any text editor

What makes us productive when working with code in the editor? Every day, there is a new shining plugin, that allows us to do something useful by pressing only 2 keystrokes. Don’t get me wrong, I’m not against plugins. Hell, I have at least 40 of them (https://git.io/vrg64).

But, are all of them equally useful? I am certain that some tricks outperform others in terms of productivity (20% results in 80% boost). These could be features, built into the editor. You just don’t know about them. Here, I’ve tried to collect the most important ones, which don’t require you to read a pile of docs and much time to learn.

There is no research (not to my knowledge) to backup the list below. If you think I missed something, leave a comment or two.

In addition, I’ve compared the 5 most popular editors (vim, emacs, idea, sublime text and atom). I hope it will be interesting for you to see how your editor is doing relative to others.

Your humble servant is using Vim at his regular job, so you may notice a certain predisposition. But I try to be open - the second attempt to master Spacemacs? https://github.com/google/xi-editor ? Who knows..

1. Fast switching between the last two files

Editor Mapping
Vim nnoremap <leader><leader> <C-^>
———— ——————————————————-
Emacs (global-set-key (kbd "M-o") 'mode-line-other-buffer)
———— ——————————————————-
Idea Ctrl + Tab / Ctrl + Shift + Tab
———— ——————————————————-
Sublime Text Ctrl + Tab / Ctrl + Shift + Tab
———— ——————————————————-
Atom Ctrl + Tab / Ctrl + Shift + Tab

Emacs:

Idea:

2. Running tests without leaving the editor

Editor The way
Vim https://github.com/janko-m/vim-test
———— ——————————————————————–
Emacs no uniform interface, but there are packages for different languages
———— ——————————————————————–
Idea through the UI plus Ctrl + R to restart
———— ——————————————————————–
Sublime Text no uniform interface, but there are packages for different languages
———— ——————————————————————–
Atom no uniform interface, but there are packages for different languages

Emacs:

Idea:

Sublime Text:

Atom:

3. Terminal emulator

Editor Terminal emulator
Vim no
————————- ——————————————
Neovim yes
————————- ——————————————
Emacs yes
————————- ——————————————
Idea yes
————————- ——————————————
Sublime Text yes
————————- ——————————————
Atom yes

Note on terminal text editors

You can easily switch to the actual terminal using Ctrl + z (this will suspend the editor) and get back by entering fg. However, I would say that it is not the same as having a terminal emulator running in an editor’s window below. The reason is simple - context. Most often, you’ll want to look at the output of some command and the code at the same time. For example, seeing an error’s stack trace and the code at the same time is far better than performing these actions in turn (you could easily forget the exact line number or some other detail).

If you don’t want to type fg, there is a hack:

zsh: https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/fancy-ctrl-z/fancy-ctrl-z.plugin.zsh

fish:

bind \ck 'if test -z (commandline) ; fg %; else ; clear; commandline ""; end'

Another advantage of having a terminal emulator: copy-pasting between the terminal emulator and your code is much easier, and you get completion in the code for things in the terminal (thanks to somebodddy).

Sublime Text: https://packagecontrol.io/packages/Terminal

Atom: https://atom.io/packages/term3

4. Go to definition

Editor Mapping
Vim Ctrl + ] / Ctrl - T using ctags
———— ——————————————————-
Emacs M-. / M-* using ctags
———— ——————————————————-
Idea Ctrl + B or Ctrl + click / Ctrl + Tab
———— ——————————————————-
Sublime Text Ctrl + click / Ctrl + right click
———— ——————————————————-
Atom Ctrl + Alt + down / Ctrl + Alt + up

Emacs:

Sublime Text: https://gist.github.com/kendellfab/6135193#gistcomment-1768760

Atom: https://github.com/atom/symbols-view

Generating tags using git hooks: http://tbaggery.com/2011/08/08/effortless-ctags-with-git.html

5. REPL (Advanced)

If you have a REPL alongside the editor - excellent! You can eval some code or lookup some documentation (http://tonsky.me/blog/interactive-development/).

Editor REPL
Vim yes (few languages)
———— ——————————————————-
Neovim yes (many languages)
———— ——————————————————-
Emacs yes (many languages)
———— ——————————————————-
Idea yes (many languages)
———— ——————————————————-
Sublime Text yes (many languages)
———— ——————————————————-
Atom yes (few languages)

Vim:

If language has a command-line REPL, you can always execute: :!<repl> (e.g. :!irb).

Neovim: https://github.com/kassio/neoterm

Emacs:

Idea:

Sublime Text: https://packagecontrol.io/packages/SublimeREPL

Atom:

The end list

  1. Fast switching between the last two files
  2. Running tests without leaving the editor
  3. Terminal emulator
  4. Go to definition
  5. REPL (Advanced)

3 and 5 could be alternatively solved using a terminal multiplexer. For example, my favorite https://tmux.github.io/ .

Bonus

  1. Do not repeat yourself ("." in Vim, macros [atom - https://atom.io/packages/atom-keyboard-macros])

  2. Operate on objects: blocks, functions, etc., not individual characters (motions and text objects https://github.com/kana/vim-textobj-user/wiki in Vim)

  3. Quickly navigate through code using AceJump-like plugins

My current use of vim-easymotion reduced to only one https://git.io/vrzAE mapping that allows me to jump to any location in the current file. Simple and effective!

  1. Use multiple selection/cursors
  1. Open files using fuzzy search

Conclusion

As you can see, each of the editors does the job. Some slightly better, others

Another finding: Vim is best suited for polyglot developers (http://searchsoftwarequality.techtarget.com/definition/polyglot-programming) because it provides plugins and unified interface for multiple languages. Emacs offers more power, but you need to configure all the packages to make mappings the same. It may be a good idea for Spacemacs, is it?

Useful links:

Did I miss something? You can leave a comment or send me an email.

Comments

comments powered by Disqus