{"id":77,"date":"2022-04-04T11:56:00","date_gmt":"2022-04-04T09:56:00","guid":{"rendered":"https:\/\/blubb.fish\/?p=77"},"modified":"2022-03-25T12:10:09","modified_gmt":"2022-03-25T11:10:09","slug":"vi-vim-usage-and-commands","status":"publish","type":"post","link":"https:\/\/blubb.fish\/index.php\/2022\/04\/04\/vi-vim-usage-and-commands\/","title":{"rendered":"vi\/vim usage and commands"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">vim is a texteditor for linux. Hard to learn but amazing to use<\/p>\n\n\n\n<p class=\"has-large-font-size wp-block-paragraph\">Commands on CLI<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">open a document<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim \/folder\/file<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Start vim with commands<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim +&lt;command&gt; \/folder\/file<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">open at specific line<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># will open file on line 5\nvim +5 \/folder\/file<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">start vim with the first occurence of a word (search in file)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim +:\/&lt;searchterm&gt; \/folder\/file<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">replace first occurence in file<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim +:s\/&lt;searchterm&gt;\/&lt;replaceterm&gt;\/ \/folder\/file<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">replace all occurences in a file<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim +:s\/&lt;searchterm&gt;\/&lt;replaceterm&gt;\/g \/folder\/file<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"has-large-font-size wp-block-paragraph\">Commands \/ usage inside veeam<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">when vim is started it is not in deiting mode. to get into editing mode press &#8220;i&#8221;. now you can type. to go back to command mode press &#8220;ESC&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">to enter a command press &#8220;:&#8221; in command mode. This will show &#8220;:&#8221; in the lower left corner. also a possible way to start this is &#8220;\/&#8221;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"137\" height=\"101\" src=\"https:\/\/blubb.fish\/wp-content\/uploads\/2022\/03\/vim.png\" alt=\"\" class=\"wp-image-81\"\/><figcaption>vim command prompt<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Here you can type different commands. commands can be combined<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">:w -&gt; saves file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">:q -&gt; quit file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">:wq -&gt; save and quit<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">:q! -&gt; force quit (ex. if changes been made and you want to discard it)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">:s\/search\/replace\/ -&gt; search and replace term in file. will only replace first occurence<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">:s\/search\/replace\/g -&gt; g for global. will replace all occurences in file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">:&lt;linenumber&gt; -&gt; ex. :13 will jump to the 13th line in file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\/term -&gt; will search for &#8220;term&#8221; in the document and stop at the first occurence. to jump to the next found term press &#8220;n&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">:set number -&gt; this will show the line number at the beginning of the line<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">:set nonumber -&gt; will disable the line numbers<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then vim has also commands which need no &#8220;:&#8221; or &#8220;\/&#8221; to enter commands. just input them while file is open to do something<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">gg -&gt; go to first line in file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">GG -&gt; fo to last line in file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">p -&gt; past line below cursor<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">P -&gt; past line above cursor<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">dd -&gt; removes line and takes it into clipboard<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">yy -&gt; copy line to clipboard<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">u -&gt; undo change<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">d2d -&gt; remove the 2 lines below<\/p>\n","protected":false},"excerpt":{"rendered":"<p>vim is a texteditor for linux. Hard to learn but amazing to use Commands on CLI open a document Start vim with commands open at specific line start vim with the first occurence of a word (search in file) replace first occurence in file replace all occurences in a file Commands \/ usage inside veeam [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-77","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/blubb.fish\/index.php\/wp-json\/wp\/v2\/posts\/77","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blubb.fish\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blubb.fish\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blubb.fish\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blubb.fish\/index.php\/wp-json\/wp\/v2\/comments?post=77"}],"version-history":[{"count":5,"href":"https:\/\/blubb.fish\/index.php\/wp-json\/wp\/v2\/posts\/77\/revisions"}],"predecessor-version":[{"id":84,"href":"https:\/\/blubb.fish\/index.php\/wp-json\/wp\/v2\/posts\/77\/revisions\/84"}],"wp:attachment":[{"href":"https:\/\/blubb.fish\/index.php\/wp-json\/wp\/v2\/media?parent=77"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blubb.fish\/index.php\/wp-json\/wp\/v2\/categories?post=77"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blubb.fish\/index.php\/wp-json\/wp\/v2\/tags?post=77"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}