Ignore regions when formatting buffers with three keys

I’m quite fond of keeping my code formatted.
For example I use yapf to format python code.
Sometimes I want particular regions not to be formatted.
In particular I want rows to stay rows but one line.

The solution is to indicate such regions for the formatter

Without indication, the buffer is formatted from this:

rows = [
    ('john', 'acme'),
    ('jane', 'acme')
]

to that:

rows = [('john', 'acme'), ('jane', 'acme')]

With added indication the formatter ignores such regions:

rows = [
    # yapf: disable
    ('john', 'acme'),
    ('jane', 'acme')
    # yapf: enable
]

Now manually typing these opening and closing indicators each time would be a bit cumbersome, wouldn’t it?
Luckily emacs’ evil-surround has you covered.

Add this to your init.el

(with-eval-after-load 'evil-surround
  (push '(?y . ("# yapf: disable" . "# yapf: enable")) evil-surround-pairs-alist))

Now visually selecting any desired region and hitting gSy subsequently, uhm, surrounds as expected.