Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédenteDernière révisionLes deux révisions suivantes | ||
technique:vim [2021/12/09 16:48] – créée francoisa | technique:vim [2022/01/06 15:00] – francoisa | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
====== Utiliser Vim ====== | ====== Utiliser Vim ====== | ||
- | CheatSheet : https:// | + | CheatSheet : [[https:// |
- | https:// | + | [[https:// |
- | https:// | + | [[https:// |
===== Commandes ===== | ===== Commandes ===== | ||
- | |||
< | < | ||
+ | |||
vimtutor fr | vimtutor fr | ||
</ | </ | ||
+ | |||
< | < | ||
cp / | cp / | ||
</ | </ | ||
+ | |||
+ | ===== Notions vim ===== | ||
+ | |||
+ | buffer : espace mémoire associé à un fichier ouvert | ||
+ | |||
+ | views : espace de l' | ||
+ | |||
+ | tab : onglet contenant une ou des views | ||
+ | |||
+ | Il est possible d' | ||
+ | |||
+ | Il est possible d' | ||
+ | |||
+ | ===== Configuration .vimrc ===== | ||
+ | |||
+ | < | ||
+ | cp /etc/vimrc ~/.vimrc | ||
+ | |||
+ | </ | ||
+ | |||
+ | Et le personnaliser avec : | ||
+ | |||
+ | < | ||
+ | set mouse=r # pour gestion copier/ | ||
+ | set number | ||
+ | set tabstop=4 | ||
+ | set expandtab | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== Templates ===== | ||
+ | |||
+ | Créer le dossier templates : | ||
+ | |||
+ | < | ||
+ | mkdir -p ~/ | ||
+ | |||
+ | </ | ||
+ | |||
+ | Créer ou récupérer des modèles comme '' | ||
+ | < | ||
+ | < | ||
+ | <html xmlns=" | ||
+ | < | ||
+ | < | ||
+ | <meta http-equiv=" | ||
+ | <meta http-equiv=" | ||
+ | <meta name=" | ||
+ | <meta name=" | ||
+ | <meta name=" | ||
+ | <meta name=" | ||
+ | <meta name=" | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
+ | Puis les activer dans .vimrc par extension : | ||
+ | |||
+ | < | ||
+ | au bufNewFile *.html 0r ~/ | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==== 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 | ||