douyu0725 2017-10-08 18:58
浏览 82
已采纳

Vim正常模式下的制表符宽度为1个字符,未与左边距对齐

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.

  • 写回答

1条回答 默认 最新

  • douqian1835 2017-10-09 09:30
    关注

    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:

    • With :set list, Vim puts the cursor at the front, as you want. But you'll see whitespace highlighted, too. You could fiddle with the 'listchars' option to reduce the visual noise, but then you'll lose that helpful feature.
    • With :set virtualedit=all, you can position the cursor anywhere inside a tab. Starting editing in the middle of it breaks the tab character into space before and after. Also, you can position the cursor anywhere behind physical text.
    • With :autocmds, you could convert tabs to spaces on reading the buffer, and back on writing. (See :help retab-example)
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教