Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix indentation and tab/space indentation representation in Neovim #25

Merged
merged 4 commits into from
Nov 11, 2024

Conversation

vicnett
Copy link
Owner

@vicnett vicnett commented Nov 10, 2024

What

  • Make lcs-tab and lcs-leadmultispace show different secondary characters to visually differentiate between space- and tab-based indentation.
  • Make lcs-leadmultispace automatically adapt to tabstop and/or shiftwidth changes.
  • Re-indent all Lua files in vim/ to use two-space indentation.

Why

I wanted two-space indentation in Lua files all along, and I thought I had achieved that using stylua but I accidentally made them all use tabs, and I didn't realize because my "visual" Neovim config was set to show leading tabs and leading spaces the same way.

While working on solving this, I realized that the length of lcs-leadmultispace needs to match the length of space-based indentation for it to "line up" visually. Since I use a vertical line character to indicate indentation, the lcs-leadmultispace value definitely needs to keep up with indentation so that the line will line up, or it will defeat the purpose.

I found and adapted some autocmd code that will dynamically change lcs-leadmultispace every time either tabstop or shiftwidth changes, which in turn are kept dynamically in sync with local indentation by vim-sleuth.

Testing

  • Confirmed that tab- and space-based indentation is represented differently and easy to tell apart.
  • Confirmed all Lua files are now indented with spaces.
  • Confirmed lcs-leadmultispace correctly follows changes in indentation, resulting in expected "vertical indentation guide line" behavior.

In order to easily distinguish between tab- and space-based indentation,
this sets the `tab` value in `listchars` to show a › after a vertical
line.
Because vim-sleuth will dynamically change the values of `tabstop` and
`shiftwidth` based on context cues and config files, a single value for
`lcs-multispace` leads to unexpected behavior where multiple vertical
lines may be shown for each level of indentation.

This implements autocmds to adjust the value of `lcs-multispace`
whenever `shiftwidth` and/or `tabstop` change, so that there will always
be a single vertical line per level of indentation, as detected by
vim-sleuth.
@vicnett vicnett force-pushed the fix-vim-indentation-listchars branch from ab0a8b4 to 70bedb7 Compare November 10, 2024 21:01
@vicnett vicnett merged commit a57ebec into main Nov 11, 2024
1 check passed
@vicnett vicnett deleted the fix-vim-indentation-listchars branch November 11, 2024 02:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant