Lightline.vim: vim-devicons in tabs

Created on 19 May 2020  路  3Comments  路  Source: itchyny/lightline.vim

Essentially what i'm trying to do is replace the 'tabnum' with the appropriate devicon. I found a couple functions on the vim-devicons site for lightline and the statusbar as shown below for file type and file format

let g:lightline = {
      \ 'component_function': {
      \   'filetype': 'MyFiletype',
      \   'fileformat': 'MyFileformat',
      \ }
      \ }

function! MyFiletype()
  return winwidth(0) > 70 ? (strlen(&filetype) ? &filetype . ' ' . WebDevIconsGetFileTypeSymbol() : 'no ft') : ''
endfunction

function! MyFileformat()
  return winwidth(0) > 70 ? (&fileformat . ' ' . WebDevIconsGetFileFormatSymbol()) : ''
endfunction

So I tried essentially wrapping the MyFiletype function with the WebDevIconsGetFileTypeSymbol() function but that didnt work. I also tried just putting WebDevIconsGetFileTypeSymbol in the tabnum field of my formatting as shown here:

let g:lightline = {
      \ 'colorscheme': 'deus',
      \ 'component_function': {
      \   'filetype': 'MyFiletype',
      \   'fileformat': 'MyFileformat',
      \ },
      \ 'tab_component_function': {
      \   'tabnum': 'WebDevIconsGetFileTypeSymbol',
      \ }
      \ }

This is returning just the default devicon value and not the document value, however when i echo it in command mode it's fine and also the above function for the statusline also works. So I'm just a bit confused. Sorry about my limited knowledge here.

configuration

Most helpful comment

The tab_component_function are evaluated with tab number argument while WebDevIconsGetFileTypeSymbol takes the filename. I don't have the fonts installed but try following sample.

let g:lightline = {
      \ 'tab_component_function': {
      \   'tabnum': 'LightlineWebDevIcons',
      \ },
      \ }

function! LightlineWebDevIcons(n)
  let l:bufnr = tabpagebuflist(a:n)[tabpagewinnr(a:n) - 1]
  return WebDevIconsGetFileTypeSymbol(bufname(l:bufnr))
endfunction

All 3 comments

The tab_component_function are evaluated with tab number argument while WebDevIconsGetFileTypeSymbol takes the filename. I don't have the fonts installed but try following sample.

let g:lightline = {
      \ 'tab_component_function': {
      \   'tabnum': 'LightlineWebDevIcons',
      \ },
      \ }

function! LightlineWebDevIcons(n)
  let l:bufnr = tabpagebuflist(a:n)[tabpagewinnr(a:n) - 1]
  return WebDevIconsGetFileTypeSymbol(bufname(l:bufnr))
endfunction

The tab_component_function are evaluated with tab number argument while WebDevIconsGetFileTypeSymbol takes the filename. I don't have the fonts installed but try following sample.

let g:lightline = {
      \ 'tab_component_function': {
      \   'tabnum': 'LightlineWebDevIcons',
      \ },
      \ }

function! LightlineWebDevIcons(n)
  let l:bufnr = tabpagebuflist(a:n)[tabpagewinnr(a:n) - 1]
  return WebDevIconsGetFileTypeSymbol(bufname(l:bufnr))
endfunction

This worked perfectly, thank you so much! Also thanks to @polyzen for pointing me in the right direction with that other project, I think I might have been able to get that working :)

Here's how it looks now: https://i.imgur.com/YQmbk2L.png

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wimstefan picture wimstefan  路  5Comments

ghost picture ghost  路  3Comments

JIAKanghao picture JIAKanghao  路  4Comments

kiryph picture kiryph  路  3Comments

indiesquidge picture indiesquidge  路  4Comments