Sunday, September 22, 2013

Simple Made Complex

What a crash course my learning experience has been over the past few months.  I must admit, my original intentions with this blog were to post frequently but I have been lacking in that to say the least.  I imagine this patterns is consistent with others who have thought. “Hey, I’m going to start a blog about that!” but became much more engulfed in what they were learning or experiencing than the desire to blog about what they were experiencing.  That said, I do have quite a few interesting things that I think are worth sharing, and I hope to start posting about these topics.

Out of everything that has been in a state of flux the absolute biggest change has been… *drum roll please* working primarily in a terminal based environment.  Prior to this job, I'd guess I'd spend less than 5% of my time in some kind of terminal..mainly Windows PoweShell when I needed it.   Now, I'd say that I spend over 80% of my time inside a terminal window.  My team uses VIM as their primary IDE, and tmux for switching between several programs in on terminal .  VIM is a text editor that is built into most UNIX systems.  It’s notorious for having a step learning curve but after you've overcome the learning curve many swear by it.  Here's an example of me hitting the learning curve pretty hard with VIM.

Simple made complex

  1. Now in VIM.. say you want to copy and paste 2 lines of code.  Here’s how you go about doing it.
  2. Ensure that you aren't in insert mode 
  3. Ensure your cursor is on the spot where you'd like to begin selecting the text you'd like to copy.
  4. Hit V to begin character based visual selection.
  5. Move your cursor to the end of the text to be copy.
  6. Hit Y to copy the text.
  7. Move your cursor to where you’d like to paste text
  8. Hit P to paste.

Blamo! Copy paste via vim.  That’s not so hard, right?  Well.. I guess not.  Seemed a bit laborious to learn another way to copy paste.  But in all fairness, VI has been around longer than I have.  Now I need to remember CTRL + C /CTRL +V for windows, Command C/Command V for OSX, and the dance listed above for VIM.

Now let’s say that I need to take the code that i just copied and put it into a bug report.  Unfortunately, by default, VIM doesn't share the the operating system’s buffer… so you need to figure out a way to get that text into a buffer that’s accessible outside that VIM session. You can do things like using the * register to reference the system clipboard, but that doesn't work in every Unix OS.  You can set clipboard=unnamedplus in your .vimrc file but it requires at least vim-7.3.74.  If you are on OSX you can use the command line tool PBCopy.   And...there seems to be 10 more ways to solve this problem.  There are times when I’m really impressed with the things I can do with VIM, and there are other times when it comes to things like this where I grow frustrated that things as simple as copy/paste can be this complicated.  It seems very silly that I actually need to go to google and search for "how to copy paste VIM OSX"  ... but I digress.

You can get by in VIM by using the most basic commands, but it’s real power comes from learning all of the tricks in and tips, installing custom plug-ins, shelling out to the command line within VIM.  Here’s a link to the "best” VIM tips.  I've found reading these to be very helpful, and I've tried to teach myself at least one new trick in VIM everyday.  Once you get beyond these initial learning/growing pains there are some really wonderful things that you can do with VIM.  There are countless tricks in here that i know I couldn't do with my last few IDEs.  The trick is continuing to learn a new thing or two everyday to make that initial learning curve worth it.

No comments:

Post a Comment