I Heart Vim
Inevitably, when learning to code and use your terminal, you will accidentally prompt Vim. As a complete novice, you may be startled. There is no way of exiting. You bang on the keyboards to no avail. For the past year, since learning to code, the only command I knew was `:q` to quit.
(Side note: My favorite thing about Vim is perhaps its outdated 1990s website).
My mentor Jayden encouraged me to learn Vim before the apprenticeship. I was able to muster a few commands, but was still hopelessly slow at the beginning. (I still am). But I was determined to not revert back to Sublime Text, so I trudged along. And I’m really happy that I did; I feel like I’m getting better everyday. There are times I try to exit out of Chrome by typing `:wq` or try to navigate my Medium post by hitting `w` to bypass words (oops). (I heard that you can use these commands with Gmail!). Essentially I have engrained Vim commands into my everyday interaction with the computer that the Internet feels a little dull without it. I’ve learned to really embrace it as a tool for efficiency and am trying to harness its power on a daily basis.
Here are some resources that were recommended to me:
- OpenVim — this feels very Mavis Beacon-like, but walks you through an interactive Vim tutorial.
- Vim Adventures — this was a promising adventure game, but I don’t think I understood the actual objectives of it and did not progress very far.
- Cheat Sheet — very helpful reference.
What helped was throwing myself into Vim. I learned a few basic commands and steadily grew my knowledge everyday (still am). After doing the above tutorials, I decided to write a story in my text editor. Inevitably, I made changes. Had to go back to a misspelled word. Had to copy and paste some text. Needed to figure out replace some words.
As a novice, it’s easy to be overwhelmed by the novelty of… well, everything. On top of learning how to use git and GitHub, you’re also learning to program and depending on what type of work you do, web development and frameworks and conventions. Vim can be an inhibitor to the learning process; it is yet another thing to learn how to use. I found that by doing something I’m very familiar with (writing a story and typing on a keyboard, at at pace of no less than 100 words per minute!), I channeled my energy into specifically learning one new thing.
Configuring Vim is also of the utmost important; you can edit your vimrc (type `vim ~/.vimrc`) for more legibility and practicality. (You may also want to install a Vim plugin manager, the ability to comment, and a file directory interface). I have yet to integrate these to my Vim, but have seen them in action. Here is what Vim profile looks like:
set number
set tabstop=2
set shiftwidth=2
set backspace=2
set expandtab
set smarttab
syntax on
set pastetoggle=<F2>
set smartindent
set incsearch
set ignorecase
set smartcase
set autoindent
set nohlsearch
set autochdir
set noswapfile
filetype indent on
filetype plugin on
By pairing with people, I’ve had the chance to exchange and share commands. So, if we’re pairing, introduce me to a new command or two! I’ll be eternally grateful for the lesson. My favorite and often used commands:
1 Splits screen horizontally to view multiple files
Of course, the brackets are not used; they're just a way to indicate what needs to be interpolated
:vsp [relative file path]2 Splits screen vertically to view multiple files
To navigate between these files, hold the control button and hit WW. :sp [relative file path]4 Finds and replaces characters
:%s/[old character]/[new character]/g5 Centers location of cursor to be in the middle of the page
I find that this helps with readability and seeing what comes before and after.
zz6 Goes to line number
This is my preferred method since you don't have to take your fingers of the keyboard and it's less keystrokes.
[num]G
(e.g. 10G + enter)7 Indents file
I love this one and it is tremendously useful!
gg=G
There is so much that can be done with Vim to automate typing, which is pretty amazing. I haven’t even touched the scripting language which allows you to perform basic functions akin to a programming language. Admittedly, I find myself unsure as to whether I am in insert mode and will often end up typing things in the wrong places. I’m not the savviest of users and it will be awhile before I feel completely at ease with how to do things. But the beauty of Vim is that you can deduce commands based on other ones. For instance, `$` jumps to the end of the line and `y` yanks or copies marked text. You can combine them (`y$`) to copy text from where the cursor is to the end of the line. Neat!
I remember gawking at people who have mastered Vim. All keystrokes, no mouse necessary. I once told a friend that once I learn Vim, I will know that I have made it. While that statement is up for debate, I do have to say: I feel like my programming skills, enhanced by Vim and my supportive mentors at 8th Light, can only go upward from here.