My transition from expensive IDEs to VIM (+ VIM Cheatsheet)

Posted on Mar 1, 2019

Update: Transition to Neovim

TLDR: Windows Me uses IDEs from day one. Thought command line tools were a thing of the past. Grown up freelancer Me switched from expensive but great RubyMine to free VIM setup.

Since my very beginnings with unix-like operating systems I always used vim to edit files on the command line. I don’t know why but I never used emacs. Back then I was proud to know how to open a file, do some changes and save it. (After googling how to exit vim for 100 times, you start to remember it)

Back in 2008 my career as a web developer started with php projects. PHPEdit was the very first IDE I used on a regular basis. Like many people who started programming in that time, I was used to write my php files in Notepad++ and upload them onto my freehost to test them. PHPEdit automatically uploaded my changed files to my server, checked my code’s syntax (and did what most IDEs do) but it felt like pure magic to me. Every time I ssh’ed to a remote machine to edit some files, I had to google every single command but whenever I managed to use vim (with the expected results), I was impressed at what can be accomplished with command line text editors. Since I grew up with windows I always thought of terminals of a thing of the past. (My 13 yo self: “Oh that’s how people edited files back when they had no GUIs!”) I was so wrong …

Nowadays I would describe myself as a ‘terminal’ guy. brew, zsh and oh-my-zsh are the very first things I install on a fresh osx installation.

During my full-time jobs I always manged to get my hands on a set of pretty nice tools. One of them was RubyMine. I used it for several years and I loved it. IDEs for dynamic languages like Ruby are hard to do but RubyMine definitly mastered it. When I quit my job and started freelancing, money was short, so I didn’t want to spend money on licenses. That’s when I started using vim as my daily driver for web development projects (Rails, Elixir, React, Vue, AngularJS, …).

Mostly, I’m happy with my vim setup, but I still have some issues (of more generic nature).

Vim Setup

GUI vim: MacVim
CLI vim: vim 8.1 (brew package)

" Theme
Plug 'altercation/vim-colors-solarized'

" Completion
Plug 'Shougo/deoplete.nvim'
Plug 'roxma/nvim-yarp'
Plug 'roxma/vim-hug-neovim-rpc'

" Elixir
Plug 'elixir-editors/vim-elixir'
Plug 'https://github.com/slashmili/alchemist.vim'

" JS
Plug 'pangloss/vim-javascript'
Plug 'leshill/vim-json'
Plug 'mxw/vim-jsx'
Plug 'ternjs/tern_for_vim'
Plug 'mustache/vim-mustache-handlebars'

" Syntax check
Plug 'w0rp/ale'

" Files
Plug 'scrooloose/nerdtree'
Plug 'Xuyuanp/nerdtree-git-plugin'

" Status Lines
Plug 'bling/vim-airline'
Plug 'airblade/vim-gitgutter'

" Git stuff
Plug 'tpope/vim-fugitive'

" Vue
Plug 'posva/vim-vue'

" Fuzzy Search
Plug 'ctrlpvim/ctrlp.vim'

" Autocompletion of { blocks
Plug 'jiangmiao/auto-pairs'

" Autocomplete begin end's
Plug 'danieljaouen/vim-endwise'

TODO

Cheatsheet

Prepend text to selection covering multiple lines

  • Navigate to the first line
  • Move cursor to the first character before the text should be prepended
  • CTRL+v to start visual block mode
  • Use j, k or something similar to select every character which should get prepended
  • Hit I to start insert mode (insert before cursor)
  • Write text
  • Hit ESC
  • The change you did on the first line should be replicated over your whole selection

Append text to the end of multiple lines

  • Navigation to the first line
  • CTRL+v: start visible block mode
  • Use j, k or similar to have at least one block in every line (that you’d like to change)
  • Hit $ to extend selection to the end of every line
  • Hit A to start insert mode (insert at the end of the line)
  • Write text
  • Hit ESC

Repeat last change

Quick delete words: dw...

Select from cursor to end of line: CTRL+v $ (try d afterwards)

Select from cursor to end of line (without selecting invisible newline character): CTRL+v g_

Delete everything between cursor and end of line (without newline) and repeat for distant other line

  • CTRL+v g_
  • d Delete
  • Navigate to other line
  • . repeat same delete call on that line

Replace text ‘Peter’ with ‘Christina’ in whole document: :%s/Peter/Christina/g

Replace text ‘Peter’ with ‘Christina” in selection:

  • Select blocks: CTRL+V jj
  • :(vim should automatically add something to the command line)
  • continue typing: s/Peter/Christina/g