How I just start using vim
Tags: vim, tutorial, beginners
Published: 2019-12-26 11:11:26

Some years ago vim was for me an unreachable text editor for "real hackers" and I really had not any ideas how to use it and how it can be useful in the daily development.

But now I can't imagine other editor, because I have finally tame vim!

There are some steps which I have done before start using vim efficiently.

### Use "all fingers"

Before `vim` I had used only 4 or 5 fingers in the "blind mode" and when I have started practicing with ten-fingers input – text navigation with arrows became just uncomfortable for me.

It was key moment, when I began to think about migration to `vim`.

How I have started using all fingers? Just start do that. I have used some keyboard trainers, but only for adapt to keyboard layout. Type with all fingers, look at keyboard when you need that, but just try to use all fingers on right positions.

It took ~1 month for me before I stopped feeling discomfort.

### Complete `vimtutor`

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/c3jaswve7101e67zmzm6.png)

`vimtutor` is a educational program with basics of `vim` usage. Before it I had not any knowledge about navigation except `h`, `j`, `k`, `l` keys.

I highly recommend to complete `vimtutor` at the beginning, because it can give you a strong basement of vim usage in the future.

### Disable arrows keys

It is very important because I had a huge temptation to start using arrows in `vim`. Just disable them for acceleration of adaptation to the new navigation way.

```vim
" Disable arrows in visual and normal modes
map <Up> <Nop>
map <Down> <Nop>
map <Left> <Nop>
map <Right> <Nop>
" Disable arrows in input mode
imap <Up> <Nop>
imap <Down> <Nop>
imap <Left> <Nop>
imap <Right> <Nop>
```

### Use existing config

The first thing, which I knew about `vim` was possibility to customize editor for your own purposes.

I had already installed NeoVim and [vim-plug](https://github.com/junegunn/vim-plug) and with existing configs I have tried to reproduce my favorite features from past text editors in vim.

As example I took configuration of one local engineer [Sergey Golovin](https://github.com/daynin/dotfiles/blob/master/configs/init.vim). It includes all basic features which can be helpful at the beginning, because in future you will configure editor for yourself.

You also can try to use [my vim configuration](https://github.com/lamartire/dotfiles/blob/master/configs/init.vim), but I'm periodically changing it.

### Bring features from your favorite editor

So, I had a lot of troubles with understanding buffers, search and replace operations, navigation between files and at the first two weeks I had a strong desire to start using Sublime Text again.

But I have discovered tabs, some plugins for reproducing favorite features like fuzzy search or navigation between opened files.

There are some `vim` plugins "mapped by features":

* [fzf.vim](https://github.com/junegunn/fzf.vim)

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/g5bcg9znnfvof5cq8ywe.png)

`fzf.vim` provides project-wide fuzzy search, search between active buffers and etc. It can be customized.

If you want to exclude all files from `.gitignore` you should add to your `init.vim` following line:

```vim
let $FZF_DEFAULT_COMMAND = 'ag --hidden --ignore .git -g ""'
```

You can use other search utility, like [ripgrep](https://github.com/BurntSushi/ripgrep) instead `ag`.

* [ctrlp](https://github.com/kien/ctrlp.vim)

This plugin provides features similar to `fzf.vim`. I have used it at the first time but then have changed it to `fzf.vim` plugin.

* [ctrlsf.vim](https://github.com/dyng/ctrlsf.vim)

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/69gyqfqi5xoi6lykri0s.png)

I really like search in Sublime Text and `ctrlsf.vim` fully reproduce it in vim.

You can find something in project and change something right in results. It is really awesome, useful and visual.

* [nerdtree](https://github.com/scrooloose/nerdtree)

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/pdhn7fvsr93a48nsvfx6.png)

`nerdtree` provides visual navigation between project files and basic filesystem manipulations (create, delete, rename, move, etc.).

I'm using it with [vim-nerdtree-sync](https://github.com/unkiwii/vim-nerdtree-sync), because I want to see active file in project tree.

* [coc.vim](https://github.com/neoclide/coc.nvim)

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/dhgi1z4vnqrkn73uouot.png)

`coc.vim` provides autocomplete engine like VS Code to `vim`. It just works.

Before using you should install `neovim` npm package globally:

```shell
npm install -g neovim

```

It is using plugins system. For example, if you want to use `typescript` or `javascript` autocompletion, you should run `:CocInstall coc-tsserver`.

I'm using `tab` and `shift+tab` for navigation between completion items:

```vim
inoremap <expr><tab> pumvisible() ? "\<c-n>" : "\<tab>"
inoremap <expr><S-tab> pumvisible() ? "\<c-p>" : "\<S-tab>"
```

---

Plugins which I have described above are very useful for daily tasks, but you can find other plugins on [vimawesome](https://vimawesome.com/) or write your own with vim script (it is not so difficult).

### Survive the first two weeks

![Shot from "The Revenant" (2015) film](https://thepracticaldev.s3.amazonaws.com/i/6zzufe2a444t0fi6himh.jpg)

It is the most difficult step. Before that try to make basic `vim` configuration with all required features and then use that. If you meet with some problems – make note about that and then try to solve with plugin or just on configuration level.

If you are not ready to use `vim` as main editor – install keymap for your current editor and accustom with navigation and other features. It is much simpler for beginners.

### Conclusion

I have met with `vim` a lot of years ago and have thought that it is very difficult all this time, but it is not difficult, it is just different and if you want to start use `vim` you can do that easily in few weeks!

So, my next target is [spacemacs](http://spacemacs.org/). When I want to start new migration? I don't know, but when I will do that – I will tell about that experience! 🦄