Your Vim is Only for You
mopp
VimConf 20192019-11-04

2mopp
GitHub●moppInteresting●Vim, Hobby OS
Self-published techbooks

Job●

MC of VimConf2017/2018/2019
Quipper Limited Japan Branch○Meguro, Tokyo
Elixir, Go, and Ruby on Rails

Introduction

3

4

Target of this talk
Vim level

Middle level Vimmer

You are Vim
Vimmer emperor

A person who
has vimrc with hundreds of lines

You can create plugin

doesn’t hesitate to open vimrc
TargetYou can enhance your Vim
by many plugins

is not so familiar with Vim script
You can conﬁg Vim and plugins
You can write code with Vim

You can input something with Vim
You can quite Vim
Not Vimmer

Theme of VimConf 2019

How to be more productive with Vim

5

Ways to increase productivity
1. Master the default Vim○

No conﬁgs and plugins○

Powerful, but unhandy sometimes

2. Customize Vim by myself○

You can send a patch○

Not easy
Theme of this talk3. Customize Vim by vimrc○

Customizability of Vim is high6Theme of this talk

Increase productivity by vimrc
Overcome vimrc which has many copy-and-past
Like Vim more and more7

8Outline

Introduction
Mopp’s vimrc
How to grow vimrc
Summarymopp’s vimrc

9mopp’s vimrc
Policies

You can ﬁnd my vimrc

Conﬁgs●mopp/dotﬁlesplugins●1303 lines

I use Neovim

10Policies
1. Shorter startup time is better
2. Portability: No errors without plugins
3. Compatibility: Works with Neovim/Vim
4. Put everything into one ﬁle11

12

Policy1: Shorter startup time is betterWhy?
● Shorter startup time doesn’t distract us● I open/close Vim many times in a day.

189.89ms

How?
● 108 plugins via dein.nvim● 55 plugins with lazy loading○27.5xﬁletype, command, mapping, etc

25.36ms
6.89mslazy

not-lazy

3.7x

nvim --startuptime stime

Policy2: Portability: No errors without plugins

13Why?
●

It’s handy immediately after installing OS or copying vimrc

How?
●
●

Pure Vimpart

My vimrc is composed of the two parts
Pure Vim part

Pluginsexist?
Checker○●

Only vim itself conﬁgs

The checker○

Plugin part

terminates loading vimrc if plugins not foundvimrc structurePolicy3: Compatibility: Works with Neovim/VimWhy?
●●

I switch Neovim and Vim sometimes to use○

New features○

Plugins support either Vim or Neovim

Neovim speciﬁc options exist○

Please see :vim-diﬀerences for more details

How?
●

Use has(‘nvim’)○return 1 if Neovim, 0 otherwise

if has('nvim')
set inccommand=split
set scrollback=5000
set wildoptions=endif

example code14Policy4: Put everything into one ﬁleWhy?
●

I simply prefer this style●

Find somethings easily

How?
●Just put the all into vimrc●Filter by denite.nvim○:Denite outline○/ works well15

Conﬁgs and plugins
1. <Leader> is space
2. number + relativenumber
3. Work quickly by mappings
4. Extending plugin
5. Plugin combination

16

17

<Leader> is space
Why?
●

It’s easy to press●

Plugin preﬁxes <Leader> to default mappings

Faraway...

How?
●

Just set the variable" Set <Leader>let g:mapleader = ' 'https://en.wikipedia.org/wiki/QWERTY

the thumb ison top of
the space key

number + relativenumberWhy?
●I can know how far fromcurrent line easily

How?
●

Just set the conﬁgs
set number
set relativenumber

Note●It makes non-Vimmer confused●I disable it duringpair-programming

18

19

Work quickly by mappings
Why?
● To reduce the time of operations
How?
● Deﬁne mappings what you do many time in a day.

I save buﬀer after
every input
I use tabs heavily.

" Write buffer to filennoremap <silent> <Leader>w :<C-U>write<CR>" Go to prev/next tabnnoremap <Leader>j gTnnoremap <Leader>k gt" Open help by word under the cursor.
nnoremap <silent> <Leader>hh :<C-U>help <C-R><C-W><CR>nnoremap <silent> <Leader>ht :<C-U>tab help <C-R><C-W><CR>I want to refer help
quickly when I would
like to know
something about Vim

20

Diﬀerence: Mapping/Command/Function
Which interface should we use?
● If you use many times -> Mapping● If you use sometime -> Command● Otherwise -> Function

Operation speed

High

Operation speed● How easily we can input
Expressiveness● How obvious what it canMapping

CommandFunctionLowNote● Command/function can take arguments

ExpressivenessHighExtending plugin: GrepBuﬀer by capture.vim
Why?
●To analyze application logs easily

How?
●

Filter current buﬀer by given word

●Capture.vim shows command resulton new buﬀer●

GrepBuﬀer! works like grep -v

command! -nargs=1 -bang GrepBuffer\ :execute printf(':Capture! global%s/%s/print',\expand('<bang>'),\<q-args>)

21

Plugin combination: defx.nvim + vim-choosewin
Why?
● To open ﬁle at target buﬀer easily

22

My standard buﬀer layoutHow?
● defx.nvim + vim-choosewin● Filer and window selector
function! DefxChoosewin(context) abort
let l:winnrs = find_winnrs() " Modified for slide
let l:opts = {'auto_choose': 1, 'hook_enable': 0}for filename in a:context.targets
call choosewin#start(l:winnrs, l:opts)
execute 'edit' filename
endforendfunction
nnoremap <silent><buffer><expr><nowait> w\ defx#do_action('call', 'DefxChoosewin')

About 10 lines
NOTE: I usually 3 windows with vsplit

23Outline

Introduction
mopp’s vimrc
How to grow vimrc
Summary

How to grow vimrc

24

Writing codes
First step is to use Vim.

25

vimrc growing ﬂowchart
Writing codes

Notice inconvenience
Enough?

●Examples○

Cannot align well○

Many key inputs are required

Keypoint: DRY○○

Don’t Repeat Yourself rule
If it distracted your attention,
It is things to be improved

Yes

No
Keep in mind

Find
Plugins/Conﬁgs

Yes
Found?

NoWriteVim script

ConﬁgureNotice inconvenience
Keep your idea in your mind●

26vimrc growing ﬂowchart
Writing codes

Take a note
Enough?

○●Google Keep, Evernote, Scrapbox

Post brief messages○

Twitter, Slack, IRC○#vim channel is good practice.

Yes

No
Keep in mind

FindPlugins/Conﬁgs

Yes
Found?

No
Write
Vim script

ConﬁgureFind plugins/conﬁgs
Search conﬁg or plugins on Internet

27

vimrc growing ﬂowchart
Writing codes

Enough?

Yes

No
Keep in mind

Ask somebody●

FindPlugins/Conﬁgs

Colleagues on SlackYes○#vim channel is good practiceFound?

No●Followers on TwitterWrite
Vim script

ConﬁgureWhen you ﬁnd, setup
Do not just copy and paste

28

vimrc growing ﬂowchart
Writing codes

Read docs for 30 seconds at least
Enough?

●Vim itself is well documented.
○●You can also know related conﬁgs

Check what interfaces plugin has
○

Yes

No
Keep in mind

Find
Plugins/Conﬁgs

Examples■■:help gitgutter-commands:help lexima-key-mappings

Yes
Found?

NoWriteVim script

ConﬁgureWhen you don’t get satisﬁed?
Why?
●

29vimrc growing ﬂowchart
Writing codes

No conﬁgs, No plugins or
The interface does not ﬁt use-caseEnough?

Yes

No

It’s chance to grow vimrc
Keep in mind●

Write the all into vimrc at ﬁrst○

You don’t need plugin at ﬁrst

●Extend/combine exist plugins●

Keep dogfooding/improving○add new features if you want

FindPlugins/Conﬁgs

YesFound?

NoWriteVim scriptConﬁgureWhen you don’t get satisﬁed?
Tips for improving quickly

30

vimrc growing ﬂowchart
Writing codes“ Open vimrc

nnoremap <silent> <Leader>ev :<C-U>tab drop $MYVIMRC<CR>“ Reload vimrc

command! ReloadVimrc :source $MYVIMRC

Use Git/GitHub to edit/share codes easily●a.k.a dotﬁles●anishathalye/dotbot

Enough?

YesNoKeep in mind

Find
Plugins/Conﬁgs

YesFound?

NoWriteVim script

ConﬁgureFrom vimrc to plugin
Iterate this cycle●31vimrc growing ﬂowchart
Writing codes

vimrc will getting large
Enough?

Vim plugin comes from your vimrc

YesNo
Keep in mind

Find
Plugins/Conﬁgs

Original part

PluginExtract

YesFound?

NoWriteVim script

ConﬁgureCleanup vimrc every 6 months
Remove unused conﬁgs/plugins●Pruning is necessary for vimrc as well as plants

Hold a meetup●The purpose is clear●

1~3 times is best to be done●

Good opportunity for sharing your knowledge

32

33

OutlineIntroduction
mopp’s vimrc
How to grow vimrc
SummarySummary34

Summary: What you take
Optimize Vim for you●

Your Vim is only for you

Find out your policy●

What you want for Vim

Keep improving●

Prepare tools to improve

Share your knowledge●

I didn’t discover the all bymyself●

Output is important

35Thank you

36

License and Acknowledgement
Noto Emoji●

Apache license, version 2.0

Plugins and tool●
●●●
●
●
●

Shougo/dein.vim
Shougo/denite.nvim
t9md/vim-choosewin
tyru/capture.vim
airblade/vim-gitguttercohama/lexima.vim
anishathalye/dotbot

37