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
|Idea||Ctrl + Tab / Ctrl + Shift + Tab|
|Sublime Text||Ctrl + Tab / Ctrl + Shift + Tab|
|Atom||Ctrl + Tab / Ctrl + Shift + Tab|
2. Running tests without leaving the editor
|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|
- clojure - https://github.com/clojure-emacs/cider
- ruby - https://github.com/pezra/rspec-mode
- erlang - https://github.com/tjarvstrand/edts
- python - https://github.com/ionrock/pytest-el
- golang - https://github.com/nlamirault/gotest.el
- for some languages, you’ll need to configure Idea, e.g. golang - https://github.com/go-lang-plugin-org/go-lang-idea-plugin/wiki/Documentation
- ruby - https://github.com/maltize/sublime-text-2-ruby-tests
- python - https://damnwidget.github.io/anaconda/tests_runner/
- scala - https://github.com/jarhart/SublimeSBT
- ruby - https://github.com/moxley/atom-ruby-test
- elixir - https://github.com/indiejames/atom-iex
- (many) - https://atom.io/packages/script
3. Terminal emulator
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:
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
4. Go to definition
|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|
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/).
|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)|
If language has a command-line REPL, you can always execute:
- ruby - https://github.com/dgutov/robe
- scala - https://github.com/ensime/ensime-emacs
- clojure - https://github.com/clojure-emacs/cider
- clojure - https://cursive-ide.com/
Sublime Text: https://packagecontrol.io/packages/SublimeREPL
The end list
- Fast switching between the last two files
- Running tests without leaving the editor
- Terminal emulator
- Go to definition
- REPL (Advanced)
3 and 5 could be alternatively solved using a terminal multiplexer. For example, my favorite https://tmux.github.io/ .
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
- vim - https://github.com/easymotion/vim-easymotion
- idea - https://github.com/johnlindquist/AceJump
- emacs - https://github.com/abo-abo/avy
- sublime text - https://packagecontrol.io/packages/EasyMotion
- atom - https://atom.io/packages/jumpy
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
4) Use multiple selection/cursors
- vim - https://github.com/terryma/vim-multiple-cursors
- idea - F6 and the rest
- emacs - https://github.com/magnars/multiple-cursors.el
- sublime text - Ctrl + D
- atom - Ctrl + D
5) Open files using fuzzy search
- vim - https://github.com/junegunn/fzf.vim
- idea - Shift + Ctrl + O (https://www.jetbrains.com/help/idea/2016.1/navigating-to-class-file-or-symbol-by-name.html)
- emacs - https://github.com/bbatsov/projectile
- sublime text - Ctrl + P (http://docs.sublimetext.info/en/latest/file_management/file_management.html)
- atom - https://github.com/atom/fuzzy-finder
As you can see, each of the editors does the job. Some slightly better, others - a little worse.
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?
Did I miss something? You can leave a comment or send me an email.