Vim the Ultimate Editor

Vim the Ultimate Editor

VIM editor is one of the most beloved, but often misunderstood editors in existence. Let’s configure it from a noobs perspective and show you it’s power.

Why VIM?

There is so many things to learn about VIM, but before we start the question often pops up why not just use VS Code or IntelliJ?

VS Code and IntelliJ have some fantastic ease of use, and great debugging capabilities. There is extension support to add some amazing functionality. So why do many programmers still use VIM? one word: SPEED!

There is nothing that can even compare when it comes to speed from a veteran VIM user. They will blaze through code at the speed of light and change so much on their screen that you will have a hard time following just watching it. Don’t believe me? Just watch ANY “The Primeagen” videos

So if it’s so fast why don’t most people use VIM? It’s hard and has one of the biggest learning curves that I have ever seen from any program. It will take YEARS to master, months to be better than vs code/intellij editors, and weeks of learning to be comparable to any other editor on the market.

However, the payoff is beyond worth it to me. The reward feels so good when you start to get it. The big thing… you can throw your mouse away, because when you get it… a mouse is no longer needed.

Beginning steps

The very first thing you need to know about vim is the modes.

  • Normal Mode - The default mode you enter into on launch. This allows quick movement, exiting, commands, but you don’t “type” in this mode.
  • Insert Mode - Pressing i on your keyboard will allow you enter insert mode. This allows you to type text and keyboard input to the open file.
  • Visual Mode - Pressing v on your keyboard will put you in visual mode. This allows you to highlight and use commands on highlighted syntax.

Note: You can escape Insert and Visual mode to go back to Normal mode with esc key

The other MEME you will always see about vim is you can’t exit it… just turn your computer off. Haha, but seriously exiting vim is probably my favorite thing and that brings us to the first thing to remember:

“If something is slow in vim, there is a way to do it faster in vim”

The official way to save and quit vim is to press the following in normal mode: :wq or faster :x or even faster ZZ

To quit without saving: :q! or faster ZQ

VIM Cheatsheets:

Learning the basics

Now that you can actually function inside of vim, you might be thinking… “How in the hell do elite programmers use this damn program so fast?”.

Movement and muscle memory are the biggest things with vim. It’s not just knowing the keys, but using them without thinking. This may seem impossible, but the more you practice the better you will get.

You may have heard of vimtutor which walks you through the basics of vim. However, I’d encourage you to treat it like speed runners of your favorite video game. Run vimtutor as often as you can and treat it like a video game. How fast can you run it? Can you beat the old time? Can you complete the entire thing for the first time?!

This is where you will pick up the speed. Between the constant cheatsheets and running vimtutor as often as possible.

Other tips are moving as much of your workflow into vim as possible and customizing it to YOUR needs. Don’t just copy and paste some vimrc file your favorite programmer uses… it’s made for that person NOT YOU!

Making VIM your own

It is time to elevate your game to the elite status and making your own .vimrc file. This is where you make it feel awesome, even if you still suck at using vim. It’s important that you make vim feel good as this will make you want to continue using it.

I’ve been using VIM for a month and this is my .vimrc file. I use a lot of plugins, themes, and just a few hotkeys. This isn’t what an experts .vimrc file looks like, as I still consider myself just now leaving the beginner stages into an intermediate user. As time goes on I will expand this file by adding more shortcuts and better hotkeys.

Source: https://github.com/christitustech/myvim

" Plugin Loading
call plug#begin('~/.vim/plugged')
Plug 'itchyny/lightline.vim' "Highlights lines
Plug 'joshdick/onedark.vim' "The One Dark Theme
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim' "Fuzzy find plugin
Plug 'junegunn/goyo.vim' "Removes Line numbers for focusing
Plug 'mbbill/undotree' "Creates an undo tree
Plug 'preservim/nerdtree' "File browser inside vim
Plug 'godlygeek/tabular' "Auto formatting
Plug 'plasticboy/vim-markdown' "Markdown syntax highlighting
Plug 'wakatime/vim-wakatime' "Wakatime tracker
Plug 'ryanoasis/vim-devicons' "Cool icons for nerd tree
Plug 'Xuyuanp/nerdtree-git-plugin' "nerd tree customization
Plug '907th/vim-auto-save' "auto saves files as you edit
Plug 'jdhao/better-escape.vim' "remaps esc key to jj
call plug#end()

" Startup Settings
	syntax on
  let mapleader=" " "Maps Leader to space
  let NERDTreeShowHidden=1
  let g:auto_save = 1
  let g:auto_save_events = ["InsertLeave", "TextChanged"]
  let $FZF_DEFAULT_COMMAND = 'fdfind --type f --hidden --follow --exclude .git --ignore-file ~/.ignore'
  set mouse=a "Allows mouse usage inside vim. Great for noobs.
  set clipboard=unnamedplus "Remaps default copy paste to system clipboard
  set cursorline
  highlight CursorLine ctermbg=Yellow cterm=bold guibg=#2b2b2b
	set noerrorbells
  set splitbelow splitright
	set tabstop=2 softtabstop=2
	set shiftwidth=2
	set expandtab
	set smartindent
  set nofoldenable
	set nowrap
	set smartcase
	set noswapfile
	set nobackup
	set incsearch
	set history=5000
	set nocompatible
  set number relativenumber
  colorscheme onedark 
  set background=dark
  set termguicolors
	filetype plugin on
	set encoding=utf-8
	set wildmenu
	set wildmode=longest,list,full
	set laststatus=2
	if !has('gui_running')
	  set t_Co=256
	endif
	autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
	set spell spelllang=en_us

" Plugin Shortcuts
	map <Leader>f :NERDTreeToggle<CR>
	map <C-\> :Goyo<CR>
  nnoremap <F5> :UndotreeToggle<CR> :UndotreeFocus<CR>
  nnoremap <C-f> :Files!<CR>
  nnoremap <Leader>l :Tabularize /
  let g:better_escape_shortcut = 'jj'
  let g:better_escape_interval = 250

" General Shortcuts
  nnoremap S :%s//g<Left><Left> 
  nmap <Leader>r :w<CR>:so %<CR>
  map <Leader>e $

" Persistent_undo
	set undodir=~/.vim/undodir"
	set undofile
	let g:undotree_WindowLayout = 2

" Tabedit keybinds
  nnoremap <Leader>1 1gt<CR>
  nnoremap <Leader>2 2gt<CR>
  nnoremap <Leader>3 3gt<CR>
  nnoremap <Leader>4 4gt<CR>
  nnoremap <Leader>5 5gt<CR>
  nnoremap <Leader>t :tabnew<CR>
  nnoremap <Leader>c :tabclose<CR>

" Markdown Edits
  let g:vim_markdown_autowrite = 1
  let g:vim_markdown_no_extensions_in_markdown = 1
  let g:vim_markdown_conceal = 0
  let g:vim_markdown_override_foldtext = 0
  let g:vim_markdown_folding_disabled = 1
  let g:vim_markdown_new_list_item_indent = 0

" Markdown auto format tables
inoremap <silent> <Bar>   <Bar><Esc>:call <SID>align()<CR>a

function! s:align()
  let p = '^\s*|\s.*\s|\s*$'
  if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
    let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
    let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
    Tabularize/|/l1
    normal! 0
    call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
  endif
endfunction

" transparent bg
autocmd vimenter * hi Normal guibg=NONE ctermbg=NONE

Walkthrough Video