Skip to content

Instantly share code, notes, and snippets.

@romainl
Last active March 20, 2024 10:11
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romainl/58245df413641497a02ffc06fd1f4747 to your computer and use it in GitHub Desktop.
Save romainl/58245df413641497a02ffc06fd1f4747 to your computer and use it in GitHub Desktop.
How to add dynamic highlighted parts to your status-line

How to add dynamic highlighted parts to your status-line

Anatomy of a "part":

Start of highlighting Dynamic content End of highlighting
%#IsModified# %{&mod?expand('%'):''} %*
  • Non-empty parts are visible because they are not empty.
  • Empty parts are not visible because they are empty.
  • If you want to hide a part, make it empty.
  • If you want to show a part, make it non-empty.
  • Part A and part B are always included in the status-line but they can be empty.
  • Part A is visible only when the current buffer is modified because it contains the buffer name only when it's modified.
  • Part B is only visible when the current buffer is not modified because it contains the buffer name only when it's not modified.

My Vim-related gists.

" custom highlight groups
highlight IsModified ctermbg=red
highlight IsNotModified ctermbg=green
" Dynamic status line
set statusline+=%#IsModified#%{&mod?expand('%'):''}%*%#IsNotModified#%{&mod?'':expand('%')}%*
" \______________ Part A _____________/\______________ Part B ________________/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment