Created
July 20, 2025 01:15
-
-
Save iglesias/5243d26b20be604d080c602b2f3410d7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function! SetupIndentConceal() | |
| " Only for Python files | |
| if &ft != 'python' | return | endif | |
| " Clear previous syntax without erroring in case the group doesn't exist | |
| silent! syntax clear LeadingSpaceConceal | |
| " Required conceal settings | |
| set conceallevel=2 | |
| set concealcursor=nvic | |
| " Match 4 leading spaces, replace last 2 with '| ' | |
| syntax match LeadingSpaceConceal /\(^\s\{2}\)\@<= / conceal cchar=| | |
| " Match 8 spaces | |
| syntax match LeadingSpaceConceal /\(^\s\{6}\)\@<= / conceal cchar=| | |
| " Match 12 spaces | |
| syntax match LeadingSpaceConceal /\(^\s\{10}\)\@<= / conceal cchar=| | |
| " Match 16 spaces | |
| syntax match LeadingSpaceConceal /\(^\s\{14}\)\@<= / conceal cchar=| | |
| " Match 20 spaces (add more rules if needed) | |
| syntax match LeadingSpaceConceal /\(^\s\{18}\)\@<= / conceal cchar=| | |
| redraw! | |
| endfunction | |
| " Auto-trigger when opening a file or entering a buffer | |
| " autocmd BufEnter,FileType python call SetupIndentConceal() | |
| augroup PythonIndentConceal | |
| autocmd! | |
| autocmd FileType python call SetupIndentConceal() | |
| autocmd BufWinEnter *.py call SetupIndentConceal() | |
| augroup END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment