Vigueur L’éditeur de texte est l’un des plus anciens et des meilleurs éditeurs de texte pour Linux. C’est une version grandement améliorée d’un bon vieux Éditeur Vi. Cet éditeur de texte contient de nombreuses fonctionnalités intéressantes telles que l’historique de la ligne de commande, la coloration syntaxique, l’annulation à plusieurs niveaux, le vérificateur d’orthographe, les opérations de bloc et le nom de fichier, etc. Dans cet article, nous apprendrons comment installer Vigueur sur CentOS.
+
Principales fonctionnalités de l’éditeur de texte Vim
- Il s’agit d’un éditeur multiplateforme disponible pour les systèmes d’exploitation Linux, Windows et Mac.
- Il est accessible à partir de l’interface de ligne de commande (CLI) et de l’interface utilisateur graphique (GUI).
- Il s’agit d’un éditeur de texte de haut niveau adapté à l’édition des langages de balisage.
Comment installer Vim sur CentOS
Vous devez exécuter la commande ci-dessous pour installer Vim sur CentOS :
sudo yum install vim
Une fois que vous avez appuyé sur Entrée, il vous demandera [y/d/N]
. Vous devez appuyer sur y pour continuer l’installation. Il installera vim et toutes les dépendances (vim-amélioré & vim-commun).
Un guide du débutant pour Vim
Ouverture de Vim
Vous pouvez utiliser vim
commande avec sudo
privilège d’ouvrir un fichier existant. Par exemple:
sudo vim name_of_the_document
Prenons un autre exemple et créons un autre document avec le nom de fichier “index.html” et ajouter quelques HTML
code dans le fichier. Pour ce faire, exécutez :
sudo vim newdocument.html
Maintenant, ajoutons quelques html
codes dedans :
<h1>Main Heading Goes Here</h1> <h2>Sub-Heading Goes Here</h2> <p>Paragraph Goes Here</P> <a href="#">Link</a> <hr> <h3>Another Sub-Heading Goes Here</h2> <p>Paragraph Goes Here</P> <a href="#">Link</a> <hr>
Pour enregistrer les modifications, appuyez sur deux-points :
et puis wq!
pour enregistrer et tout à fait les changements.
Édition modale
La plupart des éditeurs de texte n’ont qu’un seul mode alors que Vigueur l’éditeur a également un autre mode appelé « Édition modale » mode. C’est la principale différence entre Vigueur et tout autre éditeur de texte.
Dans « Édition modale »certaines fonctions spéciales sont activées pour vous aider à copier du texte en maintenant plusieurs touches de modification enfoncées, puis en appuyant sur une touche normale.
+
L’éditeur de texte Vim utilise ces modes distincts pour séparer ces fonctions de la tâche d’entrée normale.
Vérifions ces modes un par un :
Mode normal
Il est essentiellement utilisé pour les opérations d’édition telles que le copier-coller, la suppression, le déplacement et l’édition de texte.
Par défaut, Vim démarre dans “normal” mode. Si vous êtes dans un autre mode, vous pouvez revenir au mode normal en appuyant sur le bouton d’échappement ESC ou .
In normal mode, key presses do not work. But there are certain actions that you can perform to move the cursor.
+
Move the cursor
h
– move one character leftj
– move one row downk
– move one row upl
– move one character right
As many vim commands, row movement can be prefixed by a number to move s several lines at a time:
To move several lines, rows and characters, you can prefix a number.
4j
– This will move 4 rows down10l
– This will move 10 characters right
Basic word movements:
w
– move to the beginning of next wordb
– move to the beginning of the previous worde
– move to end of wordW
– move to the beginning of the next word after a white spaceB
– move to beginning of the previous word before a white spaceE
– move to end of the word before a white space
moving to the Beginning & End of the line:
0
– move to the beginning of the line$
– move to the end of the linegg
– move to the top of the document.G
– move to the bottom of the document. You can also prefix a number to go to that line number.w
– move to the next word. Prefix a number to move that many words.b
– move back one word. Prefix a number to move back that many words.e
– move to the end of the word. Prefic a number to move that many words.
Insert Mode
Insert mode is used for inserting new text in the document. It enables multiple editing options:
i
– Enters into the insert mode at the current cursor position.a
– Enters into the insert mode after the current position.o
– Inserts a new line below the current line. Also enters insert mode on the new line.I
– Enters into the insert mode at the beginning of the current line.A
– Enters insert mode at the end of the current line.O
– inserts a new line above the current line. Also enters insert mode on the new line.
To leave insert mode, press Esc
or <C-[>
Visual Mode
This third mode used by Vin Editor is known as the Visual Mode which is used for visual selection such as copying, pasting, deleting, replacing, and so on.
v
– To enter regular visual mode. This will mark a selection point and selections can be made by moving the cursor right, left, up, and down.V
– To enter visual line mode. It makes text selection by line. Which means that entire lines can be selected, from the first to the last character, by moving the cursor.-
[ctrl]-v
– Pour entrer en mode bloc visuel. Il sélectionne tout le bloc. Déplacer le curseur vers le haut ou vers le bas peut sélectionner plusieurs lignes de texte.
Presse ESC
ou , to leave visual mode and return to normal mode.
Command Mode
Command Mode is used for running vim commands. To enter in Command Mode, you simply need to hit the colon key.
:
– Enters command mode.
Command mode has variety of powerful features which can make your task a lot easier. For example, to do a global search and replace, you just need to type:
:%s/foo/bar/g
This particular command will replace all “foo” with “bar”.
:
Enters command mode%
Across all liness
Substitute/foo
is regex to find things to replace/bar/
is regex to replace things with/g
means global. If not mentioned, it would only execute once per line
For Vim related help or documentation, you can also run:
:h
or
:help
Editing
For editing purpose, Vim Editor must be in Normal mode to issue command.
Here are some of the actions that you can perform:
Deleting text
x
– to delete the character under the cursor.d
– to delete text that {motion} moves over. For example, “dl” command will deletes a character to the right.dd
– to delete a line.D
– to delete from the current position to the end of the line.
Changing Text
r
– It replaces the character under the cursor with some other character you input. You just need to substitute the character after issuing this command.c
– It changes the text in the direction that follows. For example, if you press “cw”, vim editor will take you to the insert mode where you can input your replacement text.C
– It change the text to the end of the line.
Copying and Pasting
y
– to copy in the direction that follows.yy
– to copy the entire line.Y
– to copy until the end of the line.p
– to paste the last line copied or deleted below the current line.P
– to paste the last line copied or deleted above the current line.
Miscellaneous Editing
u
– Undo<ctrl>-r
– RedoJ
– Join the current and below line.
Documents Management
To manage the document you must be inside the command line mode of the Vim editor. As you already know to enter in command line mode. You need to press colon “:” to enter and perform these command below:
:q
– to quit vim.:q!
– to forcefully quit vim and discard any unsaved changes.:w
– to save changes. You can also add a space and then a filename if you would like to save the file to a different location.:e
– to dit the file that follows.:bn
– to edit the next file that vim has open.:bp
– to edit the previous file that vim has open.
For more Vim Command and shortcuts, you can visit Vim Documentation.
[icon name=”fa-hand-o-right”] Tu pourrais aussi aimer:
J'espère que vous trouverez ce guide sur la façon d'installer Vim sur CentOS 7 utile.
Partagez vos opinions dans la section des commentaires ci-dessous.