How to show time in status bar after i write in vim?

Whenever I write to vim at the bottom of the screen, it gives some information about the record, such as the file name and the recorded amount. I would also like to include recording time in this information. I often find that I am editing the file, and then forget whether I wrote the recording or not. I would also like time to be compared there when the last time I wrote a specific file compared to other files that I am working on. Anyone have any suggestions on how to do this?

Thanks!

+4
source share
2 answers

Look at the 'statusline' parameter. This allows you to fully customize what is displayed on the status bar.

 :help 'statusline' 

You can either create a function that creates the entire status bar, or use %{} to make it part of the result of the function.

 %{strftime('%c',getftime(expand('%')))} 

should indicate the "modification time" of the current file.

It would be better to stick with this in a function, since you can check if the current file exists before receiving the time (which would be more reliable). I will leave this as an exercise for you to read the help for the status line and decide what else you want there. Try a few things and see how you deal!

  :help function-list :help strftime() :help getftime() :help expand() :help :function 
+4
source

So, I realized that I eventually got thanks to the main directions of Al:

 :hi User1 term=NONE cterm=NONE ctermfg=Magenta ctermbg=Black :set laststatus=2 :set statusline=%1*%F%h%m%w\ [Time:\ %{strftime(\"%H:%M\")}]\ [Mod\ Time:\ %{strftime(\"%H:%M:%S\",getftime(expand(\"\%\%\")))}]%=\ [%p%%]\ [%l/%L] 

Description:

 :hi User1 term=NONE cterm=NONE ctermfg=Magenta ctermbg=Black 

This command sets the background color of the user1 profile to black and the word color to Magenta. We make the status line equal to this profile so that we can change the color of our status bar.

 :set laststatus=2 

This command makes the status bar constantly visible by placing two lines at the bottom of the vim command.

 :set statusline=%1*%F%h%m\ [Time:\ %{strftime(\"%H:%M\")}]\ [Mod\ Time:\ %{strftime(\"%H:%M:%S\",getftime(expand(\"\%\%\")))}]%=\ [%p%%]\ [%l/%L] 

This is a command that actually shows what will be in the status bar. In this command, we use several functions (e.g. strftime, expand ...) that are specific to vim. We also use% (letter) to denote specific vim variables. The rest of the text simply prints what you write on the screen using \, and then a space after the space is represented. Now describe the specific variables.

  • %1* - this var corresponds to the color that we made in the first command, this sets the status bar equal to these colors
  • %F%h%m says that the full file name, help file flag, and changed flag are displayed
  • [Time:\ %{strftime(\"%H:%M\")}]\ says display [Time: (current time)] and displays it in hours and minutes. If you need a different time format, for example, perhaps include a year or do something: help strftime.
  • [Mod\ Time:\ %{strftime(\"%H:%M:%S\",getftime(expand(\"\%\%\")))}] says display [Mod Time: (mod time) ]. Its hours: minutes: seconds.
  • %=\ [%p%%]\ [%l/%L] indicates the right alignment and shows the percentage of the skipped file and [(current line num) / (maximum line num)].
+3
source

Source: https://habr.com/ru/post/1340042/


All Articles