informatique:vim
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
informatique:vim [2021/11/12 06:29] – [Chaîner des substitutions] alexis | informatique:vim [2022/09/28 04:21] (Version actuelle) – [Convertir en HTML] alexis | ||
---|---|---|---|
Ligne 27: | Ligne 27: | ||
- [[https:// | - [[https:// | ||
- [[https:// | - [[https:// | ||
- | - [[https:// | ||
- | - [[https:// | ||
</ | </ | ||
Ligne 34: | Ligne 32: | ||
La manière la plus simple d' | La manière la plus simple d' | ||
+ | <WRAP prewrap> | ||
<code bash> | <code bash> | ||
vim < | vim < | ||
</ | </ | ||
+ | </ | ||
Dans ce cas, le curseur se positionnera sur le premier caractère du fichier. Il est possible d' | Dans ce cas, le curseur se positionnera sur le premier caractère du fichier. Il est possible d' | ||
+ | <WRAP prewrap> | ||
<code bash> | <code bash> | ||
# Pour positionner le curseur sur une ligne sélectionnée par son numéro | # Pour positionner le curseur sur une ligne sélectionnée par son numéro | ||
Ligne 48: | Ligne 49: | ||
vim +$ < | vim +$ < | ||
</ | </ | ||
+ | </ | ||
Il est également possible d' | Il est également possible d' | ||
+ | <WRAP prewrap> | ||
<code bash> | <code bash> | ||
vim < | vim < | ||
</ | </ | ||
+ | </ | ||
Enfin, il est possible d' | Enfin, il est possible d' | ||
+ | <WRAP prewrap> | ||
<code bash> | <code bash> | ||
:open < | :open < | ||
</ | </ | ||
+ | </ | ||
+ | |||
===== Enregistrer un fichier en lecture seule ===== | ===== Enregistrer un fichier en lecture seule ===== | ||
On oublie tous un jour ou l' | On oublie tous un jour ou l' | ||
Il est possible de ne plus faire ça en utilisant la commande suivante : | Il est possible de ne plus faire ça en utilisant la commande suivante : | ||
+ | <WRAP prewrap> | ||
<code vim> | <code vim> | ||
:w !sudo tee % >/ | :w !sudo tee % >/ | ||
</ | </ | ||
+ | </ | ||
Cette commande lance la commande //sudo tee < | Cette commande lance la commande //sudo tee < | ||
On peut même se passer de cette commande en ajoutant l' | On peut même se passer de cette commande en ajoutant l' | ||
+ | <WRAP prewrap> | ||
<code vim> | <code vim> | ||
cnoremap sudow w !sudo tee % >/ | cnoremap sudow w !sudo tee % >/ | ||
</ | </ | ||
+ | </ | ||
Il suffit ensuite d' | Il suffit ensuite d' | ||
+ | <WRAP prewrap> | ||
<code vim> | <code vim> | ||
:sudow | :sudow | ||
</ | </ | ||
+ | </ | ||
===== Saisir des caractères de contrôle ===== | ===== Saisir des caractères de contrôle ===== | ||
Ligne 113: | Ligne 126: | ||
==== Utiliser des regexp ==== | ==== Utiliser des regexp ==== | ||
Le fonctionnement des regexp est inversé par rapport à d' | Le fonctionnement des regexp est inversé par rapport à d' | ||
+ | <WRAP prewrap> | ||
<code bash> | <code bash> | ||
# Pour supprimer '' | # Pour supprimer '' | ||
: | : | ||
</ | </ | ||
+ | </ | ||
==== Changer de casse ==== | ==== Changer de casse ==== | ||
Ligne 125: | Ligne 140: | ||
* Mettre en minuscule la première lettre du texte qui suit : '' | * Mettre en minuscule la première lettre du texte qui suit : '' | ||
+ | <WRAP prewrap> | ||
<code bash> | <code bash> | ||
:%s/Test \(TeSt\) Test/Test \U\1 Test/ # Affiche "Test TEST TEST" | :%s/Test \(TeSt\) Test/Test \U\1 Test/ # Affiche "Test TEST TEST" | ||
Ligne 133: | Ligne 149: | ||
:%s/Test \(TeSt\) Test/Test \l\1 Test/ # Affiche "Test teSt Test" | :%s/Test \(TeSt\) Test/Test \l\1 Test/ # Affiche "Test teSt Test" | ||
</ | </ | ||
+ | </ | ||
==== Chaîner des substitutions ==== | ==== Chaîner des substitutions ==== | ||
Pour cela, il suffit juste d' | Pour cela, il suffit juste d' | ||
+ | <WRAP prewrap> | ||
<code bash> | <code bash> | ||
: | : | ||
</ | </ | ||
+ | </ | ||
==== Utiliser une expression ==== | ==== Utiliser une expression ==== | ||
Il est possible d' | Il est possible d' | ||
+ | <WRAP prewrap> | ||
<code bash> | <code bash> | ||
# Ajouter le numéro de chaque ligne | # Ajouter le numéro de chaque ligne | ||
Ligne 151: | Ligne 171: | ||
: | : | ||
</ | </ | ||
+ | </ | ||
===== Copier du texte dans le presse-papier ===== | ===== Copier du texte dans le presse-papier ===== | ||
Voici une solution qui ne nécessite aucun programme supplémentaire : | Voici une solution qui ne nécessite aucun programme supplémentaire : | ||
+ | <WRAP prewrap> | ||
<code bash> | <code bash> | ||
:%w !xclip -in -selection clipboard | :%w !xclip -in -selection clipboard | ||
</ | </ | ||
+ | </ | ||
Pour d' | Pour d' | ||
===== Convertir les fins de ligne ===== | ===== Convertir les fins de ligne ===== | ||
+ | <WRAP prewrap> | ||
<code bash> | <code bash> | ||
:set ff=dos | :set ff=dos | ||
Ligne 165: | Ligne 189: | ||
:set ff=mac | :set ff=mac | ||
</ | </ | ||
+ | </ | ||
[[https:// | [[https:// | ||
+ | |||
+ | ===== Convertir en HTML ===== | ||
+ | Il est possible de convertir le contenu d'un fichier en HTML en utilisant '' | ||
+ | Il est possible de le faire également en mode CLI de la manière suivante : | ||
+ | <WRAP prewrap> | ||
+ | <code bash> | ||
+ | # Convertir tout le fichier | ||
+ | vim -e < | ||
+ | |||
+ | # Convertir une partie du fichier (de la ligne 10 à la ligne 20 incluse) | ||
+ | vim -e < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | Avec l' | ||
+ | <WRAP prewrap> | ||
+ | <code bash> | ||
+ | # Avec un arrière plan foncé | ||
+ | vim -e < | ||
+ | |||
+ | # Avec un arrière plan clair | ||
+ | vim -e < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <WRAP tip> | ||
+ | Il est intéressant de pouvoir convertir le fichier HTML généré en image pour pouvoir l' | ||
+ | </ | ||
+ | |||
+ | ==== Exemple ==== | ||
+ | === Fichier source === | ||
+ | <WRAP prewrap> | ||
+ | <code python event.py> | ||
+ | class Card: | ||
+ | def __init__(self, | ||
+ | self.event=event | ||
+ | self.person=person | ||
+ | |||
+ | def message(self): | ||
+ | print(f" | ||
+ | |||
+ | card = Card(' | ||
+ | card.message() | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | === Résultat avec le thème sombre === | ||
+ | <WRAP prewrap> | ||
+ | <code html event.py.dark.html> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | <meta charset=" | ||
+ | < | ||
+ | <meta name=" | ||
+ | <meta name=" | ||
+ | <meta name=" | ||
+ | <meta name=" | ||
+ | <meta name=" | ||
+ | < | ||
+ | <!-- | ||
+ | pre { white-space: | ||
+ | body { font-family: | ||
+ | * { font-size: 1em; } | ||
+ | .LineNr { color: #ffff00; } | ||
+ | .Constant { color: #ff40ff; } | ||
+ | .Identifier { color: #00ffff; font-weight: | ||
+ | .Statement { color: #ffff00; } | ||
+ | --> | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | <!-- | ||
+ | |||
+ | /* function to open any folds containing a jumped-to line before jumping to it */ | ||
+ | function JumpToLine() | ||
+ | { | ||
+ | var lineNum; | ||
+ | lineNum = window.location.hash; | ||
+ | lineNum = lineNum.substr(1); | ||
+ | |||
+ | if (lineNum.indexOf(' | ||
+ | lineNum = ' | ||
+ | } | ||
+ | var lineElem = document.getElementById(lineNum); | ||
+ | /* Always jump to new location even if the line was hidden inside a fold, or | ||
+ | * we corrected the raw number to a line ID. | ||
+ | */ | ||
+ | if (lineElem) { | ||
+ | lineElem.scrollIntoView(true); | ||
+ | } | ||
+ | return true; | ||
+ | } | ||
+ | if (' | ||
+ | window.onhashchange = JumpToLine; | ||
+ | } | ||
+ | |||
+ | --> | ||
+ | </ | ||
+ | </ | ||
+ | <body onload=' | ||
+ | <pre id=' | ||
+ | <span id=" | ||
+ | <span id=" | ||
+ | <span id=" | ||
+ | <span id=" | ||
+ | <span id=" | ||
+ | <span id=" | ||
+ | <span id=" | ||
+ | <span id=" | ||
+ | <span id=" | ||
+ | <span id=" | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | <!-- vim: set foldmethod=manual : --> | ||
+ | </ | ||
+ | </ | ||
+ | {{: | ||
+ | </ | ||
+ | <WRAP half column> | ||
+ | === Résultat avec le thème clair === | ||
+ | <WRAP prewrap> | ||
+ | <code html event.py.light.html> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | <meta charset=" | ||
+ | < | ||
+ | <meta name=" | ||
+ | <meta name=" | ||
+ | <meta name=" | ||
+ | <meta name=" | ||
+ | <meta name=" | ||
+ | < | ||
+ | <!-- | ||
+ | pre { white-space: | ||
+ | body { font-family: | ||
+ | * { font-size: 1em; } | ||
+ | .LineNr { color: #af5f00; } | ||
+ | .Constant { color: #c00000; } | ||
+ | .Identifier { color: #008080; } | ||
+ | .Statement { color: #af5f00; } | ||
+ | --> | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | <!-- | ||
+ | |||
+ | /* function to open any folds containing a jumped-to line before jumping to it */ | ||
+ | function JumpToLine() | ||
+ | { | ||
+ | var lineNum; | ||
+ | lineNum = window.location.hash; | ||
+ | lineNum = lineNum.substr(1); | ||
+ | |||
+ | if (lineNum.indexOf(' | ||
+ | lineNum = ' | ||
+ | } | ||
+ | var lineElem = document.getElementById(lineNum); | ||
+ | /* Always jump to new location even if the line was hidden inside a fold, or | ||
+ | * we corrected the raw number to a line ID. | ||
+ | */ | ||
+ | if (lineElem) { | ||
+ | lineElem.scrollIntoView(true); | ||
+ | } | ||
+ | return true; | ||
+ | } | ||
+ | if (' | ||
+ | window.onhashchange = JumpToLine; | ||
+ | } | ||
+ | |||
+ | --> | ||
+ | </ | ||
+ | </ | ||
+ | <body onload=' | ||
+ | <pre id=' | ||
+ | <span id=" | ||
+ | <span id=" | ||
+ | <span id=" | ||
+ | <span id=" | ||
+ | <span id=" | ||
+ | <span id=" | ||
+ | <span id=" | ||
+ | <span id=" | ||
+ | <span id=" | ||
+ | <span id=" | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | <!-- vim: set foldmethod=manual : --> | ||
+ | </ | ||
+ | </ | ||
+ | {{: | ||
+ | </ | ||
+ | </ | ||
informatique/vim.1636727363.txt.gz · Dernière modification : 2021/11/12 06:29 de alexis