{"id":24,"date":"2016-10-17T02:14:00","date_gmt":"2016-10-17T02:14:00","guid":{"rendered":""},"modified":"2021-02-22T01:13:03","modified_gmt":"2021-02-22T01:13:03","slug":"playing-with-linux-vim","status":"publish","type":"post","link":"https:\/\/www.tech-and-dev.com\/blog\/2016\/10\/playing-with-linux-vim.html","title":{"rendered":"Playing With Linux Vim"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left;\">\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"https:\/\/www.tech-and-dev.com\/blog\/2016\/10\/17\/playing-with-linux-vim\/\"><img decoding=\"async\" title=\"Vim\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/vim.png\" alt=\"Playing with Linux VIm\" border=\"0\" \/><\/a><\/div>\n<div style=\"text-align: justify;\"><b>Vim<\/b> (Vi Improved) in a Unix\/Linux text editor. It&#8217;s an improved version of Vi and is used in most modern Linux distributions from the command line or as an independent graphical user interface application.<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">Vim has two modes, command mode and insert mode. Command mode is where you issue commands such as write, quit, search. And insert mode is where you edit the text file and delete or add characters.<br \/>\n<a name=\"more\"><\/a><\/div>\n<h2 style=\"text-align: left;\">Opening a file with vim from the command line:<\/h2>\n<p><b><span style=\"color: red;\">vim text.txt\u00a0<\/span><\/b><\/p>\n<p>And the file will open in &#8220;Command Mode&#8221;<\/p>\n<h2 style=\"text-align: left;\">Inserting Text:<\/h2>\n<p>To edit the text there are several command, press either:<br \/>\n<b><span style=\"color: red;\">i<\/span><\/b> or INSERT button to insert new text where the cursor is positioned<br \/>\n<span style=\"color: red;\"><b>a<\/b><\/span> to append text after where the cursor is positioned<br \/>\n<span style=\"color: red;\"><b>o<\/b><\/span> to start a new line and add text<\/p>\n<h2 style=\"text-align: left;\">To Save the File:<\/h2>\n<p><span style=\"color: red;\"><b>:w<\/b><\/span> to write\/save the text to the file<br \/>\n<span style=\"color: red;\"><b>:wq<\/b><\/span> to save the text and exit vim<br \/>\n<span style=\"color: red;\"><b>:wq!<\/b><\/span> to save the text and exit vim without answering any question from vim<\/p>\n<h2 style=\"text-align: left;\">To Undo and Redo:<\/h2>\n<p><span style=\"color: red;\"><b>U<\/b><\/span> to Undo<br \/>\n<span style=\"color: red;\"><b>Control + R<\/b><\/span> to Redo<\/p>\n<h2 style=\"text-align: left;\">To go to End of file and Start of file:<\/h2>\n<p><span style=\"color: red;\"><b>gg<\/b><\/span> to go to the beginning of the file<br \/>\n<span style=\"color: red;\"><b>Shift\u00a0+ g<\/b><\/span>\u00a0 to go to the end of the file<\/p>\n<h2 style=\"text-align: left;\">To go to End of line and Start of line:<\/h2>\n<p><span style=\"color: red;\"><b>$<\/b><\/span> to go to end of line<br \/>\n<span style=\"color: red;\"><b>^<\/b><\/span> to go to start of line<\/p>\n<p>&nbsp;<\/p>\n<h2 style=\"text-align: left;\">To Select an entire Line:<\/h2>\n<p><span style=\"color: red;\"><b>v<\/b><\/span> to enter visual mode by clicking<br \/>\n<span style=\"color: red;\"><b>Shift + v<\/b><\/span> to select an entire line, you can go up and down with the cursors as well to select more lines<br \/>\n<span style=\"color: red;\"><b>gg<\/b><\/span> to select all the text from the cursor to the start of the file<br \/>\n<span style=\"color: red;\"><b>Shift\u00a0+ g<\/b><\/span> to select all the text from the cursor to the end of the file<\/p>\n<p><span style=\"color: red;\"><b>d <\/b><\/span>to delete the selection<br \/>\n<span style=\"color: red;\"><b>y<\/b><\/span> to copy the selection (y = yank)<br \/>\n<span style=\"color: red;\"><b>p<\/b><\/span> to paste the selection<\/p>\n<h2 style=\"text-align: left;\">Search for a word:<\/h2>\n<p><span style=\"color: red;\"><b>\/keyword<\/b><\/span> \/ is to search downward and &#8220;keyword&#8221; is the word you&#8217;re searching for<br \/>\n<span style=\"color: red;\"><b>?keyword<\/b><\/span> ? is to search upward and &#8220;keyword&#8221; is the word you&#8217;re searching for<br \/>\n<span style=\"color: red;\"><b>n<\/b><\/span> to go to the next word<\/p>\n<h2 style=\"text-align: left;\">Replace a word or character:<\/h2>\n<p><span style=\"color: red;\"><b>:s%\/oldText\/NewText<\/b><\/span> will replace the next word or character<br \/>\n<span style=\"color: red;\"><b>:s%\/oldText\/NewText\/g<\/b><\/span> will globally replace all the words or characters<\/p>\n<p><b>Want to know more? Leave a comment below!<\/b><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Vim (Vi Improved) in a Unix\/Linux text editor. It&#8217;s an improved version of Vi and is used in most modern Linux distributions from the command line or as an independent graphical user interface application. Vim has two modes, command mode and insert mode. Command mode is where you issue commands such as write, quit, [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[11,6,34],"tags":[],"class_list":["post-24","post","type-post","status-publish","format-standard","hentry","category-commands","category-linux","category-vim"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/24","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/comments?post=24"}],"version-history":[{"count":2,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/24\/revisions"}],"predecessor-version":[{"id":364,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/24\/revisions\/364"}],"wp:attachment":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/media?parent=24"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/categories?post=24"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/tags?post=24"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}