Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I show system time in airline? #1373

Closed
himanshub16 opened this issue Jan 16, 2017 · 7 comments
Closed

How can I show system time in airline? #1373

himanshub16 opened this issue Jan 16, 2017 · 7 comments

Comments

@himanshub16
Copy link

I want to add a section for showing system time in airline. Please help me out.

environment

  • vim: 7.4
  • vim-airline: latest git
  • OS: Ubuntu 16.04
  • What is your airline configuration: Nothing. Using the default one
    if you are using terminal:
  • terminal: gnome-terminal
  • $TERM variable: xterm-256color
  • color configuration (:set t_Co?): 256

Thank you.

@chrisbra
Copy link
Member

Something like this: :let g:airline_section_b = '%{strftime("%H:%M")}'

@codersguild
Copy link

That's cool. Was exactly searching for this.

@AniAggarwal
Copy link

AniAggarwal commented Feb 21, 2022

I was trying to do this but for section y. However, it doesn't seem to do anything.

Desired behavior

Display the time instead of the encoding in section y of the status bar.

Actual behavior

Section y continues to display the encoding.

What I've tried

let g:airline_section_y = '%{strftime("%H:%M")}'
This causes no change. Section y still displays only the file encoding.

let g:airline_section_y = airline#section#create(['%{strftime("%H:%M")}', 'fileformat', 'bom', 'eol'])
This also causes no change. Only file encoding displayed.

let g:airline_section_y = airline#section#create(['%{strftime("%H:%M")}', g:airline_section_y])
This gives the following error: Undefined variable: g:airline_section_y

However, let g:airline_section_c = '%{strftime("%H:%M")}' correctly displays the time in section c.

Is it possible some other extension is preventing from changing section y specifically?
Screenshot of current airline:
Screenshot from 2022-02-21 12-40-31

@chrisbra
Copy link
Member

let g:airline_section_y = '%{strftime("%H:%M")}'
let g:airline_section_y = airline#section#create(['%{strftime("%H:%M")}', 'fileformat', 'bom', 'eol'])
let g:airline_section_y = airline#section#create(['%{strftime("%H:%M")}', g:airline_section_y])

That does not make sense. You are createing the same section variable several times with different content. What exactly are you trying to achieve?

@AniAggarwal
Copy link

@chrisbra thanks for the quick response!

I've updated the above comment to be more clear.
Each of those lines were separate attempts I made to change section y to the clock. I didn't run them all at the same time.

@chrisbra
Copy link
Member

okay, I forgot, that section_y will only be visible if at least 88 columns are in the current window.
With this simple vimrc, it totally works:

set nocompatible
set bg=dark
set termguicolors
filetype plugin indent on
syntax enable
let &rtp  = '~/.vim/pack/minpac/start/vim-airline,' . &rtp
let g:airline_section_y = '%{strftime("%H:%M")}'

I recorded a small screen capture:

putty_isrKhRZOi3.mp4

@AniAggarwal
Copy link

I do have >80 columns.
I am using NeoVim and my init.vim is pretty big (and split into multiple different files which I source from within it). I have tried disabling and re-enabling different plugins but can't seem to get it to work.

Maybe Coc is causing some issues?
Let me know what other info I could provide that might help debug this problem.
(if this isn't easily fixable, don't worry about it/waste your time)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants