{"id":203,"date":"2020-08-18T19:23:47","date_gmt":"2020-08-18T20:23:47","guid":{"rendered":"http:\/\/www.linux-tutorial.info\/?page_id=77"},"modified":"2020-08-22T19:25:59","modified_gmt":"2020-08-22T20:25:59","slug":"this-is-the-page-title-toplevel-37","status":"publish","type":"page","link":"http:\/\/www.linux-tutorial.info\/?page_id=203","title":{"rendered":"Changing Text in vi"},"content":{"rendered":"\n<title>Changing Text in vi<\/title>\n<question id=\"\" type=\"\" text=\"In vi, what key combination would delete 8 lines.\" \/>\n<question id=\"\" type=\"\" text=\"In vi, what key would open a new line after your current line?\" \/>\n<question id=\"\" type=\"\" text=\"In vi, what key would delete the character the cursor is on?\" \/>\n<p>\nIn addition to &#8220;standard&#8221; editing, there are a several special editing commands.\nPressing dd will delete the entire line you are on, <keyinput>5dd<\/keyinput> would then\ndelete five complete lines. To open up a line for editing, we press <keyinput>o<\/keyinput> to open the line after the line you are currently on and <keyinput>O<\/keyinput> for the line before. Use <keyinput>x<\/keyinput> to delete the character (including numbers) that the <glossary>cursor<\/glossary> is on.\n<\/p>\n<question id=\"493\" text=\"In vi, what key combination 'trick' would you use to 'exchange' to characters?\" \/>\n<p>\nWhen we want to move something we just deleted, we put the <glossary>cursor<\/glossary>\non the spot where we want it. Then press either <keyinput>p<\/keyinput> to <u>p<\/u>ut that text\nafter the current cursor position or <keyinput>P<\/keyinput> to <u>p<\/u>ut it before the current position. A nice trick that I\nalways use to swap characters is <keyinput>xp<\/keyinput>. The <keyinput>x<\/keyinput> deletes the character you are on and the <keyinput>p<\/keyinput> immediately\ninserts\/puts it. The result is that you swap characters. So, if I had typed the word &#8220;into&#8221; as &#8220;inot,&#8221;\nI would place the cursor on the &#8220;o&#8221; and type <keyinput>xp<\/keyinput>, which would swap the &#8220;o&#8221; and the &#8220;t.&#8221;\n<\/p>\n<concept id=\"\" description=\"You can repeat the last action in 'vi' by simply pressing the dot\/period.\" \/>\n<question id=\"\" type=\"mc\" text=\"What key repeats the last action in 'vi'?\" \/>\n<p>\nTo repeat the edit we just did, be it deleting 18 lines or inputting &#8220;I love you,&#8221; we could do so by pressing &#8220;.&#8221; (dot) from command mode. In fact, any edit command can be repeated with the dot.\n<\/p>\n<question id=\"494\" text=\"In vi, what key combination would you use to change the next 4 words?\" \/>\n<p>\nTo make a change, press <keyinput>c<\/keyinput> followed by a movement command or number and movement command. For example, to change everything from where you are to the next word, press <keyinput>cw<\/keyinput>. To\nchange everything from where you are to the end of the line, press <keyinput>C<\/keyinput> (capital &#8216;c&#8217;) or or <keyinput>c$<\/keyinput>. If you do that, then a dollar sign will appear, indicating how much you intend to change. By combining this with a number you can repeat the the command multiple times, for eaxmple <keyinput>c4w<\/keyinput> or <keyinput>4cw<\/keyinput> will change the next 4 words.\n<\/p>\n<concept id=\"\" description=\"To switch from command-mode to input mode in 'vi' you press the ESC key.\" \/>\n<question id=\"\" type=\"mc\" text=\"To switch from command-mode to input mode in 'vi' what key would you press?\" \/>\n<p>\nIf we go back into command mode (press <keyinput>Esc<\/keyinput>) before we reach the dollar sign, then everything from the current\nposition to the dollar sign is removed. When you think about this, it is actually logical. By pressing <keyinput>c<\/keyinput>, you tell <command>vi<\/command> that\nyou want to change everything to the end of the line. When you press Enter, you are basically saying that you are done inputting text. However, the changes should continue to the end of the line, thereby deleting the rest of the line.\n<\/p>\n<concept id=\"\" description=\"In 'vi' you use the 'u' to undo the last edit.\" \/>\n<concept id=\"\" description=\"In 'vi' you can repeatedly press the 'u' key to undo multiple changes.\" \/>\n<question id=\"\" type=\"\" text=\"What key would you press in 'vi' to undo the last edit?\" \/>\n<p>\nTo undo the last edit, what would we press? Well, whats the first letter of the word &#8220;undo&#8221;? Keep in mind that pressing u will only undo the last change. For example, let&#8217;s assume we enter the following:\n<\/p>\n<p>\no&#9;to open a new line and go into input mode\n<\/p>\n<p>\nI love\n<\/p>\n<p>\nEsc&#9;to go back to command mode\n<\/p>\n<p>\na&#9;to append from current location\n<\/p>\n<p>\nyou\n<\/p>\n <p>\nEsc&#9;to return to command mode\n<\/p>\n<concept id=\"\" description=\"You use the u key in 'vi' to undo the last change.\" \/>\n<concept id=\"\" description=\"The u key in 'vi' can be used repeated to undo multiple changes.\" \/>\n<question id=\"\" type=\"\" text=\"What character would you use in 'vi' to undo the last change?\" \/>\n<p>\nThe result of what we typed was to open a new line with the text\n&#8220;I love you.&#8221; We see it as one change, but from the perspective of vi, two changes were made. First we entered\n&#8220;I love,&#8221; then we entered &#8220;you.&#8221; If we were to press u, only &#8220;you&#8221; would be removed. However, if <keyinput>u<\/keyinput> undoes that last change,\nwhat command do you think returns the line to its original state? What else: <keyinput>U<\/keyinput>. As you are making changes, vi keeps track\nof the original state of a line. When you press <keyinput>U<\/keyinput>, the line is returned to that original state.\n<p>\n<i>NOTE:<\/i> It is probable that the version of <command>vi<\/command> you are using will allow you to press <keyinput>u<\/keyinput> repeatedly to undo any number of previous changes.\n<\/p>\n<\/p>\n<concept id=\"\" description=\"You use the r key in 'vi' to replace characters.\" \/>\n<concept id=\"\" description=\"You use the uppercase R key in 'vi' to replace characters to the end of the current line.\" \/>\n<question id=\"\" type=\"mc\" text=\"What key would you use in 'vi' to replace characters to the end of the current line?\" \/>\n<question id=\"\" type=\"mc\" text=\"What key would you use in 'vi' to replace characters?\" \/>\n<p>\nIf you want to replace all of the text on the current line, you could simply delete the line and insert a\nnew one. However, you could also <b>replace<\/b> the existing line by using the <keyinput>R<\/keyinput> (for replace) command. This\nputs <command>vi<\/command> into replace mode and each character you type replaces the existing characters as you write.\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Changing Text in vi In addition to &#8220;standard&#8221; editing, there are a several special editing commands. Pressing dd will delete the entire line you are on, 5dd would then delete five complete lines. To open up a line for editing, &hellip; <a href=\"http:\/\/www.linux-tutorial.info\/?page_id=203\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-203","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/203","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=203"}],"version-history":[{"count":1,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/203\/revisions"}],"predecessor-version":[{"id":518,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/203\/revisions\/518"}],"wp:attachment":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}