0

How could I replace text in status line flags?

set laststatus=2
set statusline=
set statusline+=%r%m

Is there a way to replace [RO] to Read only, and [+] to Modified?

  • I agree that vi.stackexchange is the better place to ask, anyway you should not crosspost. – Ralf Feb 1 at 21:56
  • @Ralf I assumed to wait for the first answer and then immediately remove duplicate question. – john c. j. Feb 1 at 21:59
1

You can use conditional expressions when defining the statusline. Like:

set statusline+=%{&modified?\"Modified\":\"\"}
set statusline+=%{&readonly?\"Read\ Only\":\"\"}

See :help 'statusline' (it's a long text).

The &modified is the notation to access a option from Vim script. As modified and readonly are are boolean options, you can test them as shown above.

To check for a help file you would need:

set statusline+=%{&ft==\"help\"?\"HELP\ ME\":\"\"}

Here ft is short for the option filetype.

At some point you might be better off by moving all this stuff into a function to return the statusline. Like:

set statusline=%!MyStatuslineFunction()

The plugin vim-airline does it this way.

  • @Mass Does it realy influence the statusline? I couldn't make it work. – Ralf Feb 1 at 22:12
  • @Ralf Hmm, I checked the help article, but there are no mentions of &modified or &readonly. Where I could find these "long words" for another flags, e.g. h flag and w flag? – john c. j. Feb 1 at 22:39
  • At some point, I’d pull this out into a function and use a dictionary, if I really wanted to change lots of values – D. Ben Knoble Feb 1 at 22:43
  • @johnc.j. see update – Ralf Feb 1 at 22:56
  • @Ralf you are right – Mass Feb 1 at 23:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.