Question

Every now and then when using the ack-vim plugin the font in my window will change to all symbols. I've yet to see any pattern to when this happens. Any suggestions on the cause and possible remedy would be appreciated.

screen-fcuk

Was it helpful?

Solution

I've seen that happen when binary content got printed to the terminal. Do your Ack queries potentially include binary files?

A fix might be

:!echo -e '\ec\e(K\e[J'

These ANSI Escape sequences attempt to reset the terminal:

# "ESC c"        - sends reset to the terminal.
# "ESC ( K"      - reloads the screen output mapping table.
# "ESC [ J"      - erases display.

OTHER TIPS

This looks like the typical character set translation enabled by the Shift Out control character; you usually just need to send the Shift In control character to counteract it.

Basically, something is outputting a C-n character (Control-N, U+000E, named Shift Out) which tells your terminal to switch to a different display character set. You should be able to get your terminal to switch back to the normal display character set by sending a C-o (Control-O, U+000F, named Shift In) to it.

If you are in Vim, then you can probably send the C-o with a command like this:

:!printf \\017

You will have to type (or paste) this command “blindly” since (due to the alternate character set) you will probably not be able to read what you are typing. If you are typing it (not pasting), then you can also type C-v C-o (to insert a single, literal C-o) instead of the backslashed octal, if that is easier to remember.

If you find that this problem occurs only sporadically when you use the vim-ack plugin, then perhaps some bit of the text results contains the problematic Shift Out character. You might try searching for the file with a command like this:

 grep -FRl $(printf \\016) .

Once you know the names of the files, then you should be able to use Vim to search for the character (start a search and type C-v C-n to insert a literal C-n). Maybe it is just some garbage that you can clean out, or maybe you can configure your ack-based searches to exclude the problematic files.


You also tagged the question with tmux. I can not tell for sure, but it looks like the top line might be a tmux status line. Since this line is also corrupted it indicates that it your external terminal emulator that has switched character sets, not just one of your tmux panes.

If you send Shift Out or Shift In directly to a tmux pane it will only affect that pane (each pane is emulated independently), so your status like could not have been munged just by a stray Shift Out hitting a single pane.

If you are running inside tmux, then the easiest way to reset the outside terminal is to suspend and resume your tmux client (or detach from and reattach to your session). tmux pretty much resets the outside terminal when it gives up control.

Depending on the situation, you may also have to reset the character set of the tmux pane by sending it a C-o, too (i.e. printf \\017 at a shell, or a :! prompt in Vim).

It is easy to see how a stray Shift Out could reconfigure a single tmux pane, but it is harder to see how it could have “leaked” out to reconfigure the external terminal (tmux is pretty good at isolating things like this). However, there is a control sequence that tmux recognizes that instructs it to pass data directly to the external terminal (thus “leaking out”), but it is much less likely that you would randomly encounter this sequence since it is much longer:

printf '\ePtmux;%s\e\\' 'stuff bound for the external terminal'

You could use it to send the restorative Shift In like this:

printf '\ePtmux;%s\e\\' $(printf \\017)

You will also want to tell tmux to redraw itself after this (by default, the refresh-client command is bound to C-b r).

It is probably easier to just suspend and resume (or detach and reattach), but this sequence is useful if that is not possible. It also provides a means toward understanding what kind of sequence might “leak” out of tmux to switch the character set of the external terminal.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top