如何禁用Slimv对非Lisp文件的自动缩进?

时间:2019-06-03 10:16:51

标签: vim indentation auto-indent slimv

非苗条行为

首先,让我展示未启用Slimv时Vim的正常行为。

  1. 创建一个新文件:vim foo.c
  2. 进入插入模式: i
  3. 输入此代码:void f()
  4. enter

光标现在位于位置2,1(第二行,第一列)上。

苗条行为

安装Slimv之后,如果执行上述步骤,最后,我将光标定位在位置2,5(第二行,第五列)的位置,并在第五列之前自动插入四个空格作为缩进。

如何为非Lisp文件(例如.c文件)禁用这种Slimv行为?

2 个答案:

答案 0 :(得分:1)

问题是由paredit.vim中的这一行引起的:

filetype indent on

我在paredit.vim中添加了选项g:paredit_disable_ftindent以禁用缩进文件的加载,请在使用paredit.vim(或还包含paredit.vim的slimv)时将此行添加到您的.vimrc中:

let g:paredit_disable_ftindent=1

答案 1 :(得分:0)

首先,将以下两行添加到您的vimrc文件中:

filetype indent off
filetype plugin indent off

然后,您必须希望它会起作用!但是很有可能不会……

如果解决方案不起作用,则可能必须采取非常复杂的措施来解决问题。

问题是您的许多vim选项经常被许多触发器和自动命令更改。我发现的唯一方法是,用重要的符号标记重要的选项(我不想更改的选项),然后在可能的影响后强制将其还原。因此,我在vimrc中做了以下操作:

augroup MyVimrc
    autocmd!
augroup END

"The options I want to keep unchanged, I mark with the “❗” symbol.
"The usual exclamation sign “!” will work as well.
"Of course, you’re free using any other symbol you like, 
"but don’t forget the lambda-function in the hack below.

"These are the options that may influence on the indent.
set formatoptions=j    "❗
set autoindent    "❗
set nosmartindent    "❗
set indentexpr=    "❗
set copyindent      "❗
set preserveindent     "❗

"And I marked with the same way a number of other 
"important (for me) options… (not shown here)

"At the bottom of the vimrc file, I wrote this dirty hack.

function! s:keep_options()
    for line in filter(readfile($MYVIMRC), 'v:val =~ ''\v\".*(!|❗)\s*$''')
        exe line
    endfor
endfunction

command! KeepOptions call <SID>keep_options()

"Note, the “OptionSet” trigger doesn’t work always, so that I preferred “BufEnter”.
autocmd MyVimrc BufEnter * KeepOptions

最后,我的设置发生了不可预测的变化,所有的麻烦都消失了。

相关问题