Vim Tips Wiki
Advertisement

Previous TipNext Tip

Tip: #735 - Show fileencoding and bomb in the status line

Created: May 28, 2004 12:56 Complexity: basic Author: A. J. Mechelynck Version: 5.7 Karma: 15/6 Imported from: Tip#735

This stems with a discussion on the vim-list yesterday and today (27/28 May 2004). It is a modification on one of the examples given under ":help 'statusline'", which is where its workings are explained. (See also ":help expr1" for the if?then:else expression construct).


The (long) line below comes from my vimrc. I recommend copy-paste if you want to use it. It adds, at the left of the right-hand part of the status line, a pair of square brackets containing the value of 'fileencoding' for the file you are editing (or that of 'encoding' if 'fileencoding' is empty). The file's encoding is followed by a comma and B if 'bomb' is functional and has the value 1 (TRUE). Examples are [latin1], [iso-8859-15], [utf-8,B], etc.


The complexity of the value is due in large part to the necessity of (a) specifying explicitly the fields used implicitly when 'statusline' is empty (I hope I didn't forget any of them), and (b) backslash-escaping all spaces and quotation marks.


Now here it is:


if has("statusline")

set statusline=%<%f\ %h%m%r%=%{\"[\".(&fenc==\"\"?&enc:&fenc).((exists(\"+bomb\")\ &&\ &bomb)?\",B\":\"\").\"]\ \"}%k\ %-14.(%l,%c%V%)\ %P 

endif


N.B.

1. The command from "set" to "%P" should be all on one line.

2. This tip is rated as "of Vim 5.7" because I think it uses nothing that is new in version 6. But I've never had any version of Vim earlier than 6.1, which means that I cannot be 100% sure of what works, or not, on version 5. (IMHO, if you still have a version 5 Vim, you should upgrade to a more recent version anyway if it is at all possible.)


Happy Vimming !

Tony.

Comments

This tip is what I was looking for a long time!

Thanks!

marax


pvokoun--AT--wo.cz , September 24, 2004 5:56


Advertisement