Show file encoding in the statusline.
authorIain Patterson <me@iain.cx>
Fri, 31 Jan 2014 16:41:07 +0000 (16:41 +0000)
committerIain Patterson <me@iain.cx>
Mon, 3 Feb 2014 14:10:07 +0000 (14:10 +0000)
And BOM indicator if appropriate.

.vimrc

diff --git a/.vimrc b/.vimrc
index d29cc40..88ef372 100644 (file)
--- a/.vimrc
+++ b/.vimrc
@@ -662,13 +662,38 @@ fun! Has_Unicode() "{{{2
   return 0
 endfun "}}}2
 
+" Helper for status line.
+" Show file encoding
+func! Show_Encoding() "{{{2
+  let l:enc = &fenc
+  if l:enc == ""
+    let l:enc = &enc
+    if l:enc == ""
+      return ""
+    endif
+    let l:enc = '(' . l:enc . ')'
+  endif
+
+  if has("multi_byte")
+    if &bomb
+      if Has_Unicode()
+        let l:enc = l:enc . "☻"
+      else
+        let l:enc = l:enc . "@"
+      endif
+    endif
+  endif
+
+  return l:enc . ","
+endfun "}}}2
+
 " Helper for status line.
 " Show space, underscore or dollar sign depending on list mode.
 fun! Show_List() "{{{2
   call Iain_Vars()
   if w:iainlist == 0
     " No list.
-    return " "
+    return ""
   elseif Has_Unicode()
     if w:iainlist == 1
       " Just tabs.
@@ -799,7 +824,7 @@ fun! Show_StatusLine() "{{{2
     return
   endif
   call Iain_Vars()
-  let l:sl1='%2n\:\ %<%1*%f%0*\ [%{Show_List()}%{Show_Bind()}%{Show_Case()}%{Show_Tabstop()}%{Show_Paste()}%{Show_VirtualEdit()}%{Show_Undo()}%Y%M%R%{Show_SearchForward()}]%{Show_Alt()}\ '
+  let l:sl1='%2n\:\ %<%1*%f%0*\ [%{Show_Encoding()}%{Show_List()}%{Show_Bind()}%{Show_Case()}%{Show_Tabstop()}%{Show_Paste()}%{Show_VirtualEdit()}%{Show_Undo()}%Y%M%R%{Show_SearchForward()}]%{Show_Alt()}\ '
   let l:sl3='L:%1*%4.6l%0*/%-4.6L\ C:%1*%3.6c%V%0*\ \|\ %P'
   let l:hexformat='%b'
   if b:iainhex