Vim 8.0:在Ubuntu 18.04 LTS上无法禁用自动缩进

3
我正在使用Ubuntu 18.04 LTS,通过sudo apt get install vim安装了vim软件包,版本号为8.x。 我已经执行了set noautoindentset nosmartindent,但是缩进仍然会自动发生。 这更像是一种“智能”缩进,因为如果我在*.rb文件中键入enter后键入“end”,则缩进会自动删除。
2个回答

9
在评论中,Roman Odaisky提供了Ubuntu 18.04 LTS的工作解决方案。在此,我将其搬到这里,并稍微扩展一下,以便于未来的用户使用,因为我花费了一些时间才找到禁用此烦恼的方法。
  1. To turn off all autoindent temporarily in VIM session issue the following command while in vi:

    :setl noai nocin nosi inde=
    
  2. To have VIM remember the setting, add it to your .vimrc:

    $ vi ~/.vimrc
    ---
    setlocal noautoindent
    setlocal nocindent
    setlocal nosmartindent
    setlocal indentexpr=
    

3
谢谢。在编辑YAML文件时,由于无效范围导致---被删除后,在我的18.04LTS上出现了E16: Invalid range: ---错误。但是您的答案对我保持清醒非常有帮助! - kmarsh
必须在用户的 .vimrc 文件中设置,而不是系统范围内的(/etc/vim/vimrc.local)。同样适用于 20.04LTS。 - Andrew Murphy

0

:filetype plugin indent off是什么意思?

同时考虑使用'pastetoggle'来暂时禁用缩进以进行粘贴。


“filetype plugin indent off”和“filetype indent off”都没有起作用。我尝试使用--clean选项启动vim,但仍然是同样的情况。 - Lan Do
2
还有setlocal indentexpr=吗?https://vim.fandom.com/wiki/How_to_stop_auto_indenting - Roman Odaisky
set indentexpr= 真的很有效。而且这份文档也非常有帮助。感谢您的帮助。 - Lan Do

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接