diff --git a/wiki/linux/vim/c-language.md b/wiki/linux/vim/c-language.md new file mode 100644 index 0000000..e6e0b94 --- /dev/null +++ b/wiki/linux/vim/c-language.md @@ -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" + } + } + } + } +} +``` diff --git a/wiki/linux/vim/coc.md b/wiki/linux/vim/coc.md new file mode 100644 index 0000000..339858e --- /dev/null +++ b/wiki/linux/vim/coc.md @@ -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 + \ pumvisible() ? "\" : + \ check_back_space() ? "\" : + \ coc#refresh() +inoremap pumvisible() ? "\" : "\" + +function! s:check_back_space() abort + let col = col('.') - 1 + return !col || getline('.')[col - 1] =~# '\s' +endfunction + +if has('nvim') + inoremap coc#refresh() +else + inoremap coc#refresh() +endif + +inoremap pumvisible() ? coc#_select_confirm() + \: "\u\\=coc#on_enter()\" + +nmap gd (coc-definition) +nmap gy (coc-type-definition) +nmap gi (coc-implementation) +nmap gr (coc-references) +nnoremap K :call show_documentation() + +function! s:show_documentation() + if (index(['vim','help'], &filetype) >= 0) + execute 'h '.expand('') + elseif (coc#rpc#ready()) + call CocActionAsync('doHover') + else + execute '!' . &keywordprg . " " . expand('') + endif +endfunction + +autocmd CursorHold * silent call CocActionAsync('highlight') + +nmap (coc-rename) + +xmap f (coc-format-selected) +nmap f (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', + \ ] +``` + diff --git a/wiki/linux/vim/neovim.md b/wiki/linux/vim/neovim.md new file mode 100644 index 0000000..aa4de27 --- /dev/null +++ b/wiki/linux/vim/neovim.md @@ -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) diff --git a/wiki/linux/vim/vim-plug.md b/wiki/linux/vim/vim-plug.md new file mode 100644 index 0000000..be56e2f --- /dev/null +++ b/wiki/linux/vim/vim-plug.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. diff --git a/wiki/programming-languages/c-language.md b/wiki/programming-languages/c-language.md new file mode 100644 index 0000000..ec190e0 --- /dev/null +++ b/wiki/programming-languages/c-language.md @@ -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].