<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://hpc-wiki.info/hpc/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Florian-bohlken-c7a9%40uni-muenster.de</id>
	<title>HPC Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://hpc-wiki.info/hpc/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Florian-bohlken-c7a9%40uni-muenster.de"/>
	<link rel="alternate" type="text/html" href="https://hpc-wiki.info/hpc/Special:Contributions/Florian-bohlken-c7a9@uni-muenster.de"/>
	<updated>2026-06-15T11:05:10Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.9</generator>
	<entry>
		<id>https://hpc-wiki.info/hpc/index.php?title=Introduction_to_Linux_in_HPC/The_vim_text_editor&amp;diff=5305</id>
		<title>Introduction to Linux in HPC/The vim text editor</title>
		<link rel="alternate" type="text/html" href="https://hpc-wiki.info/hpc/index.php?title=Introduction_to_Linux_in_HPC/The_vim_text_editor&amp;diff=5305"/>
		<updated>2026-06-03T14:41:39Z</updated>

		<summary type="html">&lt;p&gt;Florian-bohlken-c7a9@uni-muenster.de: search commands had an error. fixed some typos while at it.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Tutorials|vim - vi Improved (Text Editor)]]&amp;lt;nowiki /&amp;gt;&lt;br /&gt;
{{DISPLAYTITLE:vim - vi Improved (Text Editor)}}&amp;lt;nowiki /&amp;gt;&lt;br /&gt;
{{Syllabus Introduction to Linux}}&amp;lt;nowiki /&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This part of the Linux tutorials introduces the vim text editor and describes its main features and use cases. A short explanation of the most important commands paired with examples on how to use them allow the user to delve right in. The tutorial demonstrates the basics, like opening/writing files or moving within the text as well as the most often employed tasks like search&amp;amp;replace or copy&amp;amp;paste which makes it interesting to both complete beginners and more intermediate users. The vim text editor&amp;#039;s main advantage is that it&amp;#039;s present in most unix operational systems, futhermore it&amp;#039;s highly configurable and provides an extensive plugin system.&lt;br /&gt;
&lt;br /&gt;
=== Video === &amp;lt;!--T:5--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;youtube width=&amp;quot;600&amp;quot; height=&amp;quot;340&amp;quot; right&amp;gt;QPWdUkgGd3I&amp;lt;/youtube&amp;gt;&lt;br /&gt;
&lt;br /&gt;
([[Media:HPC.NRW_Introduction_to_Linux_in_HPC_08_The_vim_Text_Editor.pdf | Slides as pdf]])&lt;br /&gt;
&lt;br /&gt;
=== Quiz === &amp;lt;!--T:5--&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
{{hidden begin &lt;br /&gt;
|title = How many windows does vim use?&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;quiz display=simple&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
|type=&amp;quot;()&amp;quot;}&lt;br /&gt;
-  it runs in the console and opens additional windows&lt;br /&gt;
||  &lt;br /&gt;
-  it can start in the console but it requires the X window system and opens additional windows&lt;br /&gt;
|| &lt;br /&gt;
+  it runs completely inside the console&lt;br /&gt;
|| Explanation: &amp;lt;code&amp;gt;vim&amp;lt;/code&amp;gt; doesn&amp;#039;t require the X window system or any additional windows, it runs completely inside the console.&lt;br /&gt;
&amp;lt;/quiz&amp;gt;&lt;br /&gt;
{{hidden end}}&lt;br /&gt;
&lt;br /&gt;
{{hidden begin &lt;br /&gt;
|title = How many modes does vim have?&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;quiz display=simple&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
|type=&amp;quot;()&amp;quot;}&lt;br /&gt;
-  it has only one mode &lt;br /&gt;
||  &lt;br /&gt;
-  it has two modes&lt;br /&gt;
|| &lt;br /&gt;
+  it has at least three modes&lt;br /&gt;
|| Explanation: &amp;lt;code&amp;gt;vi&amp;lt;/code&amp;gt; has the modes normal, insert and command. In addition, &amp;lt;code&amp;gt;vim&amp;lt;/code&amp;gt; hast the modes visual, select und ex-mode, not covered in this tutorial.&lt;br /&gt;
&amp;lt;/quiz&amp;gt;&lt;br /&gt;
{{hidden end}}&lt;br /&gt;
&lt;br /&gt;
{{hidden begin &lt;br /&gt;
|title = How to enter the insert mode of &amp;lt;code&amp;gt;vim&amp;lt;/code&amp;gt;?&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;quiz display=simple&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
|type=&amp;quot;()&amp;quot;}&lt;br /&gt;
- press &amp;lt;code&amp;gt;enter&amp;lt;/code&amp;gt; key&lt;br /&gt;
|| &lt;br /&gt;
+ press &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt; key&lt;br /&gt;
|| Explanation: If you are not in the insert mode, the &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt; key means insert and by pressing it you can enter the insert mode. On the other hand, the &amp;lt;code&amp;gt;Esc&amp;lt;/code&amp;gt; key brings you out of the insert mode. The behavior of the enter key depends on in which mode of vim you are. If you are in the normal mode, you navigate to the next line. If you are in the insert mode already, you start a new line.&lt;br /&gt;
- press &amp;lt;code&amp;gt;Esc&amp;lt;/code&amp;gt; key&lt;br /&gt;
|| &lt;br /&gt;
&amp;lt;/quiz&amp;gt;&lt;br /&gt;
{{hidden end}}&lt;br /&gt;
&lt;br /&gt;
{{hidden begin &lt;br /&gt;
|title = How to save a file and exit during normal mode?&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;quiz display=simple&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
|type=&amp;quot;()&amp;quot;}&lt;br /&gt;
- press &amp;lt;code&amp;gt;:q!&amp;lt;/code&amp;gt; keys and &amp;lt;code&amp;gt;enter&amp;lt;/code&amp;gt;&lt;br /&gt;
|| &lt;br /&gt;
+ press &amp;lt;code&amp;gt;:wq&amp;lt;/code&amp;gt; keys and &amp;lt;code&amp;gt;enter&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;:X&amp;lt;/code&amp;gt; keys and &amp;lt;code&amp;gt;enter&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;ZZ&amp;lt;/code&amp;gt; keys&lt;br /&gt;
|| Explanation: Any of the pressed key combinations will trigger a save and exit when in normal mode. The sequence &amp;lt;code&amp;gt;:q!&amp;lt;/code&amp;gt; would exit without writing the file.&lt;br /&gt;
- press &amp;lt;code&amp;gt;Ctrl-x Ctrl-s&amp;lt;/code&amp;gt; keys&lt;br /&gt;
|| &lt;br /&gt;
&amp;lt;/quiz&amp;gt;&lt;br /&gt;
{{hidden end}}&lt;br /&gt;
&lt;br /&gt;
{{hidden begin &lt;br /&gt;
|title = How to copy and paste &amp;lt;code&amp;gt;5&amp;lt;/code&amp;gt; entire lines in normal mode?&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;quiz display=simple&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
|type=&amp;quot;()&amp;quot;}&lt;br /&gt;
+ press &amp;lt;code&amp;gt;5yy&amp;lt;/code&amp;gt; keys, move the cursor and press &amp;lt;code&amp;gt;p&amp;lt;/code&amp;gt;&lt;br /&gt;
|| Explanation: commands can be repeated by placing an integer value before them. In this case 5 lines are copied by pressing &amp;lt;code&amp;gt;5yy&amp;lt;/code&amp;gt;. The paste command is executed by pressing &amp;lt;code&amp;gt;p&amp;lt;/code&amp;gt;, pressing &amp;lt;code&amp;gt;5p&amp;lt;/code&amp;gt; would have pasted 25 lines. &lt;br /&gt;
- press &amp;lt;code&amp;gt;5yy&amp;lt;/code&amp;gt; keys, move the cursor and press &amp;lt;code&amp;gt;5p&amp;lt;/code&amp;gt;&lt;br /&gt;
|| &lt;br /&gt;
- press &amp;lt;code&amp;gt;Ctrl-c Ctrl-v&amp;lt;/code&amp;gt; keys&lt;br /&gt;
|| &lt;br /&gt;
&amp;lt;/quiz&amp;gt;&lt;br /&gt;
{{hidden end}}&lt;br /&gt;
&lt;br /&gt;
{{hidden begin &lt;br /&gt;
|title = How to perform a forward search for the pattern &amp;lt;code&amp;gt;foo&amp;lt;/code&amp;gt;, afterwards a backward search for the pattern &amp;lt;code&amp;gt;bar&amp;lt;/code&amp;gt; in normal mode?&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;quiz display=simple&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
|type=&amp;quot;()&amp;quot;}&lt;br /&gt;
- press &amp;lt;code&amp;gt;/foo&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;enter&amp;lt;/code&amp;gt;, afterwards &amp;lt;code&amp;gt;//bar&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;enter&amp;lt;/code&amp;gt;&lt;br /&gt;
|| &lt;br /&gt;
+ press &amp;lt;code&amp;gt;/foo&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;enter&amp;lt;/code&amp;gt;, afterwards &amp;lt;code&amp;gt;?bar&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;enter&amp;lt;/code&amp;gt;&lt;br /&gt;
|| Explanation: the described commands will perform a search for a regex pattern, either forward (&amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt;) or backward (&amp;lt;code&amp;gt;?&amp;lt;/code&amp;gt;), depending on the prefix&lt;br /&gt;
- press &amp;lt;code&amp;gt;:f/foo/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;enter&amp;lt;/code&amp;gt;, afterwards &amp;lt;code&amp;gt;:r/bar/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;enter&amp;lt;/code&amp;gt;&lt;br /&gt;
|| &lt;br /&gt;
&amp;lt;/quiz&amp;gt;&lt;br /&gt;
{{hidden end}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{hidden begin &lt;br /&gt;
|title = How to search and replace all occurrences of the pattern &amp;lt;code&amp;gt;foo&amp;lt;/code&amp;gt; with &amp;lt;code&amp;gt;bar&amp;lt;/code&amp;gt; in normal mode?&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;quiz display=simple&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
|type=&amp;quot;()&amp;quot;}&lt;br /&gt;
+ press &amp;lt;code&amp;gt;:%s/foo/bar/g&amp;lt;/code&amp;gt; keys and &amp;lt;code&amp;gt;enter&amp;lt;/code&amp;gt;&lt;br /&gt;
|| Explanation: the command &amp;lt;code&amp;gt;:%s/foo/bar/g&amp;lt;/code&amp;gt; will search and replace the pattern in the entire file. Without the &amp;lt;code&amp;gt;g&amp;lt;/code&amp;gt; modifier, it would search the entire file as well but only the first occurrence in each line would be replaced. The &amp;lt;code&amp;gt;c&amp;lt;/code&amp;gt; modifier asks for a confirmation each time.&lt;br /&gt;
- press &amp;lt;code&amp;gt;:%s/foo/bar/&amp;lt;/code&amp;gt; keys and &amp;lt;code&amp;gt;enter&amp;lt;/code&amp;gt;&lt;br /&gt;
|| &lt;br /&gt;
- press &amp;lt;code&amp;gt;:%sed/foo/bar/&amp;lt;/code&amp;gt; keys and &amp;lt;code&amp;gt;enter&amp;lt;/code&amp;gt;&lt;br /&gt;
|| &lt;br /&gt;
&amp;lt;/quiz&amp;gt;&lt;br /&gt;
{{hidden end}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{hidden begin &lt;br /&gt;
|title = How would you open a file in read-only mode using the &amp;lt;code&amp;gt;vim&amp;lt;/code&amp;gt; editor? &amp;lt;/br&amp;gt;&lt;br /&gt;
Hint: In terminal &amp;lt;code&amp;gt;man vim&amp;lt;/code&amp;gt; &lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;quiz display=simple&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
|type=&amp;quot;()&amp;quot;}&lt;br /&gt;
- &amp;lt;code&amp;gt;$ vim -r filename&amp;lt;/code&amp;gt;&lt;br /&gt;
||&lt;br /&gt;
+ &amp;lt;code&amp;gt;$ vim -R filename&amp;lt;/code&amp;gt;&lt;br /&gt;
|| Explanation: the &amp;lt;code&amp;gt;-R&amp;lt;/code&amp;gt; option opens the file read-only. This can be overridden by pressing &amp;lt;code&amp;gt;:w!&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;:set noro&amp;lt;/code&amp;gt;&lt;br /&gt;
- &amp;lt;code&amp;gt;$ vim -n filename&amp;lt;/code&amp;gt;&lt;br /&gt;
|| &lt;br /&gt;
&amp;lt;/quiz&amp;gt;&lt;br /&gt;
{{hidden end}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Warning|mode=info|text= &amp;#039;&amp;#039;&amp;#039;If you forget in which mode you are in while using vim, just keep pressing Esc.&amp;#039;&amp;#039;&amp;#039;}}&lt;br /&gt;
&lt;br /&gt;
=== Exercises in Terminal === &amp;lt;!--T:5--&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
 1. Create a vim file and write some text in it with insert (pressing &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt;) and than undo and redo the changes. &lt;br /&gt;
 2. Copy (yank) multiple lines and paste them&lt;br /&gt;
 3. Search for a certain pattern and replace it with another&lt;br /&gt;
   {| role=&amp;quot;presentation&amp;quot; class=&amp;quot;wikitable mw-collapsible mw-collapsed&amp;quot;&lt;br /&gt;
    | &amp;lt;strong&amp;gt;Answer:&amp;lt;/strong&amp;gt;&lt;br /&gt;
    |-&lt;br /&gt;
    | &lt;br /&gt;
      &amp;lt;code&amp;gt;$ vim test.txt&amp;lt;/code&amp;gt; &lt;br /&gt;
      In &amp;lt;code&amp;gt;vim&amp;lt;/code&amp;gt; editor press &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt; to insert text and write few lines.&lt;br /&gt;
      Press &amp;lt;code&amp;gt;Esc&amp;lt;/code&amp;gt; than press &amp;lt;code&amp;gt;u&amp;lt;/code&amp;gt; (for undo) after that press &amp;lt;code&amp;gt;ctrl + r&amp;lt;/code&amp;gt; on keyboard for redo.&lt;br /&gt;
         - &amp;lt;code&amp;gt;u&amp;lt;/code&amp;gt;: undo last change (can be repeated to undo preceding commands).&lt;br /&gt;
         - &amp;lt;code&amp;gt;Ctrl-r&amp;lt;/code&amp;gt;: Redo changes which were undone (undo the undos).&lt;br /&gt;
      In order to copy a line press &amp;lt;code&amp;gt;yy&amp;lt;/code&amp;gt;, for several lines preclude with the command with a number, e.g. &amp;lt;code&amp;gt;5yy&amp;lt;/code&amp;gt;.&lt;br /&gt;
      For pasting simply press &amp;lt;code&amp;gt;p&amp;lt;/code&amp;gt;. &lt;br /&gt;
      Search &amp;amp; Replace can be executed with the command &amp;lt;code&amp;gt;:s%/foo/bar/g&amp;lt;/code&amp;gt;, it will search and replace the pattern &amp;lt;code&amp;gt;foo&amp;lt;/code&amp;gt; &lt;br /&gt;
      and replace it with &amp;lt;code&amp;gt;bar&amp;lt;/code&amp;gt; in the entire file. Without the &amp;lt;code&amp;gt;g&amp;lt;/code&amp;gt; modifier, it would search the entire file as well but only&lt;br /&gt;
      the first occurence in each line would be replaced. The &amp;lt;code&amp;gt;c&amp;lt;/code&amp;gt; modifier asks for a confirmation each time.&lt;br /&gt;
    |}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Tutorial Navigation&lt;br /&gt;
| previous = [[Introduction_to_Linux_in_HPC/Processes | Processes ]]&lt;br /&gt;
| main = [[Introduction_to_Linux_in_HPC | Overview ]]&lt;br /&gt;
| next = [[Introduction_to_Linux_in_HPC/Shell_scripting | Shell Scripting ]]&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>Florian-bohlken-c7a9@uni-muenster.de</name></author>
	</entry>
</feed>