vim/c: added vim setup and c language setup

- added vim setup
- added vim autocomplete guide based on coc
- added c support by coc lsp
- added c setup
master
TiynGER 4 years ago
parent ce4d4a13dd
commit 9ba0e1908a

@ -0,0 +1,39 @@
# C
C is a common programming language.
In this entry we will focus on making vim support c and use vim as an ide for c.
## Autocompletion
### Coc
To enable autocompletion for coc you need to install `ccls`.
After that you need to add the following lines to your coc config file.
```json
{
"languageserver": {
"ccls": {
"command": "ccls",
"filetypes": [
"c",
"cpp",
"objc",
"objcpp"
],
"rootPatterns": [
".ccls",
"compile_commands.json",
".vim/",
".git/",
".hg/"
],
"initializationOptions": {
"cache": {
"diretory": "/tmp/ccls"
}
}
}
}
}
```

@ -0,0 +1,87 @@
# Coc
[Conquer of completion](https://github.com/neoclide/coc.nvim) enables full
language server protocol support for neovim.
It is written specifically for neovim.
The coc config file is located in `.config/nvim/coc-settings.json`.
## Installation
- Install `nodejs`
- Install [vim-plug](vim-plug.md)
- Add coc.vim to your init.vim
- Add `Plug 'neoclide/coc.nvim', {'do': 'yarn install --frozen-lockfile'}`
to your Plug-Section
## Base config
Add the base configuration to your vim config file.
```vimscript
" neoclide/coc.nvim
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
inoremap <silent><expr> <c-@> coc#refresh()
endif
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
elseif (coc#rpc#ready())
call CocActionAsync('doHover')
else
execute '!' . &keywordprg . " " . expand('<cword>')
endif
endfunction
autocmd CursorHold * silent call CocActionAsync('highlight')
nmap <F5> <Plug>(coc-rename)
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
augroup mygroup
autocmd!
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end
```
## Extensions
Extensions can be added to the vim config aswell.
A basic example for adding a few extensions is:
```vimscript
let g:coc_global_extensions = [
\ 'coc-java',
\ 'coc-markdownlint',
\ 'coc-python',
\ 'coc-sh',
\ 'coc-vimtex',
\ ]
```

@ -0,0 +1,20 @@
# Vim
[Vim](https://github.com/vim/vim) is a texteditor.
A good alternative to baseline vim is Neovim.
[Neovim](https://github.com/neovim/neovim) is based on vim and focused
on extensibility and usability.
The configuration file is stored in `.config/nvim/init.vim`
## Plug-In
There are a bunch of different options for managing plug-ins.
- [Vim-plug](vim-plug.md)
## Autocompletion
An important feature for writing text and especially code is autocompletion.
For Neovim there are a few options.
- [Conquer of completion](coc.md)

@ -0,0 +1,35 @@
# Vim-Plug
[Vim-Plug](https://github.com/junegunn/vim-plug) is a minimalist plugin manager.
## Installation
You can add the following lines to your vim config file to make sure vim-plug is
installed with the correct folder-structure.
```vimscript
if ! filereadable(expand('~/.config/nvim/autoload/plug.vim'))
echo "Downloading junegunn/vim-plug to manage plugins..."
silent !mkdir -p ~/.config/nvim/autoload/
silent !curl "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" > ~/.config/nvim/autoload/plug.vim
autocmd VimEnter * PlugInstall
endif
```
Below is an example plugin section.
```vimscript
call plug#begin('~/.local/share/nvim/plugged')
Plug 'airblade/vim-gitgutter'
Plug 'tpope/vim-surround'
Plug 'uiiaoo/java-syntax.vim' , {'for': 'java'}
call plug#end()
```
## Important commands
- `:PlugInstall` - install plugins specified in the Plug section
- `:PlugClean` - remove plugins that are not specified in the Plug section
For both of these command remember to write the file and reload the buffer if
you just added a new plugin or removed one.

@ -0,0 +1,16 @@
# C
C is a common programming language.
## Installation
To get c working you basically just need to install a compiler.
To get a compiler for c there are a few options.
- [GNU compiler collection](gcc.gnu.org)
## IDE
### Vim
The steps to make Vim a c IDE are described in [../linux/vim/c-language.md].
Loading…
Cancel
Save