2

Some time ago I completely got rid of the status line. Vertical space is a scarcity in the modern HD world. The only thing I missed from it is an ability to see what file I'm working with. So I'm looking for a way of displaying it in the command line.

I tried to change the ruler to something like: set rulerformat=%60(%=%f\ %P%). It's essentially works. But when a window is smaller than those 60 characters, the ruler takes all the space. So I can't see error messages, which appears on the left side of the command line. And I couldn't find a way to display left-side content on top of the ruler.

The current way I use - is printing filename after changing a buffer. I'm ok with it being rewritten by a command or an error afterwards:

" Automatically show current file name in the command line
" TODO: after :wq the name is printed in the buffer we're leaving after the
" message about its successful writing
" I've tried: BufEnter, WinEnter, TabEnter
autocmd BufEnter * echo @% =~ '^\/.*$' ? @% : './' . @%

It works almost perfect except of the case of :wq, when filename is printed after the writing message and as there's more than a single line, I'm getting the Press ENTER or type command to continue. It's not critical, but still, a bit annoying.

So my question is if you have any suggestions how to fix one of described approaches or if there's a better one?

1 Answer 1

2

One simple fix is to get your autocmd to clear the "file written" message before echoing:

autocmd BufEnter * redraw | echo @% =~ '^\/.*$' ? @% : './' . @%

You get subtly different behaviour (the redraw is a bit faster) if you add !:

autocmd BufEnter * redraw! | echo @% =~ '^\/.*$' ? @% : './' . @%

The obvious downside to this approach is that you don't get to see the "file written" message, or indeed, any errors. (Although you can probably figure these out from context: if the window didn't close that means there was an error.)

The alternative is instead to suppress your echo when doing a :wq:

augroup InstallPseudoStatus
  autocmd!
  autocmd CursorHold * call s:install_autocmd()
augroup END

function! s:install_autocmd() abort
  augroup PseudoStatus
    autocmd!
    autocmd BufEnter * echo @% =~ '^\/.*$' ? @% : './' . @%
  augroup END
endfunction

cabbrev <expr> wq (getcmdpos() == 3) ? 'augroup PseudoStatus <bar> execute "autocmd!" <bar> augroup END <bar> wq' : 'wq'

This works by installing your autocommand with a CursorHold autocommand, and then removing it again just before performing a wq, by means of a command line abbreviation.

If you don't like the behaviour of CursorHold, you could try CursorMoved instead, or use a timer.

2
  • Thanks, Rich. It works perfectly. I'm just wondering if I can miss some important messages this way?
    – imbolc
    Commented May 6, 2020 at 8:55
  • @imbolc Yes, I think you can. See my edit for an alternative solution that avoids this issue.
    – Rich
    Commented May 6, 2020 at 9:02

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.