(Should you) Get started with vim

It’s all about editing text

The world of text editors is very hostile from what I’ve experienced so far. You might’ve heard discussions surrounding what to use — vim, emacs, notepad, VSCode and all the other choices. I enjoyed using VSCode during my time in college. I still remember it was something new that had come out then and I enjoyed using it a lot. So why am I writing about vim now?

Why did I choose vim?

It was in a CS Lab in college when I first ran into vi. I was on a Fedora Machine and a git commit put me into vim (Ctrl + C :wqis how you quit vim by the way). For some reason, the cryptic UI was fun to use. Ever since then, I have enjoyed it. Well, it’s improved version vim.

So should you? Use vim?

Short answer, yeah, why not? Give it a try.

Getting started with vim

When I got serious to get into vim, I didn’t realise how less clear guides were there to get started. Albeit, I was looking for how to use vim as a code editor and not a general text editor. But let’s be real, vim doesn’t really make sense as a general text editor for me.

The absolute absolute basics

  • Opening a file in vim — vim <path-to-file>
  • Tap i to insert text
  • Now write whatever you want
  • To exit, Ctrl C :wq

Plugin Manager

So, the first thing I started to look for is a package manager, or a plugin manager as it’s in the vim world. Plugins add a lot of extra features. I ended up using Vundle.

git clone <https://github.com/VundleVim/Vundle.vim.git> ~/.vim/bundle/Vundle.vim

.vimrc

Just like everything else in the shell, vim has its own rc file which we can use to customize it to our needs. Because vim is all about getting to my development environment as fast as possible, I have put my .vimrc file up on github — https://github.com/cli-config/cli-config/blob/main/profiles/mrsauravsahu/.vimrc

Tabs v spaces

I like to use spaces because it is consistent across machines & I use 2 spaces. That’s what the following snippet does (it should also be in .vimrc)

" use spaces instead of tabs
set tabstop=2 shiftwidth=2 expandtab

Time for some plugins

Because I have Vundle setup now, I can install some plugins. Here’s the entire .vimrc

syntax onset number" use spaces instead of tabs
set tabstop=2 shiftwidth=2 expandtab
" git clone <https://github.com/VundleVim/Vundle.vim.git> ~/.vim/bundle/Vundle.vim
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'bling/vim-airline'
Plugin 'prabirshrestha/vim-lsp'
Plugin 'mattn/vim-lsp-settings'
Plugin 'prabirshrestha/asyncomplete.vim'
Plugin 'prabirshrestha/asyncomplete-lsp.vim'
Plugin 'junegunn/fzf'
Plugin 'junegunn/fzf.vim'
Plugin 'ledesmablt/vim-run'
Plugin 'dense-analysis/ale'
Plugin 'hashivim/vim-terraform'
call vundle#end()
" show spaces
set listchars=trail:·,lead:·
set list
" SHORTCUTS" vim-run
nnoremap <silent> <C-x> :Run
" formatting
nnoremap <silent> <C-k><C-d> :gg=G <CR>
" fzf.vim
let fzf_default_command='find -L'
nnoremap <silent> <C-l> :Files <CR>
nnoremap <silent> <C-p> :GFiles <CR>
" UNUSED PLUGINS -- for now
" Plugin 'scrooloose/nerdtree'
" nnoremap <leader>n :NERDTreeFocus<CR>
" nnoremap <C-n> :NERDTree<CR>
" nnoremap <C-e> :NERDTreeToggle<CR>
" nnoremap <C-f> :NERDTreeFind<CR>

Brief about Modes

vim uses modal editing. Keys behave differently in different modes. The modes are — normal, insert, command.

  • Insert — You’re inserting/editing text in the file
  • Command — Shortcuts you can execute to help your workflow (most of these are defined, and you can create your own too)

Shortcuts

  • Ctrl P - When in normal mode - this will show you files in the current directory’s git repo - Fails if not in a git repo. This helps to not pollute the list with ignored files in git.
  • Ctrl L - When in normal mode - this shows all files in the current directory
  • gg - Go to top of the file
  • Shift G - Go to end of file
  • $ - Go to end of current line
  • 0 - Go to beginning of current line

Commands

  • :! <command> - Run a command in your $SHELL
  • :sh - Put vim process in background and go back to your shell. exit the shell to get back to vim

Conclusion

Clearly, vim has a lot of things going for it but also comes with a pretty steep learning curve. It might fit your needs or you might learn some new things in the shell. I’ve been having fun and trying to learn vim by using it on a daily basis.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Saurav Sahu

Saurav Sahu

Opinions are my own. Full Stack Engineer. CEO of “it was just working 🤷‍♂️”