1

I build my own statusline because I don't need such fancy things inside my statusline as some plug-ins provides. Usually everything is fine. The result looks like the following:

NORMAL   | ~/.config/nvim/lua/statusline.lua | +  | ft:LUA| buf:1| 1/123:23

But if I open a file with a deep nested path, my statusline swallows up my mode section. Like:

<ocal/share/nvim/site/pack/packer/start/zenburn.nvim/lua/zenburn/palette.lua/nvim/lua/statusline.lua | ft:LUA| buf:1| 1/123:23

This happens even if I put a minimal width on my mode section. Here is my function to create the statusline:

local function create_statusline(mapped_mode)
  local statusline_raw = {
    "%#", mapped_mode.hl, "#",
    " %7(", -- Breite des Mode (zusammen 9 Zeichen)
    mapped_mode.text, -- Mode
    "%) ", -- Schließt Mode-Teil
    "%*", -- Stellt eigentliche Highlightgroup wieder her
    " %F", -- Filename + Path
    " |", -- Separator
    " %.5(%M %R%)", -- Modifier +, ro
    "%=", -- rechte Seite
    " :%Y", -- FileType
    " ﬘:%n", -- BufferNr
    " %l/%L:%c", -- Line/line_count:column
  }         )
  return table.concat(statusline_raw)
end

The mapped_mode is a table with the text and a highlight group name as elements. The comments are a mix of German and English.

I think I don't understand the meaning of {minwid}. I hope some of you can help me out to get the mode section all the time in my statusline.

1 Answer 1

0

I think you have a couple of options:

  • use a {maxwid} to limit %F (like %.50F)
  • don't use %F :)

FWIW, in my own statusline I have a "short" and "long" version.

function! s:status_line(verbosity) abort
  set statusline=
  if a:verbosity ==# 'long'
    set statusline+=%([%{Head()}%1*%t%*]%)
  elseif a:verbosity ==# 'short'
    set statusline+=%([%1*%t%*]%)
  endif
  set statusline+=%5*%(%m%r%w%h%)%*
  set statusline+=%(%y[%{&expandtab?'S':'T'}]%)
  set statusline+=%([%{exists('*FugitiveHead')?FugitiveHead():''}]%)
  set statusline+=%([%{get(w:,'quickfix_title','')}]%)
  set statusline+=%=%<
  if a:verbosity ==# 'long'
    set statusline+=%([%3*%l%*/%LL,%3*%c%*,%p%%]%)
    set statusline+=%([%{exists('*wordcount')?wordcount().words.'W':''}]%)
    set statusline+=%([%{&ff}\|%{(&fenc==''?&enc:&fenc).((exists('+bomb')&&&bomb)?'\|bom':'')}]%)
  elseif a:verbosity ==# 'short'
    set statusline+=%([%3*%l,%c%*]%)
  endif
  set statusline+=%(%a%)
  set statusline+=%4*%([%{AleCountTotal()}]%)%*
  set statusline+=%(%{exists('*ObsessionStatus')?ObsessionStatus():''}%)
endfunction

command SLLong call s:status_line('long')
command SLShort call s:status_line('short')

SLShort

You can ignore some of the functions. The interesting bit is that with long mode I show the full path, with the head and tail highlighted differently. In short mode I only show the tail (%t). I mostly use short mode and press Ctrl+g when I want to see the full path.

2
  • Thank you for your reply. I had the idea to limit the length of the file name by maxwid yesterday. I thought that this option was a little cheap but it works very well. I have to say that the solution with a long respectively short statusline is very tempting.
    – grrr
    Feb 12 at 22:51
  • @grrr best say "thank you" with votes (though I'm consistently shocked that's a 15-rep privilege… here, have an upvote :) )
    – D. Ben Knoble
    Feb 13 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.