Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédenteDernière révisionLes deux révisions suivantes | ||
technique:vim [2021/12/14 22:49] – francoisa | technique:vim [2022/01/06 15:00] – francoisa | ||
---|---|---|---|
Ligne 18: | Ligne 18: | ||
</ | </ | ||
+ | |||
===== Notions vim ===== | ===== Notions vim ===== | ||
Ligne 83: | Ligne 84: | ||
</ | </ | ||
+ | |||
+ | ==== Exemple de .vimrc ==== | ||
+ | |||
+ | <code vim> | ||
+ | set history=700 | ||
+ | |||
+ | filetype plugin on | ||
+ | filetype indent on | ||
+ | |||
+ | set autoread | ||
+ | set ruler | ||
+ | set ignorecase | ||
+ | set smartcase | ||
+ | set hlsearch | ||
+ | set showmatch | ||
+ | |||
+ | syntax enable | ||
+ | autocmd BufRead, | ||
+ | |||
+ | if has(" | ||
+ | set guioptions-=T | ||
+ | set guioptions+=e | ||
+ | set t_Co=256 | ||
+ | set guitablabel=%M\ %t | ||
+ | endif | ||
+ | |||
+ | set encoding=utf8 | ||
+ | set ffs=unix, | ||
+ | |||
+ | set nobackup | ||
+ | set nowb | ||
+ | set noswapfile | ||
+ | |||
+ | set expandtab | ||
+ | set smarttab | ||
+ | |||
+ | set shiftwidth=4 | ||
+ | set tabstop=4 | ||
+ | |||
+ | set lbr | ||
+ | set tw=500 | ||
+ | |||
+ | set ai "Auto indent | ||
+ | set si "Smart indent | ||
+ | set wrap "Wrap lines | ||
+ | |||
+ | " Treat long lines as break lines (useful when moving around in them) | ||
+ | map j gj | ||
+ | map k gk | ||
+ | |||
+ | " Always show the status line | ||
+ | set laststatus=2 | ||
+ | |||
+ | " Format the status line | ||
+ | set statusline=\ %F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l | ||
+ | |||
+ | let data_dir = has(' | ||
+ | if empty(glob(data_dir . '/ | ||
+ | silent execute '!curl -fLo ' | ||
+ | autocmd VimEnter * PlugInstall --sync | source $MYVIMRC | ||
+ | endif | ||
+ | |||
+ | call plug# | ||
+ | Plug ' | ||
+ | Plug ' | ||
+ | Plug ' | ||
+ | Plug ' | ||
+ | Plug ' | ||
+ | Plug ' | ||
+ | Plug ' | ||
+ | call plug#end() | ||
+ | |||
+ | colorscheme PaperColor | ||
+ | set background=dark | ||
+ | set number | ||
+ | let g: | ||
+ | let g: | ||
+ | |||
+ | set hidden | ||
+ | set nobackup | ||
+ | set nowritebackup | ||
+ | |||
+ | set updatetime=300 | ||
+ | set shortmess+=c | ||
+ | |||
+ | " Always show the signcolumn, otherwise it would shift the text each time | ||
+ | " diagnostics appear/ | ||
+ | if has(" | ||
+ | " Recently vim can merge signcolumn and number column into one | ||
+ | set signcolumn=number | ||
+ | else | ||
+ | set signcolumn=yes | ||
+ | endif | ||
+ | |||
+ | " Use tab for trigger completion with characters ahead and navigate. | ||
+ | " NOTE: Use command ': | ||
+ | " other plugin before putting this into your config. | ||
+ | inoremap < | ||
+ | \ pumvisible() ? " | ||
+ | \ < | ||
+ | \ coc# | ||
+ | inoremap < | ||
+ | |||
+ | function! s: | ||
+ | let col = col(' | ||
+ | return !col || getline(' | ||
+ | endfunction | ||
+ | |||
+ | " Use < | ||
+ | if has(' | ||
+ | inoremap < | ||
+ | else | ||
+ | inoremap < | ||
+ | endif | ||
+ | |||
+ | " Make <CR> auto-select the first completion item and notify coc.nvim to | ||
+ | " format on enter, <cr> could be remapped by other vim plugin | ||
+ | inoremap < | ||
+ | \: " | ||
+ | |||
+ | " Use `[g` and `]g` to navigate diagnostics | ||
+ | " Use `: | ||
+ | nmap < | ||
+ | nmap < | ||
+ | |||
+ | " GoTo code navigation. | ||
+ | nmap < | ||
+ | nmap < | ||
+ | nmap < | ||
+ | nmap < | ||
+ | |||
+ | " Use K to show documentation in preview window. | ||
+ | nnoremap < | ||
+ | |||
+ | function! s: | ||
+ | if (index([' | ||
+ | execute 'h ' | ||
+ | elseif (coc# | ||
+ | call CocActionAsync(' | ||
+ | else | ||
+ | execute ' | ||
+ | endif | ||
+ | endfunction | ||
+ | |||
+ | " Highlight the symbol and its references when holding the cursor. | ||
+ | autocmd CursorHold * silent call CocActionAsync(' | ||
+ | |||
+ | " Symbol renaming. | ||
+ | nmap < | ||
+ | |||
+ | " Formatting selected code. | ||
+ | xmap < | ||
+ | nmap < | ||
+ | |||
+ | augroup mygroup | ||
+ | autocmd! | ||
+ | " Setup formatexpr specified filetype(s). | ||
+ | autocmd FileType typescript, | ||
+ | " Update signature help on jump placeholder. | ||
+ | autocmd User CocJumpPlaceholder call CocActionAsync(' | ||
+ | augroup end | ||
+ | |||
+ | " Applying codeAction to the selected region. | ||
+ | " Example: `< | ||
+ | xmap < | ||
+ | nmap < | ||
+ | |||
+ | " Remap keys for applying codeAction to the current buffer. | ||
+ | nmap < | ||
+ | " Apply AutoFix to problem on the current line. | ||
+ | nmap < | ||
+ | |||
+ | " Map function and class text objects | ||
+ | " NOTE: Requires ' | ||
+ | xmap if < | ||
+ | omap if < | ||
+ | xmap af < | ||
+ | omap af < | ||
+ | xmap ic < | ||
+ | omap ic < | ||
+ | xmap ac < | ||
+ | omap ac < | ||
+ | |||
+ | " Remap <C-f> and <C-b> for scroll float windows/ | ||
+ | if has(' | ||
+ | nnoremap < | ||
+ | nnoremap < | ||
+ | inoremap < | ||
+ | inoremap < | ||
+ | vnoremap < | ||
+ | vnoremap < | ||
+ | endif | ||
+ | |||
+ | " Use CTRL-S for selections ranges. | ||
+ | " Requires ' | ||
+ | nmap < | ||
+ | xmap < | ||
+ | |||
+ | " Add `:Format` command to format current buffer. | ||
+ | command! -nargs=0 Format :call CocAction(' | ||
+ | |||
+ | " Add `:Fold` command to fold current buffer. | ||
+ | command! -nargs=? Fold :call | ||
+ | |||
+ | " Add `:OR` command for organize imports of the current buffer. | ||
+ | command! -nargs=0 OR : | ||
+ | |||
+ | " Add (Neo)Vim' | ||
+ | " NOTE: Please see `:h coc-status` for integrations with external plugins that | ||
+ | " provide custom statusline: lightline.vim, | ||
+ | set statusline^=%{coc# | ||
+ | |||
+ | " Mappings for CoCList | ||
+ | " Show all diagnostics. | ||
+ | nnoremap < | ||
+ | " Manage extensions. | ||
+ | nnoremap < | ||
+ | " Show commands. | ||
+ | nnoremap < | ||
+ | " Find symbol of current document. | ||
+ | nnoremap < | ||
+ | " Search workspace symbols. | ||
+ | nnoremap < | ||
+ | " Do default action for next item. | ||
+ | nnoremap < | ||
+ | " Do default action for previous item. | ||
+ | nnoremap < | ||
+ | " Resume latest coc list. | ||
+ | nnoremap < | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | ===== Plugin et Completion ===== | ||
+ | |||
+ | ==== Installation de vim-plug ==== | ||
+ | |||
+ | source : https:// | ||
+ | < | ||
+ | curl -fLo | ||
+ | ~ / | ||
+ | https:// | ||
+ | |||
+ | </ | ||
+ | |||
+ | => Création d'un dossier .vim/ | ||
+ | |||
+ | Dans .vimrc, rajouter en fin de fichier (ici un plugin vim-easily-align) : | ||
+ | |||
+ | < | ||
+ | call plug# | ||
+ | " The default plugin directory will be as follows: | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | |||
+ | " Shorthand notation; fetches https:// | ||
+ | Plug ' | ||
+ | |||
+ | " Initialize plugin system | ||
+ | call plug#end() | ||
+ | |||
+ | </ | ||
+ | ==== Installation de coc.nvim ==== | ||
+ | |||
+ | Installer nodejs auparavant : https:// | ||
+ | |||
+ | < | ||
+ | # Using Ubuntu | ||
+ | curl -fsSL https:// | ||
+ | sudo apt-get install -y nodejs | ||
+ | |||
+ | </ | ||
+ | |||
+ | Modifier .vimrc et rajouter : | ||
+ | < | ||
+ | |||
+ | call plug# | ||
+ | |||
+ | Plug ' | ||
+ | |||
+ | call plug#end() | ||
+ | |||
+ | </ | ||
+ | |||
+ | Puis lancer vim et installer le plugin | ||
+ | |||
+ | ==== Installation de complétion pour python ==== | ||
+ | |||
+ | ==== Plusieurs plugin pour python : coc-jedi, coc-pyright, | ||
+ | |||
+ | Nombreux extensions : https:// | ||
+ | |||
+ | Et relancer vim et lancer : | ||
+ | |||
+ | < | ||
+ | :CocInstall coc-jedi | ||
+ | |||
+ | </ | ||
+ | |||
+ | ou :CocInstall coc-pyright | ||