简体   繁体   English

在vim中禁用自动缩进

[英]Disable autoindent in vim

I use vim since almost 20 years and recently someone told me about the usage of = key for indenting a block of code. 我使用vim已有近20年的时间,最近有人告诉我有关=键缩进代码块的用法。 Sometimes I try a new vim key but stop using it because it isn't doing exactly what I want or I just don't need the feature. 有时,我尝试使用新的vim密钥,但是由于它不能完全满足我的需求或者只是不需要该功能而停止使用。 But in this case I find its a nice feature. 但是在这种情况下,我发现它是一个不错的功能。

So I downloaded vim script 1120 (PHP-correct-Indenting) and installed it. 所以我下载了vim脚本1120(PHP-correct-Indenting)并安装了它。 My .vimrc contains: 我的.vimrc包含:

filetype indent on
set smartindent

Now I can use = to indent a visually marked code block. 现在,我可以使用=缩进视觉标记的代码块。

But I do NOT want vim to automatically indent code while I am typing. 但是我不希望vim在键入时自动缩进代码。 This is just irritating me as I am usually doing indentation myself and I am very much used to it ... 这只是让我感到恼火,因为我通常自己自己进行缩进,并且我已经习惯了...

So how can I stop vim from automatically indenting my code while typing but can still continue to use = for indenting a visually marked block of text. 因此,如何在输入时自动阻止vim自动缩进代码,但仍然可以继续使用=来缩进视觉标记的文本块。

PS: Use hjkl for moving around in vim. PS:使用hjkl在vim中移动。 It will make you about 1.5 times faster :) 它会使您快1.5倍:)

My complete vimrc: 我完整的vimrc:

syntax on

set tabstop=3
set shiftwidth=3

execute pathogen#infect()

filetype indent on
set smartindent 

Commenting the last two lines stops autoindenting but also using "=" does not use the mentioned vim script anymore 注释最后两行将停止自动缩进,但也使用“ =”不再使用上述的vim脚本

The plugin sets 'indentexpr' , which controls both explicit reindenting via = as well as indenting-as-you-type. 该插件设置了'indentexpr' ,它既可以控制通过=显式重新缩进,也可以根据您的输入进行缩进。 Fortunately, you can control the triggering of the latter via the 'indentkeys' option, so clearing that should work. 幸运的是,您可以通过'indentkeys'选项控制后者的触发,因此清除该选项就可以了。

Put the following into ~/.vim/after/indent/php.vim ; 将以下内容放入~/.vim/after/indent/php.vim ; this way, it'll apply after the plugin: 这样,它将在插件之后应用:

setlocal indentkeys=

The effect I want can get achieved using: 我想要的效果可以使用以下方法实现:

:set paste

This is exactly(?) the mode I wanted to switch into. 这正是我想要切换到的模式。 No autoindenting at all. 根本没有自动缩进。 But the "=" key works to indent a marked block of text. 但是“ =”键可用于缩进标记的文本块。

Maybe I will add "set paste" to my .vimrc :) 也许我会在“ .vimrc”中添加“设置粘贴” :)

Thanks for your support anyways. 无论如何,感谢您的支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM