If editing a buffer in the right side window when using two vertical split windows in a big display screen, we have to move our eyes all across the screen to the bottom left corner to see any messages Vim is displaying.

This is specially important because many times I need to re-indent the code I've just pasted, so I look at the "X more lines" message to understand how many lines I need to indent.

Is it possible to modify the location of these messages depending in which window the cursor is located?

  • 1
    Oh, the curse of today's gigantic flatscreens! As someone who started with a 40x24 character homecomputer screen, I can only shake my head in disbelief :-) – Ingo Karkat May 21 '15 at 15:54
  • My first home computer had a much bigger screen (640x480 if I recall correctly). But I still miss those awesome VT220 at the university! Still can't go over the image of the pile they created when throwing them out during my last years :'( – Vitor May 21 '15 at 17:21
  • I had a similar situation last week. I ended up using tmux to split the screen and two separate Vim's running, one in each pane. Unfortunately, while you gain status and command locality with this, you lose things like sharing registers or being able to edit the same buffer in both views, for example. – John O'M. May 22 '15 at 2:09

Messages are displayed in the commandline, and there is no way to change the position of the commandline, except for changing the height.

The only workaround I can think of is using the message history (:messages), and putting that in the statusline.

Note that :echo will not put the message in the message history, only :echomsg and :echoerr do, so it won't replicate what you see in the commandline completely.

First, we make a function to get the last message:

fun! LastMessage()
    redir => l:test
        silent messages
    redir end
    return split(l:test, '\n')[-1]

Then, we put that in the statusline with %{, which will eval any expression. Note that the statusline is empty by default, and created internally, so we'll have to "re-create" the default statusline.

For bonus points, I'm also using %1* to make it a different colour (the User1 highlight group) so it stands out a bit more.

set statusline=
let &stl .= '%<%f'                      " Filename, truncate right
let &stl .= ' %h%m%r'                   " [Help] [modified] [read-only]
let &stl .= ' %1*[%{LastMessage()}]%0*' " Show last message from history
highlight User1 ctermbg=0 ctermfg=150 cterm=bold

Here's what it looks like:

enter image description here

Note that the bottom statusline isn't updated. This will be updated once you switch to that window.

My original idea was to put 2 lines in the statusline (and putting the message above or below the default statusline), but as far as I can find out this is also not possible.

  • Give me a day or two to test this around. Still need to adapt that to vim-airline ;) In the meanwhile, I've updated my question to specify the message I'm looking for. Could you confirm this solution still applies? – Vitor May 21 '15 at 17:23
  • @Vitor I'm not sure which "X new lines" message you mean, but almost all messages from Vim should end up in the message history. You can check this by typing :messages and see if it's there :-) – Martin Tournoij May 21 '15 at 17:46
  • the message is "X more lines", my bad! :P But I confirm that they end up in :messages. Thanks! – Vitor May 21 '15 at 19:06
  • Marked as the right answer, since there is no native support for this in Vim. Thanks once again. – Vitor May 21 '15 at 19:17

The command-line will always span the entire width of Vim's application window; it cannot be moved or restricted; you can only influence its height via the 'cmdheight' option.

If you really want to have this, you'd have to modify Vim's source code and recompile; adding static padding should be fairly easy once you've found the right place to do so.

  • Static is probably not enough. It would make sense to shift the message to the column where the current window starts, but only if the message fits in the remainder of the line. But I wouldn't know even where to start looking in vim's code! – Vitor May 21 '15 at 19:16
  • Message display occurs in src/message.c. Look at msg_attr_keep(), which calls msg_strtrunc() (makes the message fit on screen) and msg_outtrans_attr(), which eventually calls msg_puts_attr_len(), which either uses msg_puts_printf() or msg_puts_display(). This last function does fancy stuff with scrolling messages and all that. A cursory glance suggests it might be painful to modify it to display one-liner messages elsewhere, but if you are inclined, that's where I'd start. There is a variable called curwin of type win_T, which has member w_wincol which looks like the screen offset for it. – John O'M. May 22 '15 at 2:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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