summaryrefslogtreecommitdiff
path: root/src/Digraphs.ascii
blob: 0a3d11611e703539ea4020f61e80102e868a0fc4 (plain)
    1 Digraphs
    2 ========
    3 :author: Aaron Ball
    4 :email: nullspoon@iohq.net
    5 
    6 Wikipedia defines digraphs (and trigraphs) as 
    7 
    8 [quote, Wikipedia, 'http://en.wikipedia.org/wiki/Digraph_%28computing%29[Digraphs and trigraphs]']
    9 ____
   10 sequences of two and three characters
   11 respectively, appearing in source code, which a programming language
   12 specification requires an implementation of that language to treat as if they
   13 were one other character.
   14 ____
   15 
   16 
   17 If you've spent much time in Unix, you have likely seen their character
   18 representations on a rare occasion. Usually they begin with a ^ followed by
   19 some key code. Note though that I said "spent much time in _Unix_ though. This
   20 is because Linux doesn't _usually_ (with some exceptions) have problems with
   21 digraphs. When I say Unix though, I am referring to the really old ones that
   22 claim to be up-to-date like AIX, Solaris, and HPUX.
   23 
   24 
   25 [[what-do-digraphs-have-to-do-with-old-unix]]
   26 == What do digraphs have to do with old Unix?
   27 
   28 Digraphs are actually used every time you use a Unix/Linux box from the
   29 command line. There's this realy nifty thing called *stty* that flies
   30 under the radar most if not all of the time on newer systems. I don't
   31 know of a single Linux distro that doesn't set stty for you. The reason
   32 it flies under the radar so often is because it's something that's been
   33 standardized for so long that it is all but set in stone (as far as I
   34 know). It's also super handy to have set, and super infuriating to not
   35 have set.
   36 
   37 
   38 [[what-is-stty]]
   39 === What is stty?
   40 
   41 Well, technically STTY is an acronym for "**S**et **TTY**". That's tons of help
   42 though. What's TTY? It turns out that
   43 http://en.wikipedia.org/wiki/Tty_%28Unix%29[TTY] is an acronym for
   44 **T**ele**TY**pewriter. Combining all that goodness, we have **S**et
   45 **T**ele**TY**pewriter.
   46 
   47 Now, all this is great, but really, what does this have to do with anything? It
   48 turns out that while we nearly never need to directly deal with it, we actually
   49 use it all the time. Here's a short list of a few things we use it for in
   50 *nix...
   51 
   52 * Backspace
   53 * Scrolling with a mouse in a terminal
   54 * Ctrl+C (sigterm)
   55 * Ctrl+D (logout/eof)
   56 * All arrow keys, both horizontal and vertical
   57 
   58 I mentioned earlier that stty is set by default on nearly all modern Linux and
   59 Unix distributions with the exception of old Unix distributions such as AIX,
   60 Solaris, and HPUX. I posed this question to a few AIX admins I know and all of
   61 them told me that IBM doesn't set stty for you by default because it's more
   62 customizable than Linux, therefore better. I have my own very charged opinion
   63 as to why they don't set a default, but I will leave that out of this post.
   64 
   65 
   66 [[what-does-stty-look-like]]
   67 == What does stty look like?
   68 
   69 Where I work, management is endeavoring to make their Linux environment as much
   70 like AIX as possible. One step in that process is to merge the .profile
   71 configurations. Since Linux doesn't have stty set in .profile because the
   72 system has a default, AIX using a Linux .profile doesn't support the
   73 afforementioned list of modern keyboard keys (backspace?  really? no). Imagine
   74 how infuriating command line can get without arrow keys for cursor movement, a
   75 backspace to correct your mistakes, and Ctrl+C to clear your line or stop your
   76 process. The only option we have here is to re-set the Linux stty so when the
   77 profile is sent over to an AIX system, it also has stty set on login. Here's my
   78 attempt at porting my Arch Linux stty to aix.
   79 
   80 ----
   81 stty erase ^? kill ^U intr ^C eof ^D quit ^\ start ^Q stop ^S susp ^Z rprnt ^R werase ^W lnext ^V flush ^O time 0 -parenb -parodd cs8 -hupcl -cstopb cread -clocal -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
   82 ----
   83 
   84 
   85 [[what-does-all-that-do]]
   86 == What does all that do?
   87 
   88 I really only want to cover a few things in that list because they are the most
   89 frequently used and caused me trouble when I was trying to set this up.
   90 
   91 Each of those items up there starting with a
   92 https://en.wikipedia.org/wiki/Caret#Circumflex_accent[\^ (Circumflex Accent)]
   93 represents a control key combination. For instance, +eof \^D+ will send the
   94 logout signal upon pressing Ctrl+D. The problem here is that those "circumflex
   95 accents" aren't caret characters. A circumflex accent is its own character. How
   96 do we do these in vi/vim?  You need another control key combination to tell
   97 vi/vim that you are going to be pressing a control key combination of course!
   98 
   99 To do, for instance, the Ctrl+D sequence in vim, go into insert mode and type
  100 +Ctrl+v Ctrl+d+ (the d is not capitalized) and you should see +\^d+ show up.
  101 
  102 I did have two problems with this method though: \^S and \^Q. It turns out that
  103 those aren't Ctrl+S and Ctrl+Q. Since I didn't know those, I elected to use the
  104 actual digraph instead of the character version to set them. To do this, go
  105 into insert mode again and hit +Ctrl\+k+ and type the digraph. In the
  106 case of \^Q and \^S, these are D1 and D3, respectively.
  107 
  108 
  109 Category:Linux
  110 Category:Vim
  111 Category:Unix
  112 
  113 
  114 // vim: set syntax=asciidoc:

Generated by cgit