2

When editing the following yaml with Vim:

countries:
  - country:
      name: France

I can comment out line 2 with :2s/^/#Enter (Case 1). The result is as expected:

countries:
#  - country:
      name: France

However, when I tried to do the same with 2G^hhi#ESC (Case 2), the result will be different :

countries:
        #- country:
      name: France

Extra 8 spaces are now present before #.

What causes this behavior, and how do I achieve the same behavior as Case 1, while using keystrokes somewhat more similar to Case 2 ?

1 Answers1

1

^ in normal-mode vim means "the first non-whitespace column of the line"

0 in normal-mode vim means "the first column of the line"

Thus, 2G0i# would go to line 2, column zero, in insert mode, and type #.

jeremysprofile
  • 342
  • 3
  • 14
  • 1
    I'm afraid `2G0i#` was equivalent to `2G^hhi#`, in this specific case. I forgot `0` and this suggestion was also helpful, though. – ŌHARA Kazutaka Mar 20 '19 at 01:29
  • I'm confused. Are you saying that `0` doesn't take you to the beginning of the line? – jeremysprofile Mar 20 '19 at 04:51
  • 1
    `0` does navigate to the beginning of the line. The problem was however about `indentexpr` issue, as explained by Christian, and `2G0i#` will result in the same consequence as Case 2, depending on the configuration. In one of my environments, `:set indentexpr` will show `indentexpr=GetYAMLIndent(v:lnum)`, where the problem occurs, while it isn't reproduced in another environment where `:set indentexpr` shows `indentexpr=`. – ŌHARA Kazutaka Mar 20 '19 at 08:54