{"id":356,"date":"2012-03-05T02:02:20","date_gmt":"2012-03-05T07:02:20","guid":{"rendered":"http:\/\/ebixio.com\/blog\/?p=356"},"modified":"2016-12-22T23:50:06","modified_gmt":"2016-12-23T04:50:06","slug":"editing-gedcom-files-with-vim","status":"publish","type":"post","link":"http:\/\/ebixio.com\/blog\/2012\/03\/05\/editing-gedcom-files-with-vim\/","title":{"rendered":"Editing GEDCOM files with vim"},"content":{"rendered":"<p>GEDCOM files sometimes have no indentation. That makes it difficult to read or edit them with a text editor. Using the following simple instructions, you can auto-indent the file so that it is more readable in the vim editor.<\/p>\n<p><div id=\"attachment_362\" style=\"width: 590px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/ebixio.com\/blog\/wp-content\/uploads\/2012\/03\/GEDCOM-12.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-362\" src=\"http:\/\/ebixio.com\/blog\/wp-content\/uploads\/2012\/03\/GEDCOM-12.png\" alt=\"\" title=\"GEDCOM Indentation\" width=\"580\" height=\"365\" class=\"size-full wp-image-362\" srcset=\"http:\/\/ebixio.com\/blog\/wp-content\/uploads\/2012\/03\/GEDCOM-12.png 620w, http:\/\/ebixio.com\/blog\/wp-content\/uploads\/2012\/03\/GEDCOM-12-300x188.png 300w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/a><p id=\"caption-attachment-362\" class=\"wp-caption-text\">Compare the readability of the two formats<\/p><\/div><\/p>\n<p>Save the next few lines into a file called <code>gedcom_indent<\/code>. Make the file executable and place it somewhere in your path.<\/p>\n\r\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n#!\/usr\/bin\/env python\r\n\r\nfrom __future__ import print_function\r\nimport sys\r\n\r\nfor line in sys.stdin:\r\n    line = line.lstrip()\r\n    try:\r\n        level = int(line.split(' ', 1)&#x5B;0])\r\n        print('\\t' * level, end='')\r\n    except:                                                                                                                                            \r\n        pass\r\n    print(line, end='', sep='')\r\n<\/pre>\r\n<p>Now add the following 2 lines to your ~\/.vimrc file:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nautocmd BufReadPost,FileReadPost *.ged %!gedcom_indent\r\nautocmd FileType gedcom set foldmethod=indent nolist ts=4\r\n<\/pre>\n<p>This tells vim to filter any file with a &#8220;ged&#8221; extension through the small gedcom_indent filter (which will add leading tabs to the file). The second line tells it to make each TAB count for 4 spaces, and to fold based on indentation.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>GEDCOM files sometimes have no indentation. That makes it difficult to read or edit them with a text editor. Using the following simple instructions, you can auto-indent the file so that it is more readable in the vim editor. Save the next few lines into a file called gedcom_indent. Make the file executable and place [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[32,31,9],"class_list":["post-356","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-gedcom","tag-python","tag-vim"],"_links":{"self":[{"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/posts\/356","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/comments?post=356"}],"version-history":[{"count":13,"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/posts\/356\/revisions"}],"predecessor-version":[{"id":647,"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/posts\/356\/revisions\/647"}],"wp:attachment":[{"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/media?parent=356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/categories?post=356"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/tags?post=356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}