Less configuration, more defaults.
Mainly focus on C++ and restructuredText.
- vim 8.0 or later, with python3 support
- git
- GNU global , pygments is recommanded.
- ripgrep
- clangd version 9.0.0 or later
Firstly, install all the modules required such as git, clangd, etc. Then run bash commands as below:
git clone https://github.com/linuor/vimrc.git vimrc cd vimrc ./install.sh
Remember to alias vi to vim, and export enviroment variables if pygments is installed too:
alias vi="vim" export GTAGSLABEL='native-pygments' export GTAGSCONF='/usr/local/share/gtags/gtags.conf' export FZF_DEFAULT_COMMAND='rg --files'
Modify the vimrc file, provides a full path of clang-format.py, and informations such as author and email, just search "CUSTOM".
Plugins as follow will be installed:
- vim-commentary comment stuff out
- vim-surround Modify surroundings
- vim-repeat enable supported plugin maps with '.'
- tabular text filtering and alignment
- ultisnips The ultimate snippet solution for Vim
- vim-snippets Code snippets
- vim-gitgutter git diff in the sign column
- vim-fugitive git wrapper
- DoxygenToolkit.vim Doxygen documentation
- DrawIt Ascii drawing
- VOoM Vim Outliner of Markers
- Unicode-RST-Tables rst table helper
- coc.nvim code-completion engine
- ListToggle toggle quick fix and location list
- gruvbox color scheme
- ucmake.vim A vim helper for cmake build system.
- ugtags.vim A automation vim plugin for GNU global tag system.
Besides, another 2 plugins has already installed:
matchit.vim
which released by vim.gtags.vim
which installed with GNU global.
Shortcuts are defined as follow:
let mapleader="\<Space>" " mute search high light before clear and redraw the screen nnoremap <silent> <C-L> \ :nohlsearch<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-L> " hightlight tailing space nnoremap <leader>sp /\s\+$<CR> " undo in insert mode inoremap <C-U> <C-G>u<C-U> " shortcut for navation " args nnoremap [a :previous<CR> nnoremap ]a :next<CR> nnoremap [A :first<CR> nnoremap ]A :last<CR> " buffers nnoremap [b :bprevious<CR> nnoremap ]b :bnext<CR> nnoremap [B :bfirst<CR> nnoremap ]B :blast<CR> " locations nnoremap [l :lprevious<CR> nnoremap ]l :lnext<CR> nnoremap [L :lfirst<CR> nnoremap ]L :llast<CR> " quick fix nnoremap [q :cprevious<CR> nnoremap ]q :cnext<CR> nnoremap [Q :cfirst<CR> nnoremap ]Q :clast<CR> " tabs nnoremap [t :tabprevious<CR> nnoremap ]t :tabnext<CR> nnoremap [T :tabfirst<CR> nnoremap ]T :tablast<CR> " there are also [c ]c for jumping between git hunks " Bash like keys for the command line cnoremap <C-A> <Home> cnoremap <C-E> <End> " retain visual selection after indention vnoremap < <gv vnoremap > >gv " auto close pairs inoremap ( ()<Left> inoremap [ []<Left> inoremap { {}<Left> inoremap < <><Left> inoremap " ""<Left> inoremap ' ''<Left> inoremap ` ``<Left> " always use :update not :write nnoremap <leader>u :update<cr>
netrw is released with every vim, we use it as the default file explorer.
Use :E
to activate it in the current window.
-
Go up directory.%
Create new file.d
Create new directory.D
Delete file or directory.R
Rename.c
Make the directory under the cursor to be the current directory.gh
Toggle hiden/unhide of dot-files.gn
Make directory under the cursor to be the top of the tree.i
Cycle betwnn thin, long, wide, and tree listings.s
Select sorting style: by name, time, or file size.t
Enter the file/directory under the cursor in a new tab.
matchit also released with every vim, it extends %
matching for HTML, LaTeX,
and many other languages.
gcc
to toggle commentary.
vim-surround has the following operations:
Old text | Command | New text ~ |
---|---|---|
"Hello *world!" |
ds" |
Hello world! |
[123+4*56]/2 |
cs]) |
(123+456)/2 |
"Look ma, I'm *HTML!" |
cs"<q> |
<q>Look ma, I'm HTML!</q> |
if *x>3 { |
ysW( |
if ( x>3 ) { |
my $str = *whee!; |
vllllS' |
my $str = 'whee!'; |
ys{motion}{mark}
wrap the text object with{mark}
cs{mark1}{mark2}
change {mark1} to{mark2}
ds{mark}
delete{mark}
Press <leader>a
then given a ,
, will make codes align base on ,
.
This shortcut is available under normal and visual mode.
With many common code snippets, such as:
c)
for copyright text.date
forstrftime("%Y-%m-%d")
.datetime
forstrftime("%Y-%m-%d %H:%M")
.time
forstrftime("%H:%M")
.lorem
for lorem string.box
andbbox
for nice box.
Also, customer snippets are provided, which located in directory
my_snippets/
:
my_snippets/rst.snippets
For rst filesmy_snippets/c.snippets
For C/C++ files
All customer snippets use tpl
to create file skecth.
- jump to next hunk (change):
]c
- jump to previous hunk (change):
[c
- stage the hunk with
<Leader>hs
- undo it with
<Leader>hu
- preview a hunk's changes with
<Leader>hp
The .
command will work with both these with the help of repeat.vim.
A hunk text object is provided which works in visual and operator-pending modes.
ic
operates on all lines in the current hunk.
ac
operates on all lines in the current hunk and any trailing empty lines.
:Gstatus
to getgit status
info, and use-
to add/reset files.:Gcommit
to commit.:Gpush
to push.:Gpull
to pull.:Gdiff
to diff.
We use gtags-cscope to replace the build in cscope.
Just use the :cscope
as usual. Notice that :cs find d
command is not
implemented by gtags-cscope.
:Gtags
can be used to invoke the global command. Also the the following
shortcuts are provided:
<leader>gl
list all the tags of the current file<leader>gd
goto the definition of the symbol under the cursor<leader>gr
list all the reference of the symbol under the cursor<leader>gi
jump to files including the current file<leader>gf
jump to files under the cursor<leader>gg
jump to definition or reference under the cursor
:Dox
generate comment for function and class.:DoxAuthor
generate author comment. Usetpl
snippet instead.
<leader>di
to strat draw, and <leader>ds
to stop.
- For a Markdown file:
:Voom markdown
- For LaTeX file:
:Voom latex
- For an Orgmode file:
:Voom org
<Tab>
could be used after :Voom
for file type auto-completion.
<leader><leader>c
Creates a new restructuredText table.<leader><leader>f
Fix table columns in a table.
<tab>
trigger the auto completion in insert mode<leader>cd
goto declaration<leader>ci
goto definition/implementation<leader>cr
goto reference<leader>fs
format the selected text in insert mode, or the following text object.<leader>fa
format the whole buffer<leader>fx
apply the fix-it<leader>rf
refector<leader>rn
rename<leader>ff
file search list<leader>fb
buffer search list<leader>sh
grep search list
auto lint.
ListToggle provides <leader>q
and <leader>l
to toggle quickfix and
location list.
- launch vim from the root of the project.
- pass a list of files as arguments for vim, such as
vim `git ls-files`
, to open all the source files of the project. - to search files from the project root, use
<leader>fb
to search buffers. - to recursively search files from the current location, use
<leader>ff
. - use both coc.nvim list and gtags to jump across the project.
- 2018-06-12
- lint and show the result in a list. YouCompleteMe provides this,
which is mapped to
<leader>yd
.
- lint and show the result in a list. YouCompleteMe provides this,
which is mapped to
- 2018-05-22
- restructure the whole vimrc.
- update README
- 2018-05-23
- outline for the current buffer.
- related file, header file, implementation file, test file
- 2018-05-24
- toggle Quickfix window
- 2018-05-26
- template for new c/c++ header/source files, namespace, include guard, etc.
- better automatic tag file manager.
- 2018-12-2
- vim-clang-format too slow, use clangformat.py instead.
- 2019-02-18
- denite is too heavy, and break when update. Remove it and use
fzf
instead. - YouCompleteMe is a little lag while linting, ALE may be a alternation. ALE is not my style, use neomake instead.
- denite is too heavy, and break when update. Remove it and use
- gtags outline source for Denite. Using outline means we don't know much about
the name. Navigation is better than filtering. So, keep the QuickFix style,
but drop the filtering style. Just use
<leader>gl
. - run make in the build dir. Use
make -C /path/to/makefile
. ucmake.vim auto set build dir formake
.
- language server protocol.
- add sources for fzf.
- use neomake to replace ucmake.vim and ugtags.vim
- neoformat may be useful for formating kinds of files.