the only 5 vim plugins i need
Tags: vim, neovim, webdev, productivity
Published: 2020-05-19 01:56:19

I've been hooked on vim for the best part of 18 months now, and earlier this year I decided it was time to step away from my comfort of using the [ultimate vim](https://github.com/amix/vimrc) setup and make my own.

At the end of the day, most users won't touch half the features that come with a pre-configured setup that big, and it turned out I could strip what I actually used from it into my own vimrc fairly easy.

Whilst I have more than just the plugins below, these are the 5 I use the most frequently.

### 1. vim surround
{% github https://github.com/tpope/vim-surround no-readme %}
Vim doesn't come with everything out of the box, part of the reason we love it. As simple as it is, vim surround makes editing code a breeze. How many times have you been in some js and realised you needed string interpolation? Vim surround makes this easy, simply press 
```cs"` ```

You can even change HTML tags with
``` cst<div> ```

### 2. vim commentary
{% github https://github.com/tpope/vim-commentary no-readme %}
Tpope is at it again - vim commentary is another simple plugin that just makes life easier. 

Want to comment out the 5 lines below in the correct format for the file you're in? Easy -

``` gc5j ```

The only one I've had some issues with is typescript & react, and for that i've just written the below in my vimrc
```autocmd FileType javascript,javascriptreact,typescript,typescriptreact setlocal commentstring={/*\ %s\ */}```


### 3. emmet vim
{% github https://github.com/mattn/emmet-vim no-readme %} 
Spending more time on front-end code recently has made me appreciate emmet even more. It's just one of those plugins you have to have in a code editor. 
``` div.test>li.item*2 ```
Will simply resolve to
```<div class="test">
  <li class="item"></li>
  <li class="item"></li>
</div>```

### 4. coc.nvim
{% github https://github.com/neoclide/coc.nvim no-readme %}
That's right, I've left the best for last. Jump around files like it's no ones business with some simple key mappings, and have code suggestions/autocomplete in almost any language.

```:coc-install coc-tsserver``` and you're set up for javascript, giving you the best autocomplete you've seen. Ruby LSP? Easy, just 
```:coc-install solargraph```

![TSSever](https://dev-to-uploads.s3.amazonaws.com/i/de99t2d6a7s1brritp5l.png)
![Solarwind](https://dev-to-uploads.s3.amazonaws.com/i/hvpc9dupacq3reo0w8u0.png)

There is even an LSP for TailwindCSS which I've been enjoying using recently, no more visiting the website every time you forget a classname!

![TailwindCSS](https://dev-to-uploads.s3.amazonaws.com/i/x55uo3f18nxfczh4m55x.png)

One of the best things about vim is the movement - Not only does coc provide amazing autocomplete, but it just takes movement to the next level.

Add a few bindings to your vimrc and from JS imports, classes or methods in Ruby, whatever you want.

```
nmap <buffer> <leader>gd <Plug>(coc-definition)
nmap <buffer> <leader>gr <Plug>(coc-references)
```
Go to the definition with your binding, and use vims built in [jumping](https://vim.fandom.com/wiki/Jumping_to_previously_visited_locations) to get you right back where you were, no time wasted at all!

### 5. fzf
{% github https://github.com/junegunn/fzf no-readme %}
If you haven't used fzf yet, you're going to be blown away. I've been using FZFs file searching in a project that has been developed for over 10 years and FZF still proves its, as they put themselves, blazingly fast.

I add some simple keybinds for easy access
```
nnoremap <C-T> :Files<cr>
nnoremap <Leader>b :Buffers<cr>
nnoremap <Leader>s :BLines<cr>
```

And after that, it's smooth sailing. You even get a cool preview window!
![Fzf](https://dev-to-uploads.s3.amazonaws.com/i/zsbj2ea6d8ek5jwvpoqg.png)

FZF and [RG](https://github.com/BurntSushi/ripgrep) makes search a project easier than it's ever been.

# Conclusion
Sitting down and writing my own vimrc, taking my favourite parts from different repositories and customising them took time, but has proved to be priceless. 

As with anyone who uses vim will tell you, there is always more to learn, and that's what I love about it.

If you want to check out my dotfiles, you can see them below.
{% github https://github.com/haydenrou/dotfiles no-readme %}
Thanks for reading :)