Only show encoding and format if not utf-8[unix]
dblume

dblume commited on 2024-03-18 19:06:42
Showing 2 changed files, with 30 additions and 10 deletions.

... ...
@@ -77,6 +77,13 @@ function! GitBranch()
77 77
   return strlen(l:branchname) > 0 ? '  │ '.l:branchname : ''
78 78
 endfunction
79 79
 
80
+function! EncodingAndFormat()
81
+  if (len(&fileencoding) && &fileencoding != 'utf-8') || &fileformat != 'unix'
82
+    return &fileencoding?&fileencoding:&encoding .'['. &fileformat . '] │ '
83
+  endif
84
+  return ''
85
+endfunction
86
+
80 87
 function! Current_mode()
81 88
   let l:currentmode={
82 89
     \ 'n'  : 'NORMAL',
... ...
@@ -112,9 +119,8 @@ set statusline+=\ %=
112 119
 set statusline+=%h
113 120
 set statusline+=\ %{Trim_brackets(&filetype)}
114 121
 set statusline+=\ %#StatusLineNC#
115
-set statusline+=\ %{&fileencoding?&fileencoding:&encoding}
116
-set statusline+=\[%{&fileformat}\]
117
-set statusline+=\ │\ %p%%\ of
122
+set statusline+=\ %{b:enc_fmt}
123
+set statusline+=%p%%\ of
118 124
 set statusline+=\ %L\ 
119 125
 
120 126
 " Fast saving
... ...
@@ -282,8 +288,12 @@ if has("autocmd")
282 288
   " ...except for gitcommit where we always want to start at the top
283 289
   autocmd FileType gitcommit exe "normal! gg"
284 290
 
285
-  autocmd BufNewFile,BufReadPost * let b:git_branch = GitBranch()
286
-  autocmd BufEnter * let b:git_branch = GitBranch()
291
+  autocmd BufNewFile,BufReadPost *
292
+  \ let b:git_branch = GitBranch() |
293
+  \ let b:enc_fmt = EncodingAndFormat()
294
+  autocmd BufEnter *
295
+  \ let b:git_branch = GitBranch() |
296
+  \ let b:enc_fmt = EncodingAndFormat()
287 297
 endif
288 298
 
289 299
 " This requires vim to be compiled with +python
... ...
@@ -99,6 +99,13 @@ function! GitBranch()
99 99
   return strlen(l:branchname) > 0 ? '  │ '.l:branchname : ''
100 100
 endfunction
101 101
 
102
+function! EncodingAndFormat()
103
+  if (len(&fileencoding) && &fileencoding != 'utf-8') || &fileformat != 'unix'
104
+    return &fileencoding?&fileencoding:&encoding .'['. &fileformat . '] │ '
105
+  endif
106
+  return ''
107
+endfunction
108
+
102 109
 function! Current_mode()
103 110
   let l:currentmode={
104 111
     \ 'n'  : 'NORMAL',
... ...
@@ -134,9 +141,8 @@ set statusline+=\ %=
134 141
 set statusline+=%h
135 142
 set statusline+=\ %{Trim_brackets(&filetype)}
136 143
 set statusline+=\ %#StatusLineNC#
137
-set statusline+=\ %{&fileencoding?&fileencoding:&encoding}
138
-set statusline+=\[%{&fileformat}\]
139
-set statusline+=\ │\ %p%%\ of
144
+set statusline+=\ %{b:enc_fmt}
145
+set statusline+=%p%%\ of
140 146
 set statusline+=\ %L\ 
141 147
 
142 148
 set encoding=utf-8
... ...
@@ -311,8 +317,12 @@ if has("autocmd")
311 317
   " ...except for gitcommit where we always want to start at the top
312 318
   autocmd FileType gitcommit exe "normal! gg"
313 319
 
314
-  autocmd BufNewFile,BufReadPost * let b:git_branch = GitBranch()
315
-  autocmd BufEnter * let b:git_branch = GitBranch()
320
+  autocmd BufNewFile,BufReadPost *
321
+  \ let b:git_branch = GitBranch() |
322
+  \ let b:enc_fmt = EncodingAndFormat()
323
+  autocmd BufEnter *
324
+  \ let b:git_branch = GitBranch() |
325
+  \ let b:enc_fmt = EncodingAndFormat()
316 326
 endif
317 327
 
318 328
 " This requires vim to be compiled with +python
319 329