Transitioning to vim. Having issues with indentation

前端 未结 2 1604
执念已碎
执念已碎 2021-01-24 23:47

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. Addit

相关标签:
2条回答
  • 2021-01-25 00:25

    In my vimrc I have the following:

    set autoindent
    set expandtabs
    set shiftwidth=4
    set tabstop=4
    

    Actually I just have

    set ai et sw=4 ts=4
    

    You can change the specific settings using FileType or BufEnter:

    autocmd BufEnter *.py ai et sw=4 ts=4
    
    0 讨论(0)
  • 2021-01-25 00:40

    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).

    After directory approach

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

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

    Autocommand approach

    Add the following to your ~/.vimrc file:

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

    Learn more

    As you are just starting to vim it is best to learn how to query these options so you can track down future bugs. Querying an option is as simple as :verbose set {option}?, e.g. :verbose set expandtab?.

    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
    
    0 讨论(0)
提交回复
热议问题