Loading...
Loading...
Introduction The vi text editor , which is installed with all versions of OneFS , can be used to create and edit files stored on the cluster . This article lists commands that can be used in the vi editor.
N/A
Commands This article lists the most common and useful vi commands. To view all vi commands and their descriptions, run the following command: man vi Modes The vi editor has two modes: command mode and insert mode. The editor starts up in command mode . When in command mode, the cursor can be moved to a specified location in a file to paste and delete text. When in insert mode, text can be entered and edited in a file. To enter insert mode, enter an insert or change command. To return to the command mode, press ESC. NOTE : Most commands run when they are typed. Commands that begin with a colon ( : ) run after pressing ENTER. Quit the vi editor. Command Function :x Exit, saving changes :q Exit if there have been no changes. :q! Exit and ignore any changes. Insert text Command Function i Insert before cursor I Insert before line a Append after cursor A Append after line o Open a new line after current line. O Open a new line before the current line. r Replace one character. R Replace many characters. Move through a file Command Function h Move left. j Move down. k Move up. l Move right. w Move to the next word. b Move to the beginning of the word e Move to the end of the word 0 Move to the beginning of the line $ Move to the end of the line 1G Move to the first line of the file G Move to the last line of the file nG Move to the n th line of the file. : n Move to the n th line of the file. f x Move forward to letter x. F x Move back to letter x. H Move to top of screen. M Move to middle of screen L Move to bottom of screen. Delete text. Almost all delet e commands are performed by typing d followed by a move command . For example, dw deletes a word. Additional delete commands are listed in the table below. Command Function x Delete character to the right of the cursor. X Delete character to the left of the cursor. dw Delete a word. D Delete to the end of the line. dd Delete current line. :d Delete current line. Yank (copy) text. Like delet e commands , almost all yank (copy) commands are performed by typing y followed by a move command . For example, y$ yanks to the end of the line. Additional yank commands are listed in the table below. Command Function y$ Yank to the end of the line. yy Yank the current line. :y Yank the current line. Put text. The put command places text that has been yanked (copied). Command Function p (lowercase) Put after the position or after the line. P (uppercase) Put before the position or before the line. Change text The change command is a delete command that leaves the editor in insert mode. It is performed by typing c followed by a move command . For example, cw changes a word. Additional change commands are listed in the table below. Command Function C Change to the end of the line cc Change the whole line. cw Change a word. Buffers Named buffers can be specified before any delete, change, yank, or put command. The general prefix has the form x where x is any lowercase character. For example, the adw command deletes a word into buffer a. It can be put back into the text using the appropriate ap command. The vi editor has 27 buffers where text can be stored. There is one for each letter of the alphabet and an unnamed buffer, which is where deleted text goes. When you delete text, any content stored in the unnamed buffer is pushed into buffer a. Content that was in buffer a is moved into buffer b, and any content in buffer b is moved to buffer c, and so on. Content in buffers remain undisturbed until replaced with other content, either when specifying that buffer in a command or when content is moved from the previous buffer. When exiting vi, all buffers are cleared. Search for strings Command Function / <string> Search forward for <string> ? <string> Search back for <string> n <string> Search for the next instance of <string> N <string> Search for the previous instance of <string> Replace The replace function is accomplished with the :s command. It is commonly used with ranges or the :g c ommand. For example, the :s/<pattern>/<string>/flags command, replaces <pattern> with <string> according to the flags listed below. Flag Function g Replace all occurrences of the pattern. c Confirm replaces. & Repeat last :s command. Regular Expressions Regular expressions can be used to specify patterns of text on which to perform search and replace operations. NOTE Regular expressions are case-sensitive. Expression Function . (dot) Any single character except the new line character * zero or more occurrences of any character [...] Any single character specified in the set (see examples below) [^...] Any single character not specified in the set ^ Anchor - beginning of the line $ Anchor - end of line \< Anchor - beginning of word \> Anchor - end of word \(...\) Grouping - used to group conditions \ n Contents of n th grouping [...] - Set Examples Expression Function [A-Z] The set from uppercase A to uppercase Z [a-z] The set from lowercase a to lowercase z [0-9] The set from 0 to 9 (All numerals) [./=+] The set containing . (dot), / (slash), =, and + [-A-F] The set from uppercase A to uppercase F and the dash (dashes must be specified before ranges) [0-9 A-Z] The set containing all uppercase letters and digits and a space [A-Z][a-zA-Z] In the first position, the set from uppercase A to uppercase Z. In the second character position, the set containing all letters Regular Expression Examples Expression Function /Hello/ Matches if the line contains the value Hello. /^TEST$/ Matches if the line contains TEST by itself. /^[a-zA-Z]/ Matches if the line starts with any letter. /^[a-z].*/ Matches if the first character of the line is a-z and there is at least one more of any character following it. /2134$/ Matches if the line ends with 2134. /\(21"35\)/ Matches is the line contains 21 or 35. Note the use of ( ) with the pipe symbol to specify the 'or' condition. /[0-9]*/ Matches if there are zero or more numbers in the line. /^[^#]/ Matches if the first character is not a # in the line. Counts Nearly every command could be preceded by a number that specifies how many times it is to be performed. For example, 5dw deletes five words and 3fe moves the cursor forward to the third occurrence of the letter e . Insertions can be repeated as well using this method, for example, to insert the same line 100 times. Ranges Ranges might precede most " colon " commands and cause them to be performed on a line or lines. For example, :3,7d deletes lines 3-7. Ranges are commonly combined with the :s command to perform a replacement on several lines. For example, the :.,$s/pattern/<string>/g command performs a replacement from the current line to the end of the file. Command Function :n,m Lines n-m :. Current line :$ Last line :'c Marker c :% All lines in file :g/<pattern>/ All lines that contain <pattern>. Files Command Function :w <file> Write to <file>. :r <file> Read <file> in after line. :n Go to next file. :p Go to previous file. :e <file> Edit <file>. !!program Replace line with output from program. Other commands Command Function ~ Toggle upper and lower case. J Join lines. . Repeat the last text-changing command. u Undo last change. U Undo all changes to the line.
Click on a version to see all relevant bugs
Dell Integration
Learn more about where this data comes from
Bug Scrub Advisor
Streamline upgrades with automated vendor bug scrubs
BugZero Enterprise
Wish you caught this bug sooner? Get proactive today.