过渡到vim.有缩进问题 [英] Transitioning to vim. Having issues with indentation

查看:26
本文介绍了过渡到vim.有缩进问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从手术中恢复过来,因此,我正在过渡到 VIM.作为我的起点,我选择使用 vim-sensible 插件作为我配置的基础.此外,我已经安装了 'vim-rails' 和 'vim-ruby' 插件.这些都是通过 Pathogen 加载的.

I am recovering from a surgery, thusly, I am transitioning to VIM. As I starting point, I've opted to use the vim-sensible plugin as the foundation of my configuration. Additionally, I've installed the 'vim-rails' and 'vim-ruby' plugins. These are all loaded via Pathogen.

无论出于何种原因,插件都没有根据文件类型调整缩进设置.选项卡似乎锁定到 9 列.我可以手动设置它们,但显然这并不理想.

For whatever reason, the plugins are not adjusting indentation settings in accord with filetype. Tabs seem locked to 9 columns. I am able to set them manually, but obviously this is not ideal.

这是我的 .vimrc.如您所见,它非常基础.

Here is my .vimrc. As you can see, it is very basic.

execute pathogen#infect()
syntax on
filetype plugin indent on

推荐答案

Vim 提供了以下缓冲区本地选项来管理缩进:'softtabstop''shiftwidth''tabstop''expandtab'.这个想法是为特定的文件类型设置这些选项,例如ruby 使用 autocommand 或使用 after ftplugin 目录(我的偏好).

Vim provides the following buffer local options for managing indention: 'softtabstop', 'shiftwidth', 'tabstop', and 'expandtab'. The idea is to set these options for a specific filetype, e.g. ruby either by using an autocommand or using the after ftplugin directory (my preference).

将以下内容添加到您的 ~/.vim/after/ftplugin/ruby.vim 文件中:

Add the following to your ~/.vim/after/ftplugin/ruby.vim file:

setlocal softtabstop=2
setlocal shiftwidth=2
setlocal tabstop=2

自动命令方法

将以下内容添加到您的 ~/.vimrc 文件中:

augroup MyIndentSettings
  autocmd!
  autocmd FileType ruby setlocal softtabstop=2 shiftwidth=2 tabstop=2
augroup END

了解详情

当您刚刚开始使用 vim 时,最好学习如何查询这些选项,以便您可以追踪未来的错误.查询一个选项就像 :verbose set {option}? 一样简单,例如:verbose set expandtab?.

您可能还对 Tim Pope 的 vim-sleuth 感兴趣,它启发式地设置缩进设置.

You may also be interested in Tim Pope's vim-sleuth which heuristically sets indent settings.

有关更多帮助,请参阅:

For more help see:

:h :set
:h 'softtabstop'
:h 'shiftwidth'
:h 'tabstop'
:h 'expandtab'
:h after-directory

这篇关于过渡到vim.有缩进问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆