Home > Uncategorized > Editing GEDCOM files with vim

Editing GEDCOM files with vim

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.

Compare the readability of the two formats

Save the next few lines into a file called gedcom_indent. Make the file executable and place it somewhere in your path.

#!/usr/bin/env python

from __future__ import print_function
import sys

for line in sys.stdin:
    line = line.lstrip()
        level = int(line.split(' ', 1)[0])
        print('\t' * level, end='')
    print(line, end='', sep='')

Now add the following 2 lines to your ~/.vimrc file:

autocmd BufReadPost,FileReadPost *.ged %!gedcom_indent
autocmd FileType gedcom set foldmethod=indent nolist ts=4

This tells vim to filter any file with a “ged” 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.

Categories: Uncategorized Tags: , ,
  1. May 2nd, 2021 at 17:55 | #1

    Here’s a Golang equivalent:

    package main

    import (

    func main() {

    in := bufio.NewReader(os.Stdin)
    for {
    s, err := in.ReadString(‘\n’)
    if err != nil {
    // io.EOF is expected, anything else
    // should be handled/reported
    if err != io.EOF {
    // Do something with the line of text
    // in string variable s.
    _ = s
    //fmt.Print(“added: “+s)

    trimmed := strings.TrimSpace(s);
    level,err := strconv.Atoi(strings.Split(trimmed,” “)[0])


  1. No trackbacks yet.