When in vim I execute this command :set isprint=1-225 all the non printable characters are condensed/removed. Now how can I save this file or convert the format of this file so that by default this file opens with this format. Or if I upload it to github the non printable characters are condensed?

My question was down-voted on Stack Overflow for not being programming- or development-related, so I thought I’d try adding some more detail here. I couldn't fit this all in the title, but basically I can sum my additions with this line: I am using the script command to log my session, while script command gives a file with lots of 'non-printable' characters, I can condense non-printable characters in vim with :set isprint=1-225 how can I save the file in this format?

Other options that I am aware of and have tried out are writing a perl function to remove control character (best alternative, albeit I have to check to see if all the non-printable characters have been removed), and combination of dos2unix & col -bp commands from the bash prompt.

This looked promising, but before I could try it out I saw that under downloads for Ubuntu it says out of date – should I still try to install it with the .tar.bz2 file?

P.S. In this SO post Kyle Barbour's answer's gets me thinking is there a way to use tr utility to do what set: isprint=1-225 doing from vim command line.

  • 1
    What is your overall goal? (See also "XY problem".) The result of script contains tons of escape sequences that have a meaning to terminal emulators only. E.g. the non-printable ESC followed by the printable characters [31m switch the foreground color to red. Not even script, let alone vim have any clue where such escape sequences end. Hence, by removing non-printable characters only, the resulting file wouldn't make any sense whatsoever. Removing all the escape sequences (including printable characters within) might make a bit more sense, yet is significantly harder. – egmont Sep 23 '17 at 19:35

Setting the 'isprint' option does not modify the file, it only affects how Vim displays the file. You can, however, run a substitute command after setting that option:


Then write the file.

  • thanks, I have tried another perl regular expression from SO as well and with that one some of good code was getting eaten. And with what you proposed the file is not cleaned as neatly as it is with the :set isprint=1-225 option, specifically a line like this one ^[]0;sher@SINGH-PC: ~^G^[[01;32msher@SINGH-PC^[[00m:^[[01;34m~^[[00m$ sudo^H^[[K^H^[[K^H^[[K^H^[[Kexport DISPLAY=:0^M where [ follows ] or another [. How would I tinker with the Regex to achieve that (I would like to learn more about the Regex used here — is it perl? I see /s is for sub but can you expound. thx. – Shér Sep 23 '17 at 19:32
  • [ and ] are printable characters, and are specifically included in the isprint range you set. Regular expressions tend to vary from language to language. For Vim: :help pattern.txt – Heptite Sep 23 '17 at 19:37

[SOLVED] Since I am using tmux, for my purposes I have settled on the using tmux command capture-pane -S <# off lines>.

So after I capture I/O from a session with script command into a xyz.txt file, from the terminal prompt I can issue cat xyz.txt to view the file without non-printable characters. In tmux check how many lines are in my xyz.txt file with copy mode. Finally from tmux command buffer issue the capther-pane -S <# of lines>command and then save it to a file zyx.txt with :save-buffer zyx.txt.

Thanks all.

  • I think you may have a misunderstanding of what "non printable characters" is. It sounds like you were looking for a way to strip escape sequences instead. – Heptite Sep 28 '17 at 16:47

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.