5 Vim productivity tips to improve your workflow
Tags: vim
Published: 2019-10-15 17:47:56

## 1. Remap the leader key to the space bar

```viml
let mapleader      = ' '
```

It might look strange, but think about how little you use it on normal mode. The space bar is a pretty accessible key on your keyboard and it will reduce your pinky pain.

## 2. Use `Localvimrc` to customize your vim per project

{% github embear/vim-localvimrc %}

I have lot of customizations for Vim, but making them work on each and every project I work is nearly impossible. For example for JavaScript/TypeScript. In some projects I just use plain JS, in others JS with Flow, in others TypeScript but a bit of plain JS too... and setting up vim with specific linters, shortcuts, etc for each one of them is painful.

Besides that, sometimes I don't want to make certain configurations public, so adding them to my public dot-files is not an option. 

With this plugin you can easily (and more or less safely) keep those configurations scoped to the projects where you need them.

## 3. Spell check your markdown and git commits

```viml
augroup setSpelling
  autocmd!

  autocmd FileType gitcommit setlocal spell spelllang=en_us
  autocmd FileType markdown setlocal spell spelllang=en_us
augroup END
```

If (like me) you're not a native English speaker it is even more helpful to have spell checking. This simple piece of config will spell check your git commit messages and the markdown you write.

Remember when Vim marks a spelling issue you can see the available options with `z=`. You want to know more about spelling? Check `:help spell` on Vim.

## 4. Use mnemonics for your shortcuts

I have a lot of shorcuts on Vim. Remembering them all is impossible. I group them with mnemonics which are simpler to remember. For example, all my git related mnemonics are grouped under `<leader>g` so `<leader>gs` means `:Gstatus`. Most are obvious, but I've added some comments where not.

```viml
nnoremap <leader>gs :Gstatus<CR>
nnoremap <leader>gc :Gcommit<CR>
nnoremap <leader>gC :Gcommit -n<CR> " commit but ignore hooks
nnoremap <leader>gP :Gpush<CR>
nnoremap <leader>gfP :Gpush --force-with-lease<CR>
nnoremap <leader>gp :Gpull<CR>
nnoremap <leader>gf :Gfetch<CR>
nnoremap <leader>gl :GV!<CR> " Git log for the current file
nnoremap <leader>gL :GV<CR> " Full git log
nnoremap <leader>gd :Gvdiff<CR>
nnoremap <leader>gb :Gblame<CR>
nnoremap <leader>gm :Git checkout master<CR>
nnoremap <leader>g- :Git checkout -<CR>
nnoremap <leader>grm :Grebase -i master<CR>
```

BTW, If you are interested those 2 use fugitive and gv

{% github tpope/vim-fugitive %}
{% github junegunn/gv.vim %}

From 2 of my favorite vim plugin authors. [Tim Pope][tpope] and [Junegunn Choi][junegunn]

## 5. Learn how to navigate the help.

Vim's help is great. Not only that, most plugins you install come with a very well crafted help. Understanding how to navigate it makes your life easier. It is pretty easy:

* `:help` to see the global vim help (yeah, that's pretty obvious)
* `:help command/topic/shortcut` to see its help. E.g. `:help :Gstatus`, `:help CTRL-W` or `:help sort`
* You'll see some words on the help are highlighted. Those are links and you can follow them with `CTRL+]`. If you want to go back to where you were you can use `CTRL+o`
    ![Link tag on vim help](https://thepracticaldev.s3.amazonaws.com/i/rfe9aig6mzcy0p2ie5wi.png)

## Bonus: You don't know what you don't know...

Let me explain that: Vim can do A LOT, you don't know how much (and neither do I). The only way to do it is to research and play with it. Many of the things I do on my `.vimrc` come from other people's dotfiles.

There are literally thousands of dotfiles out there, people shares them (I do share mines!). If you are interested on improving your Vim's workflow go check them. Find famous Vim authors and check what they do. You'll be amazed on how much you will learn!


[tpope]: https://github.com/tpope
[junegunn]: https://github.com/junegunn