Corporal Trim (or James Butler, which is his real name) is Toby's servant and a regular at Shandy Hall. He's irritating, loyal, funny, obtuse, acute, brave, sentimental, and all together a way more complex character than it seems like he ought to be. Let's start with the good and move to the ugly:
Trim is an old-timer who's been with Toby for at least "five-and-twenty" years (6.6.1). Clearly, he's into fortifications just as much as his beloved master. He loves Toby so much that he always stands behind his chair "with the most dutiful respect" (6.6.1), even though he's got a bum knee. Completely sharing Toby's obsession with battle and fortification, he does anything that Toby asks, even swearing that (if he had the money and his brother was dead), he would leave everything to Toby. He puts the Downton Abbey crew to shame.
Trim is the type who watches The Notebook in the dark and bawls. He cries when he thinks about his brother being tortured by the Spanish Inquisition, so much so that "tears trickled down [his] cheeks faster than he could well wipe them away" (2.17.15). He weeps when Toby promises to take care of him—again "tears trickled down his cheeks faster than he could wipe them off" (4.4.3), and then he weeps again when he tells the servants that he would take care of Toby if he could: "Trim could not refrain from tears at this testamentary proof he gave of his affection to his master" (5.10.6), and then he weeps again when Toby praises him: "The corporal blushed down to his fingers' ends—a tear of sentimental bashfulness—another of gratitude to my uncle Toby—and a tear of sorrow for his brother's misfortunes, started into his eye and ran sweetly down his cheek" (9.5.6). Get a handle on yourself, Trim!
So why cry a river? Is it just an act, or is there actually sentiment buried under the pretentious, boastful exterior? One way to figure it out might be to think not about what he says, but about what he does: he treasures the hat that his brother gave him, and goes above and beyond his duty in helping Toby. It seems like there's a deep core of sentiment and sweetness beneath the annoying exterior. Hand him a handkerchief and let him sob over Ryan Gosling.
That's not to say that the guy is perfect. To be specific, he loves the sound of his own voice. To be even more specific, he loves, as Tristram says, "to advise—or rather to hear himself talk" (1.5.9). He won't shut up about his opinions and he talks the ear off of anyone who will listen. You've got to hand it to Trim—he's such a good faker that the cook and the chambermaid both think that he knows every bit as much as Toby does about fortifications.
Trim has a natural gift for giving advice, because he somehow knows just the right attitude for reading and speaking. When he prepares to read a sermon, he stands "bent forwards just so far, as to make an angle of 85 degrees and a half" (2.7.2) which happens to be the exact "true persuasive angle of incidence." But Tristram has no idea how Trim knows this. Is he a genius or a master con artist?
Aside from all his personal characteristics, Trim serves an important function in the narrative: he's Shandy-lite. Just like Mr. Shandy, he likes to pontificate, opinionate, and narrate. He's also Toby-lite: he weeps, builds forts, and is deeply loyal. You get the picture.
The upstairs/ downstairs split is a classic of English fiction (think Downton Abbey). When the rich folk do something upstairs, the servants mimic it or talk about it downstairs. The idea is that there are two different worlds in one house. You can find a similar split in the A plot/ B plot of a lot of TV shows, where the minor plot reflects the theme of the major plot. In Tristram Shandy, the servants are constantly re-enacting and commenting upon the events of the masters, like when Susannah, the scullery maid, the cook, Jonathan, Obadiah, and corporal Trim all talk about Bobby's death in the kitchen (5.10).
So Trim also lets Tristram comment—a little more meanly—on the characteristics that Tristram gives Mr. Shandy and Toby. He's the bad side of Mr. Shandy's convictions and the foolish side of Toby's sentiment. This is another clue that Tristram's book is a lot more than his rambling recollections. Not to give away spoilers, but it's starting to look a lot more like a sophisticated, carefully planned magnum opus.