Vim help
version available in : it ru zh es ja de nl fr
date of creation : 20220618- date of update : 20220618- generation date : 20240612_171233
vim vim_25_presentation_by_bram_moolenaar_on_2016_november_2 mastering_the_vim_language
You have just entered the vim editor.
You can use the arrow keys (arrows and pagination) to move around in this text.
The most important thing to know that makes vim (vi) unique is the fact that vim (vi) is a multimode editor.
The major feature of the vim editor (vi) is to operate primarily in the . mode commande vi We can say that there are two kinds of editors those that work by default and mainly in an editing mode (we type on the keyboard and it writes text) and those that work by default and mainly in a command mode (we type on the keyboard and it does things).
In the first one there are all editors except vi and vim (emacs, ultraedit, notepad, ...getting started with vim) in the second one there are vi and vim.
vim is the historical extension, the development of the original vi of the unix system which has not evolved except by vim.
The modes of vim are:
In vim the input mode is identical to an editor like notepad.
You enter this mode from the . mode commande vi by entering the following commands:
These are in fact the commands of the "teletype" editor, the precursor of vi, the "ed" editor..
When computer input could be viewed on a screen rather than on a teletype, "ed" evolved into "vi" (which is an abbreviation of "visual").
This means that "vi" contains the genes of "ed".
ed by the way gave birth to the command "sed" which could mean "stream ed" for example.
This mode is accessed by entering the character ".:" from . mode commande vi .
Under vim, it is possible to retrieve commands already entered by navigating with the up and down arrows.
You can even enter the beginning of a command and then use the arrows to select only the commands corresponding to the prefix entered.
order note_en action
:b nn rend courant le buffer (fichier) identified under the number "nn", for the list of buffers see command :ls
:e file edit the file whose path is entered :g/expr/ global : selects the lines that contain the regular expression "exp" and : :g/expr/l - list the lines :g/expr/d - destroys the lines :g/expr/s/// - applies the substitution command "s" to the selected lines :ls lists the buffers already edited during the session and displays their number (see order :b nn) :n next - outputs the next buffer if multiple files were requested :q leave the editor ":q!" force output without saving :r rewind - returns to the first buffer requested when opening vi or when ordering ":n file" :s . substitution de chaine :w saves the current file ":w!" force rewriting in case of warning :x eXit saves the current buffer and exits vi :map_en creates a new command for the . mode commande vi by command combination of this mode ! . shell vi allows interaction with the external environment of the program vi, offers unlimited possibilities / or :/ search for a . expression régulière (targets are displayed in yellow) the "n" command allows you to navigate the search
vim
specific :gf go file, opens the file whose path is under the cursor :sp split ,splits the workspace in two to open a second buffer switch by ctrl-W w :tabnew added a workspace tab
The use of the " character!" in different contexts allows to launch system commands.
On the command line vi for example type ":!dir " to open a shell and run the dir command.
or in . mode commande vi , "!" followed by a move command (ne
would be that ENTER) displays a prompt on which you can enter a command
system. The buffer selected by the move is sent to the standard input of the (stdin)
and the standard output of the (stdout) is retrieved and places the result in the delimited buffer
by moving (the old buffer is lost).
We can launch a SQL query with the isql command, transform a text with a perl script,
write C programs to create new editing commands, ... The possibilities are endless.
the order :map allows you to create a new command.
For example the command :"map ² j.
" creates the command "²" which finds the last command on the next line.
5.3.1.Example command map analogy vim mq
I can't help but make an amusing analogy here with the <mécanique_quantique_en_nweb>(fr.wikipedia.org/wiki/M%C30X0P+09canique_quantique) and the Hamiltonian H operator
responsible for the evolution over time. This operator can be seen as the combination of the operators of creation and destruction of energy states (or particles in the quantum field theory).
The energies are often H = potential energy kinetic energy = a² b² and with the complex factorization or i²=-1 H = (a ib)(a-ib) = C * D, C and D being the creation and destruction operators.
If we consider a line of text in vim and the "x" command to delete a character (destruction),
the default buffer content insertion command "p" (creation)
and their combination "xp" in a command ":map
we will have created the new command ": the evolution.
But here the space is symbolized by a line of underscore and for example the character o as a particle :
by applying the command ".
You can also create the inverse operator by ":map
__________________________________o___________________________________________________________________
- execute the macros by placing yourself on the "o" (the quantum particle :-quantum mechanics nweb)
- to compile the macros without copying them to the command line you can use the macro [xlm_en] by placing yourself on the line of the macro.
map
map
- A trajectory can be defined by
map #H
- A cyclical trajectory (oscillation) by the recursive macro:
map #S #H#S
- Attention this resursive macro can only be interrupted by CTRL-C
you can see that when you stop the macro you leave the system with the destroyed particle, the "o" has disappeared (it has returned to the quantum vacuum) or created, the "o" is present but probably elsewhere than in its initial position.
This tells us that when a macro is interrupted it is done on a "atomic" command and not on a macro called by a macro.
I think this example shows the dynamics of macros very well.
In Vim there is another way to record a command sequence.
This is the "q" command that allows you to record the sequence of commands that will be typed on the keyboard (entering another "q" stops the registration) and the "@" command which allows to execute these commands.
Commands are stored in buffers named by an alphanumeric character that must be specified in conjunction with the commands "q" and "@".
For example q03dwj stores in buffer 0 the command 3dwjbbb which deletes 3 words and moves to the next line by going back 3 words while executing this sequence.
the @0 command allows to repeat the sequence.
The command ":s/chaine1/chaine2/" of chain1 by chain2 substitution offers very powerful possibilities: If you want to make changes to the "/" character you must use "\\/" to specify this character or use another string delimiter character ":s.
chaine1.
channel2.
"
:s/toto/titi/ replace "toto" with "titi" on the line
:s/toto/titi/g replace all "toto" with "titi" on the line :1,$/toto/titi/g replace all "toto" with "titi" on the whole file :., 10/toto/titi/g replace all "toto" with "titi" starting from the current line on ten lines :g/tata/s/to/titi/g replace all "toto" with "titi" on all lines that contain the string "tata" :'a,'bg/tata/s/to/titi/g replaces all "toto" with "titi" on all lines that contain the string "tata" between the lines stored by the indexes "a" and "b"
5.4.1.. expression régulière : regular expression
Regular expressions allow you to specify complex search strings.
The " character." is used to specify any character.
The "*" character is used to specify any sequence of characters.
The ""^ character is used to specify the beginning of the line
The "$" character is used to specify the end of the line
A block "" is used to specify a possible character set in the regular expression.
For example :
For example "toto.*titi" designates the portion of lines that start with toto and end with titi.
For example ".*this.*titi.*" designates the lines that contain both toto and titi in this order.
For example "^toto.*titi$" designates lines that start with toto and end with titi.
|" (backslash-pipe)
so "toto.|titi.*toto" allows for example in a g//s// command to
make the modification only on the lines corresponding to the criterion.
We are almost at the level of a text mode requester.
It is possible to break down a line or a portion of a line into sub-fields in a regular expression
in the command ":s".
Example: target chain: "Beautiful marquise your beautiful eyes make me die of love" (B.)(v.)()()()" which is called \\1 \\2 \\3 \\4 \\5
The command ":(B.)(v.)()()()/\\5 \\4\\3/" with all permutations of subfields generate less beautiful forms of proses of the first sentence: of love your beautiful eyes die me Beautiful marquise
It is this mode that explains the power of vim.
Each key is a command.
There are major types of commands:
You can combine commands of different types: change*move, for example :
The move commands, see type "d" in the list . vimaz can be combined with other change commands to form a new change command.
The arrow keys are of course operational and work in conjunction with the SHIFT, CTRL.
The modification commands, see type "m" in the list . vimaz
Search commands, see type "r" in the list . vimaz
6.4.Commande de gestion de buffer vi
The buffer commands, see type "g" in the list . vimaz
6.5.. vimaz :I came from A to Z
The vim alphabet.
When you are in . mode commande vi each letter is a command :
column description
. lettre
the letter of the order. It can be a single letter, doubled, followed by another letter, followed again by the type of a command
Doubled letter mentioned by ² which is not used by vim Letter followed by any other letter this last case is indicated by the presence of a "underscore" for example f_ Followed by the type of a command "d" for displacement for example, in this case all displacement commands are operative . commande type
order type : d Move, m Edit, r Search, g Buffer management . note vim
utility or power of the control mentioned by a series of more ... or less . mnemo
origin of the use of the letter for the command, mnemonic means, in English necessarily
. lettre . type cmd . mnemo . note vim action
. caractère non alphabétique vi
. m repeats the last modification command ~ m upper-case-lower-case reverse. To be used with "g" : g~d ^ d goes to the beginning of the line $ d goes to the end of the line * r vim searches for the word under the cursor : all targets are colored yellow . See here g* '_ d "cote" followed by a letter moves the cursor to the line stored by that letter see m_ "_yd g "double dimension" followed by a letter, followed by "y" yank followed by a move command stores the text to be moved in a buffer named by this letter "ayfo g example: "afo stores in the buffer "a" from the current character to the next "o" on the current line "byy g "byy stores the current line in buffer b "by'b g "b'b stores in the buffer b from the current line to the line stored by the index b . caractère alphabétique vi
a m append adds text after the current character and switches to . mode de saisie vi A md Append adds text at the end of the line switches to . mode de saisie vi b d back moves the cursor back one word, if . majuscule the words are just separated by blanks and spaces B d Back idem "b" si . majuscule words defined by what is separated by blanks and spaces c_ m change - "c" followed by a . commande de déplacement vi changes the text from the current character to the end of the move C m Change - changes the text from the current character to the end of the line dd m delete "d" followed by a . commande de déplacement vi deletes the text from the current character to the end of the move d² m delete "d" doubled deletes the current line D m delete deletes the text from the current character to the end of the line e d end moves the cursor to the end of the current word E d End moves the cursor to the end of the ". mot large " current f_ r find "f" followed by a character moves the cursor on the line to the character if it exists F_ r find "F" same as "f" but moves to the beginning of the line g² d go moves the cursor to the beginning of the file G d go moves the cursor to the end of the file g* r global (vim) same as "*" but it is not the word but the string that is searched (if it appears in a word) g~d m global inverts lower case letters until you move gf d go file edit the file whose path is under the cursor i m insert insert the characters typed later before the current character toggles to . mode de saisie vi I md Insert insert the characters typed later at the beginning of the line toggles to . mode de saisie vi J m join concatenates the current line with the next one (merging of two lines) a blank is inserted between the two lines displacement keyboard : hjkl jk:up down , hl left right (to be used in the macro instead of the arrows) original keyboard without trackpad . touches de déplacement vi
h d left arrow j d up arrow k d down arrow l d right arrow m_ d memorise "m" followed by a letter memorizes the next line with this letter as index, the recall is done with the "cote" character: ' o m open opens or inserts a line after the current line O m Open opens or inserts a line BEFORE the current line p m put inserts the content of the current buffer r_ m replace replaces the current character toggle remains in . mode commande vi R m Replace replaces the text from the current position switches to . mode de saisie vi s m subsitute replaces the text from the current position switches to . mode de saisie vi S m Subsitute - substitutes the current line with the characters typed later and switches to . mode de saisie vi t_ r to "t" followed by a character moves the cursor to the line immediately before the character if it exists T_ r To "T" same as "t" but moves to the beginning of the line (usefulness in combination with double-rated control u m undo "undo" undoes the last modification. undo cancels all changes since the last edited file change . "redo" ctrl-r is the inverse of undo v g (vim) enters the text selection mode (linear view of the text) ctrl-v in rectangular block selection mode (surface vision of the text) w d end moves the cursor to the end of the current word W d End moves the cursor to the end of the ". mot large " current x m removes the letter yd g yank "y" followed by a . commande de déplacement vi stores in the default buffer the text concerned by the move, used in conjunction with the buffers named cf "_ z² "z." or "zz" centers the window on the current line z. ENTER
positions the current line at the top of the window z- positions the current line at the bottom of the window . commandes utilisant la touche CTRL
CTRL-R "redo"^ inverse of "u"" "undo"^ CTRL-A increments the number under the cursor CTRL-X decrements the number under the cursor
How to move easily in a file you are working on.
a word defined by what is separated by blanks and spaces only.
example: "since Monday morning" is a single "broad word"
In vi the alteration of a key by shift (upper case) alters the command corresponding to the lowercase.
The alteration can be of several types but the resulting command is close to the initial.
possible alteration: