Skip to content

Commit 595246c

Browse files
committed
feat: update c development environment
Use YouCompleteMe and syntastic to build and check project. Update statusline theme and use ctags in project.
1 parent 25d1b6e commit 595246c

11 files changed

+371
-52
lines changed

README.md

+26-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ All plugins settings are defined in the `plug_plugins` folder.
1717

1818
- [Fugitive](https://github.com/tpope/vim-fugitive) Requires Git to be installed.
1919
- [vimwiki](https://github.com/vimwiki/vimwiki) Convert vimwiki to html requires `pandoc` to be installed.
20+
- [fzf](https://github.com/junegunn/fzf.vim) Requires [ripgrep](https://github.com/BurntSushi/ripgrep), or [the_silver_searcher](https://github.com/ggreer/the_silver_searcher) to be installed.
21+
- FZF, tagbar, and vim-gutentags Required [Universal Ctags](https://ctags.io/) to be installed.
22+
- [youcompleteme](https://github.com/Valloric/YouCompleteMe) make sure you have Vim 7.4+ with Python 2 or Python 3 support. Requires `CMake` and `LLVM` to build this.
2023

2124
## Configuration
2225

@@ -139,6 +142,17 @@ Normal:
139142

140143
- `<F3>`: Toggle tagbar split window.
141144

145+
### Fzf
146+
147+
Normal:
148+
149+
- `<leader>ff`: Open currently path files list.
150+
- `<leader>bb`: Open all open buffers list.
151+
152+
Insert Mode:
153+
154+
- `<ctrl>x<ctrl>k`: Open word list.
155+
142156
## Commands
143157

144158
### Plugins Commands
@@ -163,18 +177,29 @@ For more information, see `:help fugitive`.
163177

164178
For more information, see [nerdtree-tabs-key-mappings](https://github.com/jistr/vim-nerdtree-tabs#commands-and-mappings).
165179

180+
#### vim-codefmt
181+
182+
- `:FormatCode`: Format code style.
183+
166184
## Plugin List
167185

168186
<!-- prettier-ignore-start -->
169187
<!-- PLUGIN_LIST_BEGIN -->
170188
| Plugin | Description |
171189
| ------ | ----------- |
190+
| [YCM-Generator](https://github.com/rdnetto/YCM-Generator) [:gear:](./plug_plugins/YCM-Generator.vim) | Generates config files for [YouCompleteMe](https://github.com/Valloric/YouCompleteMe) |
191+
| [YouCompleteMe](https://github.com/Valloric/YouCompleteMe) [:gear:](./plug_plugins/YouCompleteMe.vim) | A code-completion engine for Vim |
192+
| [c.vim](https://github.com/vim-scripts/c.vim) [:gear:](./plug_plugins/c.vim) | C/C++ IDE -- Write and run programs. Insert statements, idioms, comments etc |
193+
| [fzf.vim](https://github.com/junegunn/fzf.vim) [:gear:](./plug_plugins/fzf.vim) | fzf ❤️ vim|
172194
| [incsearch.vim](https://github.com/haya14busa/incsearch.vim) [:gear:](./plug_plugins/incsearch.vim) | 🔦 Improved incremental searching for Vim |
173-
| [lightline.vim](https://github.com/itchyny/lightline.vim) [:gear:](./plug_plugins/lightline.vim) | A light and configurable statusline/tabline plugin for Vim |
174195
| [molokai](https://github.com/tomasr/molokai) [:gear:](./plug_plugins/molokai.vim) | Molokai color scheme for Vim |
175196
| [nerdtree](https://github.com/vim-nerdtree/nerdtree) [:gear:](./plug_plugins/nerdtree.vim) | A tree explorer plugin for vim. |
197+
| [syntastic](https://github.com/vim-syntastic/syntastic) [:gear:](./plug_plugins/syntastic.vim) | Syntax checking hacks for vim |
176198
| [tagbar](https://github.com/majutsushi/tagbar) [:gear:](./plug_plugins/tagbar.vim) | Vim plugin that displays tags in a window, ordered by scope |
199+
| [vim-airline](https://github.com/vim-airline/vim-airline) [:gear:](./plug_plugins/vim-airline.vim) | Lean & mean status/tabline for vim that's light as air |
200+
| [vim-codefmt](https://github.com/google/vim-codefmt) [:gear:](./plug_plugins/vim-codefmt.vim) | codefmt is a utility for syntax-aware code formatting |
177201
| [vim-fugitive](https://github.com/tpope/vim-fugitive) [:gear:](./plug_plugins/vim-fugitive.vim) | fugitive.vim: A Git wrapper so awesome, it should be illegal |
202+
| [vim-gutentags](https://github.com/ludovicchabant/vim-gutentags) [:gear:](./plug_plugins/vim-gutentags.vim) | A Vim plugin that manages your tag files |
178203
| [vim-nerdtree-syntax-highlight](https://github.com/tiagofumo/vim-nerdtree-syntax-highlight) [:gear:](./plug_plugins/vim-nerdtree-syntax-highlight.vim) | Extra syntax and highlight for nerdtree files |
179204
| [vim-nerdtree-tabs](https://github.com/jistr/vim-nerdtree-tabs) [:gear:](./plug_plugins/vim-nerdtree-tabs.vim) | NERDTree and tabs together in Vim, painlessly |
180205
| [vim-polyglot](https://github.com/sheerun/vim-polyglot) [:gear:](./plug_plugins/vim-polyglot.vim) | A solid language pack for Vim. |

plug_plugins/YCM-Generator.vim

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
" Copyright (c) 2019-present Kaiming Guo. All rights reserved.
2+
" Use of this source code is governed by a BSD-style license that can be
3+
" found in the LICENSE file.
4+
5+
if exists('g:plug_installing_plugins')
6+
Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' }
7+
finish
8+
endif
9+
10+
" vim: set sw=2 ts=2 et tw=78 :

plug_plugins/YouCompleteMe.vim

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
" Copyright (c) 2019-present Kaiming Guo. All rights reserved.
2+
" Use of this source code is governed by a BSD-style license that can be
3+
" found in the LICENSE file.
4+
5+
function! BuildYcmd(info) abort
6+
if a:info.status == 'installed' || a:info.force
7+
!./install.py --clang-completer
8+
endif
9+
endfunction
10+
11+
if exists('g:plug_installing_plugins')
12+
Plug 'Valloric/YouCompleteMe', { 'do': function('BuildYcmd') }
13+
finish
14+
endif
15+
16+
let g:ycm_show_diagnostics_ui = 0
17+
let g:ycm_complete_in_comments = 1
18+
let g:ycm_seed_identifiers_with_syntax = 1
19+
let g:ycm_collect_identifiers_from_comments_and_strings = 1
20+
21+
let g:ycm_semantic_triggers = {
22+
\ 'cs,java,javascript,typescript,d,python,perl6,scala,vb,elixir,go': ['.'],
23+
\ 'ruby,c,cpp': ['.', '::'],
24+
\ 'gitcommit': ['#', ':']
25+
\ }
26+
27+
" Overwritten so we can allow markdown completion.
28+
let g:ycm_filetype_blacklist = {
29+
\ 'notes': 1,
30+
\ 'unite': 1,
31+
\ 'tagbar': 1,
32+
\ 'pandoc': 1,
33+
\ 'qf': 1,
34+
\ 'vimwiki': 1,
35+
\ 'text': 1,
36+
\ 'infolog': 1,
37+
\ 'mail': 1
38+
\ }
39+
40+
" vim: set sw=2 ts=2 et tw=78 :

plug_plugins/c.vim

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
" Copyright (c) 2019-present Kaiming Guo. All rights reserved.
2+
" Use of this source code is governed by a BSD-style license that can be
3+
" found in the LICENSE file.
4+
5+
if exists('g:plug_installing_plugins')
6+
Plug 'vim-scripts/c.vim', { 'for': ['c', 'cpp'] }
7+
finish
8+
endif
9+
10+
" vim: set sw=2 ts=2 et tw=78 :

plug_plugins/fzf.vim

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
" Copyright (c) 2019-present Kaiming Guo. All rights reserved.
2+
" Use of this source code is governed by a BSD-style license that can be
3+
" found in the LICENSE file.
4+
5+
if exists('g:plug_installing_plugins')
6+
if isdirectory('/usr/local/opt/fzf')
7+
Plug '/usr/local/opt/fzf' | Plug 'junegunn/fzf.vim' " hidden readme
8+
else
9+
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --bin' } " hidden readme
10+
Plug 'junegunn/fzf.vim'
11+
endif
12+
finish
13+
endif
14+
15+
if has('autocmd')
16+
augroup auto_fzf_settings
17+
autocmd!
18+
19+
autocmd! FileType fzf
20+
autocmd FileType fzf set laststatus=0 noshowmode noruler
21+
\| autocmd BufLeave <buffer> set laststatus=1 showmode ruler
22+
augroup END
23+
endif
24+
25+
let $FZF_DEFAULT_COMMAND =
26+
\ get(g:, 'fzf_default_cmd',
27+
\ !empty($FZF_DEFAULT_COMMAND) ? $FZF_DEFAULT_COMMAND :
28+
\ executable('rg') ? 'rg --files --hidden --follow --glob "\!.git/*"' :
29+
\ executable('ag') ? 'ag --hidden --ignore .git -g ""' :
30+
\ executable('fd') ? 'fd --type f' :
31+
\ 'find * -path "*/\.*" -prune -o -path "node_modules/**" -prune -o -path "target/**" -prune -o -path "dist/**" -prune -o -type f -print -o -type l -print 2> /dev/null'
32+
\ )
33+
34+
if executable('rg')
35+
set grepprg=rg\ --vimgrep
36+
command! -bang -nargs=* Find call fzf#vim#grep(
37+
\'rg --column --line-number --no-heading --fixed-strings --ignore-case --hidden --follow --glob "\!.git/*" --color "always" '
38+
\. '| tr -d "\017"', 1, <bang>0)
39+
elseif executable('ag')
40+
set grepprg=ag\ --nogrup\ --nocolor
41+
endif
42+
43+
let s:ctags_bin = get(g:, 'ctags_bin', 'ctags')
44+
let g:fzf_tags_command = s:ctags_bin . ' -R'
45+
let g:fzf_layout = { 'down': '~40%' }
46+
let g:fzf_colors = {
47+
\ 'fg': ['fg', 'Normal'],
48+
\ 'bg': ['bg', 'Normal'],
49+
\ 'hl': ['fg', 'Comment'],
50+
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
51+
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
52+
\ 'hl+': ['fg', 'Statement'],
53+
\ 'info': ['fg', 'PreProc'],
54+
\ 'border': ['fg', 'Ignore'],
55+
\ 'prompt': ['fg', 'Conditional'],
56+
\ 'pointer': ['fg', 'Exception'],
57+
\ 'marker': ['fg', 'Keyword'],
58+
\ 'spinner': ['fg', 'Label'],
59+
\ 'header': ['fg', 'Comment']
60+
\ }
61+
62+
nnoremap <silent> <leader>ff :FzfFilesWithDevIcon<cr>
63+
nnoremap <silent> <leader>bb :Buffers<cr>
64+
65+
" advanced customization using autoload functions
66+
inoremap <expr> <C-x><C-k> fzf#vim#complete#word({'left': '15%'})
67+
68+
""
69+
" @private
70+
" Get file and devicons
71+
" From: https://github.com/ryanoasis/vim-devicons/issues/106
72+
function! s:FzfFilesWithDevIcons() abort
73+
if executable('bat')
74+
let l:fzf_files_options = printf('--preview "bat %s %s | head -%s"',
75+
\ '--style=numbers,changes --color always',
76+
\ exists('*WebDevIconsGetFileTypeSymbol') ? '{2..-1}' : '{}',
77+
\ &lines)
78+
else
79+
let l:fzf_files_options = ''
80+
endif
81+
82+
function! s:GetFiles()
83+
let l:files = split(system($FZF_DEFAULT_COMMAND), "\n")
84+
return <sid>PrependIcon(l:files)
85+
endfunction
86+
87+
function! s:PrependIcon(candidates)
88+
let l:result = []
89+
for candidate in a:candidates
90+
let l:fname = fnamemodify(candidate, ':p:t')
91+
if exists('*WebDevIconsGetFileTypeSymbol')
92+
let l:icon = WebDevIconsGetFileTypeSymbol(l:fname, isdirectory(l:fname))
93+
call add(l:result, printf('%s %s', l:icon, candidate))
94+
else
95+
call add(l:result, candidate)
96+
endif
97+
endfor
98+
return l:result
99+
endfunction
100+
101+
function! s:EditFile(item)
102+
let l:pos = stridx(a:item, ' ')
103+
let l:file_path = a:item[pos+1:-1]
104+
execute 'silent e' l:file_path
105+
endfunction
106+
107+
call fzf#run({
108+
\ 'source': <sid>GetFiles(),
109+
\ 'sink': function('s:EditFile'),
110+
\ 'options': '-m ' . l:fzf_files_options,
111+
\ 'down': '40%' })
112+
endfunction
113+
command! FzfFilesWithDevIcons call <sid>FzfFilesWithDevIcons()
114+
115+
" similarly, we can apply it to fzf#vim#grep. To use ripgrep instead of ag:
116+
command! -bang -nargs=* Rg
117+
\ call fzf#vim#grep(
118+
\ 'rg --column --line-number --no-heading --color=always --smart-case '.shellescape(<q-args>), 1,
119+
\ <bang>0 ? fzf#vim#with_preview('up:60%')
120+
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
121+
\ <bang>0)
122+
123+
" command for git grep
124+
" - fzf#vim#grep(command, with_column, [options], [fullscreen])
125+
command! -bang -nargs=* GGrep
126+
\ call fzf#vim#grep(
127+
\ 'git grep --line-number '.shellescape(<q-args>), 0,
128+
\ { 'dir': systemlist('git rev-parse --show-toplevel')[0] }, <bang>0)
129+
130+
" augmenting Ag command using fzf#vim#with_preview function
131+
" * fzf#vim#with_preview([[options], [preview window], [toggle keys...]])
132+
" * For syntax-highlighting, Ruby and any of the following tools are required:
133+
" - Bat: https://github.com/sharkdp/bat
134+
" - Highlight: http://www.andre-simon.de/doku/highlight/en/highlight.php
135+
" - CodeRay: http://coderay.rubychan.de/
136+
" - Rouge: https://github.com/jneen/rouge
137+
"
138+
" :Ag - Start fzf with hidden preview window that can be enabled with "?" key
139+
" :Ag! - Start fzf in fullscreen and display the preview window above
140+
command! -bang -nargs=* Ag
141+
\ call fzf#vim#ag(<q-args>,
142+
\ <bang>0 ? fzf#vim#with_preview('up:60%')
143+
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
144+
\ <bang>0)
145+
146+
" vim: set sw=2 ts=2 et tw=78 :

plug_plugins/lightline.vim

-51
This file was deleted.

plug_plugins/syntastic.vim

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
" Copyright (c) 2019-present Kaiming Guo. All rights reserved.
2+
" Use of this source code is governed by a BSD-style license that can be
3+
" found in the LICENSE file.
4+
5+
if exists('g:plug_installing_plugins')
6+
Plug 'scrooloose/syntastic'
7+
finish
8+
endif
9+
10+
let g:syntastic_enable_signs = 1
11+
let g:syntastic_enable_highlighting = 1
12+
let g:syntastic_always_populate_loc_list = 1
13+
let g:syntastic_auto_loc_list = 0
14+
let g:syntastic_aggregate_errors = 1
15+
let g:syntastic_echo_current_error = 1
16+
17+
let g:syntastic_error_symbol = ''
18+
let g:syntastic_warning_symbol = ''
19+
let g:syntastic_style_error_symbol = ''
20+
let g:syntastic_style_warning_symbol = ''
21+
22+
if exists('&signcolumn')
23+
set signcolumn=yes
24+
endif
25+
26+
highlight link SyntasticError SpellBad
27+
highlight link SyntasticWarning SpellCap
28+
highlight SyntasticErrorSign ctermfg=1 guifg=#BF616A
29+
highlight SyntasticWarningSign ctermfg=3 guifg=#EBCB8B
30+
31+
" vim: set sw=2 ts=2 et tw=78 :

plug_plugins/tagbar.vim

+17
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,23 @@ if exists('g:plug_installing_plugins')
77
finish
88
endif
99

10+
if has('nvim')
11+
runtime! macros/matchit.vim
12+
else
13+
packadd! matchit
14+
endif
15+
16+
let g:tagbar_autofocs = 1
17+
let g:tagbar_type_ruby = {
18+
\ 'kinds': [
19+
\ 'm:modules',
20+
\ 'c:classes',
21+
\ 'd:describes',
22+
\ 'C:contexts',
23+
\ 'f:methods',
24+
\ 'F:singleton methods'
25+
\ ] }
26+
1027
nmap <silent> <F3> :TagbarToggle<cr>
1128
1229
" vim: set sw=2 ts=2 et tw=78 :

0 commit comments

Comments
 (0)