Some notes for vim, actually neovim.
markdown
There are 3 packages for markdown syntax in vim:
- vim-polyglot, A collection of language packs for Vim.
- vim-markdown. It needs tabular for table.
- vim-pandoc. It requires vim-pandoc-syntax for syntax support.
Finally, I chose vim-pandoc. It has many useful key mapping for editing markdown, which is missed in vim-markdown. As to vim-polyglot, although it use vim-markdown to provide markdown support, it can’t highlight fenced codeblocks, because of lacking ftplugin/markdown.vim
.
Installation
1 | call plug#begin('~/.local/share/nvim/plugged') |
Setting
1 | let g:pandoc#folding#fdc = 0 |
Usage
:TOC
to open TOC, When the user presses<CR>
(the Enter key) in the TOC buffer, the cursor is moved in the source window to the position selected.g:pandoc#toc#position
sets the position of TOC (default right).g:pandoc#toc#close_after_navigating
controls the whether close the TOC buffer after navigating.
Available key mapping
1 | - *<localleader>i* toggles emphasis [vn] |
Preview
1 | Plug 'iamcco/mathjax-support-for-mkdp' |
vim-template
Use vim-template to open a template when creating a new file.
Installation
1 | Plug 'aperezdc/vim-template' |
Setting
1 | " vim-template |
Customized templates
1 | #! /usr/bin/env python |
Complete and snippets using ncm2 and ultisnips
- Use ncm2 as completion framework
- Use ultisnips as snippet engine
- Use vim-snippets as source of snippets
- Use CompleteParameter.vim to complete parameters
Installation
1 | " ncm2 requires nvim-yarp |
Configure and key mapping
1 | " use Tab to cycle in the popmenu, enter to complete or expand |
Customized snippets
1 | snippet ifmain "ifmain" b |
Complete and snippets using deoplete and neosnippet (Deprecated)
Deprecated because deoplete/Neosnippet doesn’t work well for completion of functions. For pri
, it gets print
rather than print()
. Seems that neopairs.vim are needed to auto insert pairs when complete done.
- Use deoplete.nvim as completion framework
- Use Neosnippet as snippet engine
- Use vim-snippets as source of snippets
- Use CompleteParameter.vim to complete parameters
Not using neosnippet-snippets as snippets source, because it’s not frequently updated.
Installation
1 | Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' } |
Configure
1 | " deoplete |
Key mapping
1 | inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>" |
vim-polyglot
sheerun/vim-polyglot, A collection of language packs for Vim.
This plugin acts weird. It changes the folding pattern of markdown/pandoc filetype, changes conceallevel in some filetype and overrides nmap <F3>
in r
. These cannot be disabled by g:polyglot_disabled
. Considering remove it.
1 | Plug 'sheerun/vim-polyglot' |
python
- vim-python/python-syntax, syntax highlight
- fisadev/vim-isort, sort imports. Not need anymore, since
ale
can useisort
directly. - tmhedberg/SimpylFold, for folding code.
1 | Plug 'vim-python/python-syntax' |
Indent guide
- thaerkh/vim-indentguides, I prefer this one, because it show guide for both space and tab
1 | Plug 'thaerkh/vim-indentguides' |
vim-gitgutter
- vim-gitgutter shows git diff signs.
1 | Plug 'airblade/vim-gitgutter' |
Usage
]c
jump to the next hunk[c
jump to the previous hunk
Fold
- Konfekt/FastFold, speed up Vim by updating folds only when called-for. Use
zuz
in normal mode to update the fold.
1 | Plug 'Konfekt/FastFold' |
Distraction-free writing
1 | Plug 'junegunn/goyo.vim' |
Undo tree
- simnalamburt/vim-mundo
- gundo seems not maintained anymore.
1 | Plug 'simnalamburt/vim-mundo' |
Rainbow Parentheses
- luochen1990/rainbow, other Rainbow Parentheses plugins aren’t maintained.
1 | Plug 'luochen1990/rainbow' |
CN doc
1 | " cn doc |
The doc is for vim, not neovim. Removed.
Shell
1 | Plug 'Shougo/vimproc.vim', {'do' : 'make'} |
Match-up
1 | Plug 'andymass/vim-matchup' |
clever-f.vim
1 | Plug 'rhysd/clever-f.vim' |
File-explorer
vimfiler does not respect set splitright
. if set 'direction' : 'rightbelow'
, although the split window will appear on right, the vimfiler window will also on right. Considering change to NERDTree.
1 | Plug 'Shougo/unite.vim' |
Neovim configure
1 | " enable true color support |
Tips
nvim -u NONE
will run neovim without plugins and init.vim,nvim -u NORC
will run neovim without init.vim (with plugins from neovim). These are useful for troubleshooting.Tab setting:1
与缩进相关的参数有shiftwidth、tabstop、softtabstop、expandtab。
shiftwidth reindent 操作(<<和>>)时缩进的列数(这里的一列相当于一个空格)
tabstop 一个tab键所占的列数,linux 内核代码建议每个tab占用8列
softtabstop 敲入tab键时实际占有的列数。
expandtab 输入tab时自动将其转化为空格softtabstop大于tabstop时,且没有设置expandtab时,例如:softtabstop=12,tabstop=8,那么当输入一个tab时(softtabstop:实际占用的是12列),最后会变成一个tab(tabstop)加4个空格(8+4),输入两个tab(2个softtabstop:24列)会变成3个tab(tabstop),也就是说vim或用tabstop+空格来表示,最终你能看到的缩进的列数一定是softtabstop*按的tab键次数。(ps::set list 可以查看tab符号)
softtabstop小于tabstop且没有设置expandtab时,如果softtabstop=4,tabstop=8,输入一个tab(softtabstop),会变成4个空格(因为不够用一个tabstop表示),输入两个tab会变成一个tab(8列)。
如果softtabstop等于tabstop,而且expandtab没有设置,softtabstop与tabstop就没什么区别了。
如果设置的expandtab,输入一个tab,将被展开成softtabstop值个空格,如果softtabstop=4,那么一个tab就会被替换成4个空格。
References
1. http://liuzhijun.iteye.com/blog/1831548 ↩