Is it possible to display indentation guides in Vim?

后端 未结 7 1152
暖寄归人
暖寄归人 2020-11-30 18:50

I\'m a longtime Vim user (3 or 4 years) who has recently started dealing with some deeply nested code. This code is indented with spaces, not tabs. I would like some clean

相关标签:
7条回答
  • 2020-11-30 19:04

    NOTE: This answer is a bit late to the party and also a shameless plug :)

    Regardless, try my Indent-Guides.vim plugin. It was created to scratch my own itch regarding the lack of indent guides in vim. I got fed-up waiting for someone else to come along and build it, so I just did it myself.

    Features:

    • Can detect both tab and space indent styles.
    • Automatically inspects your colorscheme and picks appropriate colors (gVim only).
    • Will highlight indent levels with alternating colors.
    • Full support for gVim and basic support for Terminal Vim.
    • Seems to work on Windows gVim 7.3 (haven't done any extensive tests though).
    • Customizable size for indent guides, eg. skinny guides (soft-tabs only).
    • Customizable start indent level.

    Here's a few screenshots of the plugin in action: put your mouse here and click.

    0 讨论(0)
  • 2020-11-30 19:04

    use the Indent-Guides.vim plugin, and toggle use ig whenever you need it. Sometimes it could be annoying though :)

    0 讨论(0)
  • 2020-11-30 19:05

    The following command will configure Vim to show dots to indicate the indentation level as you type. The dots magically disappear when the cursor leaves the line:

    :set list listchars=tab:»-,trail:·,extends:»,precedes:«
    
    0 讨论(0)
  • 2020-11-30 19:11

    Try out this VIM plugin BlockHL It color codes the indentation of each successive level differently.

    EDIT:What lanaguge are you using? This plugin is for C-style languages.

    0 讨论(0)
  • 2020-11-30 19:14

    You might use tabs to display indentation guides and remove tabs before saving file:

    " use 4 spaces for tabs
    set tabstop=4 softtabstop=4 shiftwidth=4
    
    " display indentation guides
    set list listchars=tab:❘-,trail:·,extends:»,precedes:«,nbsp:×
    
    " convert spaces to tabs when reading file
    autocmd! bufreadpost * set noexpandtab | retab! 4
    
    " convert tabs to spaces before writing file
    autocmd! bufwritepre * set expandtab | retab! 4
    
    " convert spaces to tabs after writing file (to show guides again)
    autocmd! bufwritepost * set noexpandtab | retab! 4
    
    0 讨论(0)
  • 2020-11-30 19:17

    If you indent code with spaces, you can try my plugin: https://github.com/Yggdroot/indentLine, it displays thin vertical lines but not thick vertical lines as the above answers mentions. If you indent code with tab, just :set list lcs=tab:\|\ (here is a space)

    0 讨论(0)
提交回复
热议问题