Changing vim's status line's "file modified" flag to be more noticeable
Asked Answered
D

3

8

I do this all the time:

Edit a file, go back to the terminal and execute the script I'm writing… only to realize that I haven't written it to disk yet.

How do I make it so that vim is basically shouting at my eyes whenever the file is unwritten? That tiny [+] isn't good enough. Ideally, I'd like to either increase the number of red plusses being shown, or something more drastic.

FOR INSTANCE, I'm using powerline (purely in an attempt to get a more noticeable 'file has been modified' notifier). I think it'd be pretty great if the main colour at the bottom of the bar changed whenever the file has not been saved.

Any ideas?

Dillman answered 26/9, 2012 at 21:41 Comment(0)
J
7

You can set vim to display the file modified flag 5 times if you want.

set statusline+=%m

This adds it one time. Increase the number of "%m" to whatever number you want. Further explanations and tricks here: http://got-ravings.blogspot.co.at/2008/08/vim-pr0n-making-statuslines-that-own.html

Janijania answered 26/9, 2012 at 21:51 Comment(1)
Deep inside that blog post they show you how to set custom highlights on custom regions.Dillman
K
4

I have written the StatusLineHighlight plugin for that. It changes the color of the statusline to red (customizable) for modified buffers.

It won't work together with Powerline or other fancy statusline modifications, though.

Kktp answered 26/9, 2012 at 21:55 Comment(0)
O
2

It is not the answer to the question you asked, but why don’t you just do

set autowrite

to make the problem you mentioned (“go back to the terminal and execute the script I'm writing… only to realize that I haven't written it to disk yet”) go away: this option makes vim save changes you did when you suspend it (note: not when you use :shell to spawn a new shell).

For powerline the only thing you can do easily is to edit colorscheme to make more noticeable highlighting: copy autoload/Powerline/Colorschemes/default.vim to ~/.vim/autoload/Powerline/Colorschemes/my.vim, find Pl#Hi#Segments(['fileinfo.flags' and in each line add the second color (background one): transform ['brightestred', ['bold']] to ['white', 'brightestred', ['bold']] and so on. Then add

let g:Powerline_colorscheme='my'

to the vimrc and run :PowerlineClearCache.

Ourself answered 27/9, 2012 at 15:19 Comment(3)
Ah, but I like everything to be explicit, so autowrite is out. I tried your suggestions - the most comprehensive and on point - but it didn't make a huge difference. It's very annoying how there doesn't seem to be a straightforward way to modify the segment - or rather, that I can't seem to figure out how Powerline works. Thanks a lot for your response.Dillman
@Dillman This segment is defined in autoload/Powerline/Segments.vim, you can increase the number of %M there. But you then need to use git and have it care about your changes, it is not a thing you can copy to ~/.vim and expect Powerline to work after next update (unless you copy the default theme as well). It also may conflict with a maximum number of statusline items (up to 80, but powerline uses a lot of them. AFAIR I heard that default theme does use all 80 items if all required plugins are installed, not sure whether it is true: on my system there are only 29 of them).Ourself
With the modified colorscheme, adding a bunch of spaces in that segment kind of did the job, so I switched back to powerline. THIS IS SORT OF WHAT I WANTED, thanks! It kind of messes up with my other segments if the window is at a reduced size, but I don't really need to know the filetype and encoding at all times. Powerline is all kinds of vimscript voodoo; I can't even figure out how to reorder the segments.Dillman

© 2022 - 2024 — McMap. All rights reserved.