Skip to content

Instantly share code, notes, and snippets.

@romainl
Last active April 25, 2023 08:04
Show Gist options
  • Save romainl/eabe0fe8c564da1b6cfe1826e1482536 to your computer and use it in GitHub Desktop.
Save romainl/eabe0fe8c564da1b6cfe1826e1482536 to your computer and use it in GitHub Desktop.
Highlight characters after line 80
augroup TooLong
autocmd!
autocmd winEnter,BufEnter * call clearmatches() | call matchadd('ColorColumn', '\%>80v', 100)
augroup END
@igbanam
Copy link

igbanam commented Apr 25, 2023

I made this variable by replacing the second argument of matchadd with '\%>' .. eval('&tw') .. 'v'. This way, it respects whatever the user has set to be their text width.

…but I quickly reverted that when I went into a .md file which has tw=0 in my config.

I guess a smart way would be a function which uses a default number when the set text width is either not set or zero, else respect the already set text width.

@romainl
Copy link
Author

romainl commented Apr 25, 2023

I don't think you need the eval(), here. This should be enough:

'\%>' .. &tw .. 'v'

That said set tw=0 means that there is no line length limit for that buffer so a better approach would probably be to wrap the whole thing in a conditional:

  • if &tw > 0, highlight the characters after tw,
  • if &tw == 0, don't highlight anything as it doesn't make sense in that context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment