{"id":1099,"date":"2015-06-21T20:04:05","date_gmt":"2015-06-21T18:04:05","guid":{"rendered":"http:\/\/www.robinglauser.ch\/blog\/?p=1099"},"modified":"2015-06-21T14:35:37","modified_gmt":"2015-06-21T12:35:37","slug":"some-vim-tips-and-tricks","status":"publish","type":"post","link":"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/","title":{"rendered":"Some VIM tips and tricks."},"content":{"rendered":"<p><strong>&lt;esc&gt; :wq!\u00a0<\/strong>Save the file and quit vim<\/p>\n<p><b><strong>&lt;esc&gt; <\/strong>ZZ\u00a0<\/b>Other way to save the file and quit vim<\/p>\n<p><strong>&lt;esc&gt; :earlier 15m<\/strong> Go back 15 minutes in the history of the file<\/p>\n<p><strong>&lt;esc&gt; :later\u00a015m<\/strong>\u00a0Reverses the :earlier command<\/p>\n<p><strong>&lt;esc&gt; :! ls<\/strong>\u00a0Run command ls from inside vim<\/p>\n<p><strong>&lt;esc&gt; :.! ls<\/strong>\u00a0Run command ls from inside vim and write output into open file.<\/p>\n<p><strong><strong>&lt;esc&gt; <\/strong>:w !sudo tee % &gt; \/dev\/null<\/strong>\u00a0With this handy shortcut you can save a file as root even if you opened vim as a non-root user. This works because vim redirects the file content to standard input of the command you specified after :w!<\/p>\n<p>In this case this is sudo tee % &gt; \/dev\/null. The sudo command runs the specified command as root and redirects the standard input to the command.<\/p>\n<p>Vim replaces the % character with the file path of the open file. \u00a0The command tee reads from the standard input and saves everything to the file which is provided as the first argument. Because we run tee as root it can overwrite the file with root rights and save it.<\/p>\n<p>It also prints everything again to the standard output. This is why we use &gt; \/dev\/null at the end to suppress tee from printing everything to the terminal.<\/p>\n<p>Vim will warn you that the file has changed because of the external overwrite from tee. It will the provide you with the option to re[l]oad or ignore the change.<\/p>\n<p><strong>dd\u00a0<\/strong>Cut line into the the buffer.<\/p>\n<p><strong>p\u00a0<\/strong>Paste from the buffer<\/p>\n<p><strong>_dd\u00a0<\/strong>Removes line without putting it into the buffer<\/p>\n<p><strong>10j\u00a0<\/strong>Go ten lines down<\/p>\n<p><strong>10k\u00a0<\/strong>Go ten lines\u00a0up<\/p>\n<p><strong>10h\u00a0<\/strong>Go ten lines\u00a0left<\/p>\n<p><strong>10l\u00a0<\/strong>Go ten lines\u00a0right<\/p>\n<p>Sources:<br \/>\n<a href=\"https:\/\/stackoverflow.com\/questions\/726894\/what-are-the-dark-corners-of-vim-your-mom-never-told-you-about\" target=\"_blank\">https:\/\/stackoverflow.com\/questions\/726894\/what-are-the-dark-corners-of-vim-your-mom-never-told-you-about<\/a><\/p>\n<p><a href=\"https:\/\/www.reddit.com\/r\/linux\/comments\/383r6l\/_\/\" target=\"_blank\">https:\/\/www.reddit.com\/r\/linux\/comments\/383r6l\/_\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\">&lt;esc&gt; :wq!\u00a0Save the file and quit vim &lt;esc&gt; ZZ\u00a0Other way to save the file and quit vim &lt;esc&gt; :earlier 15m Go back 15 minutes in the history of the file &lt;esc&gt; :later\u00a015m\u00a0Reverses the :earlier command &lt;esc&gt; :! ls\u00a0Run command ls from inside vim &lt;esc&gt; :.! ls\u00a0Run command ls from inside vim and write output into open file. &lt;esc&gt; :w !sudo &#8230; <a class=\"read-more\" href=\"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/\">Read More<\/a><\/p>\n","protected":false},"author":2,"featured_media":1115,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[45],"tags":[120,119,118],"class_list":["post-1099","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development","tag-save","tag-tips","tag-vim"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Some VIM tips and tricks. - Robin Glauser<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Some VIM tips and tricks. - Robin Glauser\" \/>\n<meta property=\"og:description\" content=\"&lt;esc&gt; :wq!\u00a0Save the file and quit vim &lt;esc&gt; ZZ\u00a0Other way to save the file and quit vim &lt;esc&gt; :earlier 15m Go back 15 minutes in the history of the file &lt;esc&gt; :later\u00a015m\u00a0Reverses the :earlier command &lt;esc&gt; :! ls\u00a0Run command ls from inside vim &lt;esc&gt; :.! ls\u00a0Run command ls from inside vim and write output into open file. &lt;esc&gt; :w !sudo ... Read More\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/\" \/>\n<meta property=\"og:site_name\" content=\"Robin Glauser\" \/>\n<meta property=\"article:published_time\" content=\"2015-06-21T18:04:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/06\/vim1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"700\" \/>\n\t<meta property=\"og:image:height\" content=\"300\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Robin Glauser\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@robinglauser\" \/>\n<meta name=\"twitter:site\" content=\"@robinglauser\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Robin Glauser\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/\"},\"author\":{\"name\":\"Robin Glauser\",\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/#\/schema\/person\/e1a94504a6ff5171fa13670932514b19\"},\"headline\":\"Some VIM tips and tricks.\",\"datePublished\":\"2015-06-21T18:04:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/\"},\"wordCount\":318,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/#\/schema\/person\/e1a94504a6ff5171fa13670932514b19\"},\"image\":{\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/06\/vim1.jpg\",\"keywords\":[\"save\",\"tips\",\"vim\"],\"articleSection\":[\"Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/\",\"url\":\"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/\",\"name\":\"Some VIM tips and tricks. - Robin Glauser\",\"isPartOf\":{\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/06\/vim1.jpg\",\"datePublished\":\"2015-06-21T18:04:05+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/#primaryimage\",\"url\":\"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/06\/vim1.jpg\",\"contentUrl\":\"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/06\/vim1.jpg\",\"width\":700,\"height\":300},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.robinglauser.ch\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Some VIM tips and tricks.\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/#website\",\"url\":\"https:\/\/www.robinglauser.ch\/blog\/\",\"name\":\"Robin Glauser\",\"description\":\"My Blog about Development, Design and my random thoughts.\",\"publisher\":{\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/#\/schema\/person\/e1a94504a6ff5171fa13670932514b19\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.robinglauser.ch\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/#\/schema\/person\/e1a94504a6ff5171fa13670932514b19\",\"name\":\"Robin Glauser\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/10\/DSC_1244_small.jpg\",\"url\":\"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/10\/DSC_1244_small.jpg\",\"contentUrl\":\"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/10\/DSC_1244_small.jpg\",\"width\":800,\"height\":530,\"caption\":\"Robin Glauser\"},\"logo\":{\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/10\/DSC_1244_small.jpg\"},\"description\":\"I'm a web developer.\",\"sameAs\":[\"https:\/\/www.robinglauser.ch\",\"https:\/\/www.instagram.com\/robinglauser\/\",\"https:\/\/x.com\/robinglauser\"],\"url\":\"https:\/\/www.robinglauser.ch\/blog\/author\/robin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Some VIM tips and tricks. - Robin Glauser","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/","og_locale":"en_US","og_type":"article","og_title":"Some VIM tips and tricks. - Robin Glauser","og_description":"&lt;esc&gt; :wq!\u00a0Save the file and quit vim &lt;esc&gt; ZZ\u00a0Other way to save the file and quit vim &lt;esc&gt; :earlier 15m Go back 15 minutes in the history of the file &lt;esc&gt; :later\u00a015m\u00a0Reverses the :earlier command &lt;esc&gt; :! ls\u00a0Run command ls from inside vim &lt;esc&gt; :.! ls\u00a0Run command ls from inside vim and write output into open file. &lt;esc&gt; :w !sudo ... Read More","og_url":"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/","og_site_name":"Robin Glauser","article_published_time":"2015-06-21T18:04:05+00:00","og_image":[{"width":700,"height":300,"url":"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/06\/vim1.jpg","type":"image\/jpeg"}],"author":"Robin Glauser","twitter_card":"summary_large_image","twitter_creator":"@robinglauser","twitter_site":"@robinglauser","twitter_misc":{"Written by":"Robin Glauser","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/#article","isPartOf":{"@id":"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/"},"author":{"name":"Robin Glauser","@id":"https:\/\/www.robinglauser.ch\/blog\/#\/schema\/person\/e1a94504a6ff5171fa13670932514b19"},"headline":"Some VIM tips and tricks.","datePublished":"2015-06-21T18:04:05+00:00","mainEntityOfPage":{"@id":"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/"},"wordCount":318,"commentCount":0,"publisher":{"@id":"https:\/\/www.robinglauser.ch\/blog\/#\/schema\/person\/e1a94504a6ff5171fa13670932514b19"},"image":{"@id":"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/#primaryimage"},"thumbnailUrl":"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/06\/vim1.jpg","keywords":["save","tips","vim"],"articleSection":["Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/","url":"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/","name":"Some VIM tips and tricks. - Robin Glauser","isPartOf":{"@id":"https:\/\/www.robinglauser.ch\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/#primaryimage"},"image":{"@id":"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/#primaryimage"},"thumbnailUrl":"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/06\/vim1.jpg","datePublished":"2015-06-21T18:04:05+00:00","breadcrumb":{"@id":"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/#primaryimage","url":"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/06\/vim1.jpg","contentUrl":"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/06\/vim1.jpg","width":700,"height":300},{"@type":"BreadcrumbList","@id":"https:\/\/www.robinglauser.ch\/blog\/2015\/06\/21\/some-vim-tips-and-tricks\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.robinglauser.ch\/blog\/"},{"@type":"ListItem","position":2,"name":"Some VIM tips and tricks."}]},{"@type":"WebSite","@id":"https:\/\/www.robinglauser.ch\/blog\/#website","url":"https:\/\/www.robinglauser.ch\/blog\/","name":"Robin Glauser","description":"My Blog about Development, Design and my random thoughts.","publisher":{"@id":"https:\/\/www.robinglauser.ch\/blog\/#\/schema\/person\/e1a94504a6ff5171fa13670932514b19"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.robinglauser.ch\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.robinglauser.ch\/blog\/#\/schema\/person\/e1a94504a6ff5171fa13670932514b19","name":"Robin Glauser","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/10\/DSC_1244_small.jpg","url":"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/10\/DSC_1244_small.jpg","contentUrl":"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/10\/DSC_1244_small.jpg","width":800,"height":530,"caption":"Robin Glauser"},"logo":{"@id":"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/10\/DSC_1244_small.jpg"},"description":"I'm a web developer.","sameAs":["https:\/\/www.robinglauser.ch","https:\/\/www.instagram.com\/robinglauser\/","https:\/\/x.com\/robinglauser"],"url":"https:\/\/www.robinglauser.ch\/blog\/author\/robin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/posts\/1099","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/comments?post=1099"}],"version-history":[{"count":5,"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/posts\/1099\/revisions"}],"predecessor-version":[{"id":1125,"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/posts\/1099\/revisions\/1125"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/media\/1115"}],"wp:attachment":[{"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/media?parent=1099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/categories?post=1099"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/tags?post=1099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}