govimindentationgofmt

Vim normal mode shows tabs as 1 char wide, not aligned to left margin


enter image description here This is the leftmost my cursor goes in normal mode.

enter image description here This is how it looks in insert mode.

I have the following filetype settings

au BufNewFile,BufRead *.py
     \ set tabstop=4 |
     \ set softtabstop=4 |
     \ set shiftwidth=4 |
     \ set textwidth=79 |
     \ set expandtab |
     \ set autoindent |
     \ set fileformat=unix |

 au BufNewFile,BufRead *.js, *.html, *.css
     \ set tabstop=2 |
     \ set softtabstop=2 |
     \ set shiftwidth=2 |

 au BufNewFile,BufRead *.go
     \ set tabstop=4 |
     \ set softtabstop=4 |
     \ set shiftwidth=4 |
     \ set noexpandtab |
     \ set smarttab

This typically happens with .go files as I guess I have noexpandtab. But the cursor not going to column-0 in normal mode freaks me out.


Solution

  • What you see is normal Vim behavior. On a line that starts with a <Tab> character, the cursor is shown on the character; as a tab occupies multiply (default 8) screen cells, Vim puts the cursor at the end of the character (for double-width characters, Vim also double the character, but a 8-char wide cursor probably would look bad, and may not technically be possible in the terminal) in normal mode. In insert mode, the cursor is between characters, so you can position the cursor before (e.g. with gI) and after (I) the tab.

    Remedies

    It would be best to accept this behavior; if you really can't stand it, here are some options that change the behavior. Unfortunately, each comes with caveats and downsides: