vim *** plein de doc http://www.catswhocode.com/blog/100-vim-commands-every-programmer-should-know Installation ============ il faut installer vim-full via un apt-get install .. code-block:: bash apt-get install vim-full Paramétrage =========== dans le fichier HOME/.vimrc il est possible d’ajouter des paramètres: .. code-block:: bash syn enable set number set autoindent set nopaste set shiftwidth=4 set softtabstop=4 set tabstop=4 syntax on set ai set hlsearch pour permettre que lors de l’indentation automatique les tabulations soient remplacé par des espaces il faut ajouter après autoindent .. code-block:: bash set expandtab pour empêcher la sauvegarde automatique .. code-block:: bash set nobackup set nowritebackup pour empêcher les bips en cas d'erreurs et les remplacer par un flash visuel .. code-block:: bash set visualbell pour avoir un visuel plus joli on peut modifier la font utilisée .. code-block:: bash set gfn=Courier:h11 pour avoir les raccourcit vers une liste de repertoire (plugin NERDTree) et les Crtl-c / a /v /x .. code-block:: bash map :NERDTree map ggVG map "+y map "+x map "+gP pour pouvoir lancer facilement la commande python par *F2* on peut ajouter dans .vimrc .. code-block:: bash function! Python() :! python "%" endfunction map :call Python() donc au total le .vimrc ressemble à ceci .. code-block:: bash " general syn enable set number set autoindent set expandtab set nopaste set shiftwidth=4 set softtabstop=4 set tabstop=4 set visualbell syntax on set ai "set hlsearch set nohlsearch set colorcolumn=81 set nobackup set nowritebackup " encoding set encoding=utf-8 set fileencoding=utf-8 " map copy/paste print map :e . map ggVG map "+y map "+x map "+gP map :w imap :w noremap :ha function! Load() if &filetype == "python" :! start cmd /k python "%" endif if &filetype == "dosbatch" :! start cmd /k "%" endif endfunction map :call Load() function! LoadDebug() if &filetype == "python" :! python -m pdb "%" endif endfunction map :call LoadDebug() function! LoadHelp() echo "ha print C-e explorer F5 load file F6 load debug" echo "ls list buffer bd del buffers b? select buffers q quit vi" echo " new tab new tab open v selected F2 terminal" echo "e file open file s/find/replace/g find and replace all :vert diffsplit file2 comparaison" endfunction map :call LoadHelp() "fonction tab :command New tabnew noremap :tabnew noremap :tabnew noremap :tabnew:e . noremap :tabnext noremap :tabprevious map v map v noremap v noremap v " open terminal function! Term() :!start cmd /k cd %:p:h endfunction :command TERM call Term() map :call Term() color mycolor pour l'encoding il faut en plus ajouter .. code-block:: bash set encoding=utf-8 set fileencoding=utf-8 On peut ajouter une fonction pour formatter notre code qui sera appellé par la commande format .. code-block:: bash " open terminal function! Format(synt) if a:synt == "python" :! start cmd /k python /opt/prettycode.py -i "%" -o "%" -s python endif if a:synt == "sql" :! start cmd /k python /opt/prettycode.py -i "%" -o "%" -s python endif if a:synt == "java" :! start cmd /k jalopy "%" endif if a:synt == "xml" :! start cmd /k xmllint --format "%" --output "%" endif endfunction :command FORMAT call Format(b:current_syntax) .. code-block:: bash pour linux il faut supprimer le "start cmd /k" pour avoir un gvim sans barre d'outil .. code-block:: bash :set guioptions-=m "remove menu bar :set guioptions-=T "remove toolbar :set guioptions-=r "remove right-hand scroll bar :set guioptions-=L "remove left-hand scroll bar .. warning:: sur windows il faut modifie le fichier _vimrc qui ce trouve dans le répertoire d'installation de gvim .. note:: pour avoir **un** gvim (une seule instance) avec plusieurs onglets essayer ceci .. code-block:: bash gvim first_file.dat gvim --remote-tab second_file.dat il est alors possible d'écrire un fichier bat (que vous pourrez transformer en exe) qui n'ouvre toujours qu'un gvim .. code-block:: bash @echo off tasklist /FI "IMAGENAME eq gvim.exe" | grep gvim.exe if ERRORLEVEL 1 goto Process_NotFound :Process_Found "C:\Program Files\Vim\vim73\gvim.exe" --remote-tab "%1" goto END :Process_NotFound "C:\Program Files\Vim\vim73\gvim.exe" "%1" goto END :END pour ouvrir les fichiers avec **GVimOne** ainsi créé vous pouvez modifier dans un explorateur le paramétrage via Outil\Option des dossiers\Types de fichier .. figure:: data\20110214_1.jpg Pour windows 7 (Vista) on peut créer un nouveau "Edit with gVimOne" en modifiant la base de registre .. code-block:: bash Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\*\shell\Open with gvim] @="Edit with gVimOne" [HKEY_CLASSES_ROOT\*\shell\Open with gvim\Command] @="C:\\Program Files\\Vim\\vim73\\gvimOne.exe \"%1\"" .. warning:: sous windows 8 pour avoir les accents en mode console il faut ajouter :: set encoding=utf-8 set termencoding=cp1252 et dans alias.bat un "chcp 1252" afin d'être sur d'avoir une console dos avec un encoding en 1252 Utilisation =========== l’autocomplementation .. code-block:: bash + + + .. note:: il existe plusieurs mode d’auto-complementation basé sur le type de code, un dictionnaire ou bien sur ce qui est déjà écrit lancement d’une commande .. code-block:: bash :!ma_commande Commande utile ============== .. warning:: il faut ajouter ":" avant chaque commande - o NameFile ouverture d’un fichier - w [NameFile] enregistrement d’un fichier - file NameFile sauvegarde du fichier - q fermeture - ha impression - crtl+g fin de fichier - sh accès un une console classique (exit pour revenir au fichier) - "! cmd" lance la commande cmd - r file insère le contenu du fichier dans le buffer - r !cmd envoie le contenu de la commande dans le buffer - yy copie la ligne courante - xp colle le tampon - A ce place en fin de ligne - /tutu recherche la chaine tutu - s/chaine à chercher/texte de remplacement/g recherche et remplace - e . Ouvre l’explorateur de fichiers intégré - Sex sépare en la fenetre en deux et ouvre l’explorateur - crtl + w se déplace dans les fenêtres - crtl+n complète le mot - crtl+x compléte le mot en utilisant le dictionnaire - buffers liste des fichiers ouverts - ls même chose que :buffers - buffer 2 ouvre le fichier contenu dans le tampon 2 les buffeurs: .. code-block:: bash : ls [liste des buffers] : bx (x=numero du buffer) [atteindre un buffer] :e # [passer au buffer suivant] :bd [supprime le buffer en cours] Editer le premier buffer avec fleche haut .. code-block:: bash noremap :1b! Editer le dernier buffer avec fleche bas .. code-block:: bash noremap :blast! Editer le prochain buffer avec fleche droite .. code-block:: bash noremap :bnext! Editer le précédent buffer avec fleche gauche .. code-block:: bash noremap :bprevious! lancer une commande .. code-block:: bash :! cmd lancer la commande python avec le fichier en paramètre .. code-block:: bash :! python "%" recherche / remplace .. code-block:: bash :/tutu recherche la chaine tutu :s/chaine à chercher/texte de remplacement/g recherche et remplace plugin ====== NERDTree -------- très utile: il suffit de lancer la commande :NERDTree pour voir un arbre des répertoire apparaitre AirLine ------- permet d'avoir une barre d'état plus jolie et avec plus d'information l'installation .. code-block:: bash cd .vim git clone https://github.com/bling/vim-airline.git mv vim-airline/* . rm -Rf vim-airline/ rm Gemfile rm LICENSE rm Rakefile rm README.md wget https://github.com/Lokaltog/powerline/raw/develop/font/PowerlineSymbols.otf mv PowerLineSymbols.otf .fonts/ fc-cache -vf .~/.fonts .. note:: si le dossier ~/.vim n'existe pas il faut le créer. On peut mettre aussi le fichier .vimrc avec un lien sur ~ ce qui permet de garder toutes la configuration de vim dans un même répertoire le paramétrage de vim dans .vimrc .. code-block:: bash " Airline setup "------------------------------------------------------------------------------ set t_Co=256 set laststatus=2 let g:airline_powerline_fonts=1 let g:airline#extensions#tabline#enabled = 1 Afin d'avoir la barre du type .. figure:: data/vimairline_01.png il faut que le terminal utilise la font Powerlinesymbol ... exemple de configuration dans gnome-terminal .. figure:: data/vimairline_02.png vous pouvez trouver d'autres font powerline sur http://github.com/Lokaltog/powerline-fonts sous windows il faut installer la police DejaVuSansMono Powerline que vous pouvez trouver sur le lien https://github.com/Lokaltog/powerline-fonts puis modifier la police dans gvim. Cette modification peut être définitive si on ajoute dans .vimrc .. code-block:: bash set guifont=DejaVu\ Sans\ Mono\ for\ Powerline Pour le vim en console sous windows je n'ai pas trouvé de solution pour utiliser la font, il faut modifier le fichier .vimrc ainsi .. code-block:: bash let g:airline_powerline_fonts=0 let g:airline_left_sep='>' let g:airline_right_sep='<' .. note:: tout cela a été trouvé dans la doc de airline :help airline Tabular ------- mes en colonnes les élements par rappor à un élément `(=, |, ...)` .. code-block:: bash :Tab / :Tab = créer une nouvelle synthaxe =========================== dans le répertoir vim73/synthax créer un fichier fred.vim (qui est une copie de python.vim par exemple) dans le fichier .vimrc ajouter la ligne .. code-block:: bash autocmd BufRead *.fred set ft=fred et voila maintenant tout les fichiers `*.fred` s'ouvrirons avec la synthaxe fred coloration ========== n'ayant pas trouvé ce qui me convenait sous le terminal windows voilà deux exemples simple mais efficase mycolor.vim :: " local syntax file - set colors on a per-machine basis: " vim: tw=0 ts=4 sw=4 " Vim color file " inpired by: Ron Aaron set background=dark hi clear if exists("syntax_on") syntax reset endif let g:colors_name = "mycolor" hi Normal ctermfg=White ctermbg=black guifg=cyan guibg=black hi Comment term=bold ctermfg=DarkGrey ctermbg=black guifg=#80a0ff hi Constant term=underline ctermfg=Magenta ctermbg=black guifg=Magenta hi Character term=underline ctermfg=Green ctermbg=black guifg=Green hi Special term=bold ctermfg=Magenta ctermbg=black guifg=Red hi Identifier term=underline ctermfg=Cyan ctermbg=black guifg=#40ffff cterm=bold hi Statement term=bold ctermfg=Yellow ctermbg=black guifg=#aa4444 gui=bold hi PreProc term=underline ctermfg=Red ctermbg=black guifg=#ff80ff hi Type term=underline ctermfg=LightGreen ctermbg=black guifg=#60ff60 gui=bold hi Function term=bold ctermfg=cyan ctermbg=black guifg=cyan hi Repeat term=underline ctermfg=Red ctermbg=black guifg=white hi Operator ctermfg=Red ctermbg=black guifg=Red hi Ignore ctermfg=black ctermbg=black guifg=bg hi Error term=reverse ctermfg=White ctermbg=Red guibg=Red guifg=White hi Todo term=standout ctermfg=Black ctermbg=Yellow guifg=Blue guibg=Yellow hi LineNr ctermfg=Darkgreen ctermbg=black cterm=italic hi Excep ctermfg=brown ctermbg=black " Common groups that link to default highlighting. " You can specify other highlighting easily. hi link String Character hi link Character Character hi link Number Constant hi link Boolean Constant hi link Float Number hi link Conditional Repeat hi link Label Statement hi link Keyword Statement hi link Exception Excep hi link Include PreProc hi link Define PreProc hi link Macro PreProc hi link PreCondit PreProc hi link StorageClass Type hi link Structure Type hi link Typedef Type hi link Tag Special hi link SpecialChar Special hi link Delimiter Special hi link SpecialComment Special hi link Debug Special mycolorinv.vim :: " local syntax file - set colors on a per-machine basis: " vim: tw=0 ts=4 sw=4 " Vim color file " inpired by: Ron Aaron set background=dark hi clear if exists("syntax_on") syntax reset endif let g:colors_name = "mycolorinv" hi Normal ctermfg=Black ctermbg=White guifg=cyan guibg=White hi Comment term=bold ctermfg=DarkGrey ctermbg=White guifg=#80a0ff hi Constant term=underline ctermfg=DarkMagenta ctermbg=White guifg=Magenta hi Character term=underline ctermfg=Darkgreen ctermbg=White guifg=Darkgreen hi Special term=bold ctermfg=DarkMagenta ctermbg=White guifg=Red hi Identifier term=underline ctermfg=Cyan ctermbg=White guifg=#40ffff cterm=bold hi Statement term=bold ctermfg=Blue ctermbg=White guifg=#aa4444 gui=bold hi PreProc term=underline ctermfg=Red ctermbg=White guifg=#ff80ff hi Type term=underline ctermfg=Darkgreen ctermbg=White guifg=#60ff60 gui=bold hi Function term=bold ctermfg=DarkCyan ctermbg=White guifg=cyan hi Repeat term=underline ctermfg=Red ctermbg=White guifg=white hi Operator ctermfg=Red ctermbg=White guifg=Red hi Ignore ctermfg=White ctermbg=White guifg=bg hi Error term=reverse ctermfg=Black ctermbg=Red guibg=Red guifg=White hi Todo term=standout ctermfg=Black ctermbg=Yellow guifg=Blue guibg=Yellow hi LineNr ctermfg=Darkgreen ctermbg=White cterm=italic hi Excep ctermfg=brown ctermbg=White " Common groups that link to default highlighting. " You can specify other highlighting easily. hi link String Character hi link Character Character hi link Number Constant hi link Boolean Constant hi link Float Number hi link Conditional Repeat hi link Label Statement hi link Keyword Statement hi link Exception Excep hi link Include PreProc hi link Define PreProc hi link Macro PreProc hi link PreCondit PreProc hi link StorageClass Type hi link Structure Type hi link Typedef Type hi link Tag Special hi link SpecialChar Special hi link Delimiter Special hi link SpecialComment Special hi link Debug Special " color dispo " Black White " Green DarkGreen LightGreen " Brown " Red DarkRed LightRed " Grey DarkGrey LightGrey " Magenta DarkMagenta LightMagenta " Cyan DarkCyan " Yellow DarkYellow LightYellow " Blue DarkBlue LightBlue