Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make vim indicate the file has changed since last save?

Tags:

vim

I used to work with netbeans and it always put an asterisk and changed the tab color when the file had changed since last save. Is there any way to make vim do something similar, that is, remind me that I haven't saved the file?

I know that there is a way to have it save automatically once in a while, but I don't want to do that.

like image 230
user798275 Avatar asked Oct 27 '13 04:10

user798275


2 Answers

You can use the m flag in the 'statusline' option to add a [+] if file is modified. Note that in order to see the statusline, you'll need to set 'laststatus' to be greater than 0 (1-Only shows status line if there are two or more windows, 2-Always).

If you're using a GUI-version, such as MacVim, you may prefer to set 'titlestring', which uses the same syntax but will alter the name of the window in your window-manager.

Example:

:set laststatus=2
:set statusline=[%n]\ %<%f%h%m

This will display:

  • [: literal
  • %n: buffer number
  • ]: literal
  • \<Space>: a space
  • %<: Truncate the field at the beginning if too long
  • %f: Path to the file in the buffer, as typed or relative to current directory.
  • %h: Help buffer flag, text is "[help]".
  • %m: Modified flag, text is "[+]"; "[-]" if 'modifiable' is off.

For more information see:

  • :help status-line
like image 73
Johnsyweb Avatar answered Nov 18 '22 09:11

Johnsyweb


If the terminal displays its title somewhere, it's possible to use

:set title

to display whether the file is modified: a + is displayed after the file name if it's modified.

However, a file can have + at the end of its file name. For most files this should work fine.


Source: https://stackoverflow.com/a/13244715/5267751

like image 27
user202729 Avatar answered Nov 18 '22 11:11

user202729