{"id":262,"date":"2014-05-09T15:07:00","date_gmt":"2014-05-09T15:07:00","guid":{"rendered":"https:\/\/questy.org\/?p=262"},"modified":"2024-09-26T19:07:14","modified_gmt":"2024-09-26T19:07:14","slug":"why-all-the-vim","status":"publish","type":"post","link":"https:\/\/questy.org\/index.php\/2014\/05\/09\/why-all-the-vim\/","title":{"rendered":"Why All the Vim?"},"content":{"rendered":"\n<p>As we move on through the last post on Vim, you may ask yourself why I\u2019m remediating all the way back to text editors. &nbsp;Well, as you\u2019ll see over time, this is all about workflow; Building yourself a detailed workflow by which you can write code, syntax check, commit to revision control, deploy to your Puppet instances, and duplicate that workflow across all your environments.<\/p>\n\n\n\n<p>The text editor itself, while important, is just a tiny part of a much larger picture I hope to cobble together over time. &nbsp;So, let\u2019s begin to push forward with our coverage of Vim.<\/p>\n\n\n\n<p><strong>Plugins and Syntax Highlighting<\/strong><\/p>\n\n\n\n<p>I went through the beginnings of Vim to give you a starting point and some basics in the event you have no experience in the Vim world. &nbsp;One would assume that since you\u2019re on a Puppet\/Dev-Ops-y sort of page, all this is old news, but we do have completely \u201cgreen\u201d readers from time to time, and I didn\u2019t want to leave them out.<\/p>\n\n\n\n<p>The main goal in getting Vim in the picture was to bring you to the point where we start looking at our code and knowing what we\u2019re dealing with at a glance. &nbsp;As you begin to work in the field, whether coding in Perl, Python, Shell, or the Puppet DSL, there are some conventions out there all designed to help you and smooth your workflow. &nbsp;Of these is syntax highlighting in code editors in general, but (for our purposes) in Vim&nbsp;<em>specifically.<\/em><\/p>\n\n\n\n<p>Take a look at this screen:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"679\" src=\"https:\/\/i0.wp.com\/questy.org\/wp-content\/uploads\/2024\/08\/nosyn.png?resize=900%2C679&#038;ssl=1\" alt=\"\" class=\"wp-image-205\"\/><\/figure>\n\n\n\n<p>While the code is well formatted and everything seems ok, were there any issues in this document, you\u2019d never know it. &nbsp;From syntax issues to missing elements, none of this is automatically highlighted to you in any way. &nbsp;Enter syntax highlighting\u2026 &nbsp;Look again:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"679\" src=\"https:\/\/i0.wp.com\/questy.org\/wp-content\/uploads\/2024\/08\/nosyn.png?resize=900%2C679&#038;ssl=1\" alt=\"\" class=\"wp-image-205\"\/><\/figure>\n\n\n\n<p>Much nicer, no? &nbsp;Were there any missing elements, you\u2019d see something amiss in the document. &nbsp;The colors would not be organized according to element type, and odd things would be displayed in the page. &nbsp;Let me \u201cbreak\u201d the file for you\u2026<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"679\" src=\"https:\/\/i0.wp.com\/questy.org\/wp-content\/uploads\/2024\/08\/broke.png?resize=900%2C679&#038;ssl=1\" alt=\"\" class=\"wp-image-170\"\/><\/figure>\n\n\n\n<p>You\u2019ll notice that on line 4 something is amiss. &nbsp;If you compare the two colored instances, you\u2019ll see that your eye is drawn to where things begin to be different. &nbsp;Best part for quick and easy glancing is that the entirety of the file after that one mistake now looks \u201cwrong\u201d. &nbsp;Ease of view.<\/p>\n\n\n\n<p><strong>How Can This Help With Puppet?<\/strong><\/p>\n\n\n\n<p>As luck would have it, Vim has a plugin engine that allows you to have pre-built templates that syntax highlight code for you in a predetermined way. &nbsp;It \u201crecognizes\u201d your code type, and highlights accordingly. &nbsp;The basic plugin structure for vim lives in your home directory and in the \u201chidden\u201d .vim directory. &nbsp;Under this directory you can have a number of wide and varied add ons to vim. &nbsp;We\u2019re just going to talk about plugins.<\/p>\n\n\n\n<p>By default, you don\u2019t have anything in this directory. &nbsp;You usually have a .vimrc file and a .vim directory in your home directory location, but that\u2019s about it. &nbsp;The \u201cmagic\u201d happens, though, when you add a few pieces. &nbsp;Those would include a \u201c.vimrc\u201d file which will turn on syntax highlighting, and then a Puppet vim plugin that sorts all the language elements and colorizes them for you.<\/p>\n\n\n\n<p>In your home directory, if it doesn\u2019t already exist, create a .vimrc file with a single entry:<\/p>\n\n\n\n<p><strong>syntax on<\/strong><\/p>\n\n\n\n<p>This will instruct vim to syntax highlight, and to be aware of any highlighting plugins that may live in the .vim plugin folder. &nbsp;Next, place&nbsp;<a href=\"http:\/\/questy.org\/stuff\/puppet\/puppet.vim\">this file<\/a>&nbsp;into your .vim plugin directory. &nbsp;If it does not yet exist, create it. &nbsp;It lives in ~\/.vim\/plugin. &nbsp;Once you load up new puppet manifests, it will recognize the type and begin to highlight the code according to the defined convention from the puppet.vim file you just downloaded. &nbsp;If you have any issues, look at the vim plugin reference&nbsp;<a href=\"http:\/\/vimdoc.sourceforge.net\/htmldoc\/usr_05.html\">here<\/a>.<\/p>\n\n\n\n<p>Now you\u2019re ready to work with Puppet files like a pro!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As we move on through the last post on Vim, you may ask yourself why I\u2019m remediating all the way back to text editors. &nbsp;Well, as you\u2019ll see over time, this is all about workflow; Building yourself a detailed workflow by which you can write code, syntax check, commit to revision control, deploy to your [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[6],"tags":[],"class_list":["post-262","post","type-post","status-publish","format-standard","hentry","category-technology"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/posts\/262","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/comments?post=262"}],"version-history":[{"count":1,"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/posts\/262\/revisions"}],"predecessor-version":[{"id":263,"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/posts\/262\/revisions\/263"}],"wp:attachment":[{"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/media?parent=262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/categories?post=262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/tags?post=262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}