Vim commands in MacVim’s NSMenuItems

January 29th, 2013

I consider myself an intermediate user of Vim. I use it for nearly all of my editing now-a-days, but still have troubles remembering some commands and enjoy learning new ones. The advantage to knowing these is that you can perform many more actions in vim without having to take your fingers off the keyboard. In most versions of GVim they have the menu items showing the equivalent vim command to the right. This is very useful for learning vim. Here’s an example in GVim on Ubuntu.

ubuntuGvim

I  work on a Mac and MacVim doesn’t support these commands entirely. Mostly because MacOS didn’t support custom NSMenuItems until 10.5. So MacVim only shows the keystroke for these commands, not the actual command itself. In order to see the command, you have to mouse over the menu item then wait for the tooltip to show it to you.

before

Since MacOS supports an NSMenuItem with a custom view, I thought I’d try to implement this in MacVim. Each of the menu items now have the vim command as well as the keystroke in MacOS (if it has one).

after

 

I still have some issues with the alignment of a few items. I will probably end up rewriting most of it to use Objective-C categories rather than subclassing NSMenu and NSMenuItem. And I may change the command to use a fixed-width font. But here’s the branch on Github in all it’s gory glory.

https://github.com/gordolio/macvim/tree/custom-nsmenuitems

Highlight and tidy json in vim

August 13th, 2011

If you’ve ever tried to edit or view a json file that’s been generated from JSON or JSON:XS in vim, you know it’s not the easiest thing. Especially when the amount of content gets rather large.

Here’s how you can highlight and tidy json files from within vim.

Highlighting:
Download the json syntax highlighting file from vim.org and place it in your $HOME/.vim/syntax/ directory.

Place the following in your .vimrc file
au BufRead,BufNewFile *.json set filetype=json foldmethod=syntax
au! Syntax json source $HOME/.vim/syntax/json.vim

Tidy:
Install the perl module JSON::XS from cpan (if you don’t have it already)
sudo cpan JSON::XS
place the following in your .vimrc file
au FileType json command -range=% -nargs=* Tidy <line1>,<line2>! json_xs -f json -t json-pretty

Then whenever you need to tidify any json data you’ve opened in vim… just type
:Tidy

Paint it Black

December 11th, 2010

Rolling StonesAt work and at home, I usually keep the lights off.  And sometimes visiting a website can be blinding (especially when you’ve been staring at a black vim session for a few hours)

I searched around and found a bookmarklet that will change any page to straight black on white.  I changed the values to be the opposite: white on black and saved the bookmarklet. Clicking the bookmark while on a page will change the colors to white on black. Now whenever I visit a page that is too bright for my cave dweller eyes, I make like a Rolling Stone and paint it black.

Drag this bookmarklet to your bookmark bar to use it: Paint it Black

Here is the code for it:

javascript: (function(){ var newSS, styles='* { background: black ! important; color: white !important } :link, :link * { color: #0000EE !important } :visited, :visited * { color: #551A8B !important }'; if(document.createStyleSheet) { document.createStyleSheet('javascript:\''+styles+'\''); } else { newSS=document.createElement('link'); newSS.rel='stylesheet'; newSS.href='data:text/css,'+escape(styles); document.getElementsByTagName('head')[0].appendChild(newSS); } } )();

Congrats, you used the bookmarklet to find my super secret text!

Awesome bar.

September 20th, 2009

I’ve been doing some maintenance on my website…  I’ve got it up and running on CentOS4 with cPanel.  But I wanted to add subversion support to it as well.  I found a forum post that gives details on how to set up subversion on a cPanel install, and after working on it for a while I closed my browser and all it’s tabs.

I know it’s a piece of cake to look through the history…  but it’s even more easy to just start typing into the awesome bar in Firefox 3.5 some of the text that was in that page.  I just typed in subversion cpanel and it showed up as the first hit underneath the awesome bar.

Where’s Gordon?

September 4th, 2008

Screenshot of WheresgordonI guess it’s time to blog about this one.  I have made a page on this website that shows my current location.  Anyone can access it.  There is also a little date chooser with the ability to go back and show places I’ve been throughout the day on any particular day (back to the 13th of August).  It’s been a while in the making.  I actually got something working a little less than a month ago but am finally now writing about it.

Here’s how it works:

  1. iPhone gets current latitude/longitude location via GPS satellites orbiting in space.
  2. Location is logged to a file on the iPhone every time I move 5 feet.
  3. Every 5 minutes the log is uploaded to gordonchild.com.
  4. Website writes all locations received to database.
  5. Google Maps magically shows the location and paths on a map.

I’ve been wanting to do this ever since I got the original iPhone, but since it lacked GPS capabilities I never was able to.  I got the new iPhone 3G about a month and a half ago and have been enjoying the GPS goodness that it has.

Additional things I plan on adding:

  • Pinpoints of pictures taken on iPhone at the location it was taken
  • Pinpoints for any location that I spent more than 1 hour at
  • Ability to view path by time of day
  • An estimated-path-taken if path has moved drastically from one location to the next.

Note to all stalkers, mafia, CIA/FBI agents and bigfoot: Chuck Norris is my bodyguard.

Note to all ninjas: You are welcome to come play RockBand at my house anytime.

LDS Scriptures on iPhone

August 1st, 2008

I’ve heard it said that if you don’t like the price on something, just wait for a bit and it will change or something new will come up with a better price.  The only exception to this would be gas, as the price on that keeps getting worse.  :P

ReadScriptures.com is a website that has the LDS Scriptures available for the iPhone and iPod Touch.  They have, since the announcement of the iPhone SDK, promised an offline reader. For a while many people have been looking forward to this offline reader of the scriptures for the iPhone and iPod Touch.  This morning this has been released on the Apple Application Store for $14.99.

To myself, I think that this is a little over priced.  Nonetheless, they have the potential of doing a lot with this application.  They have the potential of improving it tremendously.

In the mean time, I think I’m going to develop a LDS Scriptures reader using Apple’s SDK.  I would make this available for free on the App Store.  It would probably have less features than the one currently on the App Store, but nonetheless would be available as a poor man’s version of the scriptures with the same content.

I’ve told a couple people of my intention to do this.  And they’ve suggested to make it “donationware.”  I’d have to check with Apple’s license to see if I can do this.  But the idea would be to make this available without any required payment.

Update: It appears that someone has already beaten me.  There is a version of the scriptures on the AppStore that is free.  So there’s no reason for me to do this anymore.

Linux for Young Human Beings

June 26th, 2008

This past week my sister has been asking my parents for a computer.  I told them of an old computer that we had sitting in our storage room and that I could build it up as a machine for her.  We had an extra license for Windows XP but I decided that we’d try something new for her.  So I installed a copy of Edubuntu Linux for her computer.  Did I mention that she’s 9 years old?

I really didn’t need to show her anything.  She mostly plays games on the internet and she figured out quickly where the little launch icon is for Firefox.  However, she did call me up asking me how she could write a “rough draft” for a book that she wanted to write.  She didn’t know where Microsoft Word was.  I explained over the phone that there’s this great tool called OpenOffice.org.  I showed her how to get to it and off she goes with it.

I am terribly excited for her.  She’s 1 up’d the rest of my family.  She is the first one out of all of us to use Linux as her sole operating system (including me, I’ve been dual booting MacOS and Ubuntu Linux lately).  I’m gonna be following up with her to make sure that she’s using it.  But so far she really likes it.  She especially likes Compiz.  In her words, it’s “Awwesooome!”

Time Lapse

June 19th, 2008

So I’ve played around a bit with some time lapsing.  It’s really a very fun thing to do.  The following video shows a time lapse that I created during a sunrise while near Yellowstone in Idaho.

I used a program called gphoto to take the pictures.  It only runs on MacOS and Linux.  I haven’t yet seen a port for Windows. As long as you have a camera that gphoto supports, you can have it automatically snap pictures. The minimum amount of time that I was able to snap pictures was 10 seconds. The reason being that the camera had to extent the lens, take the picture, then retract the lens. It would take about 10 seconds for it to do this. But the command that I used in gphoto to do this was the following:

gphoto2 --capture-image

Then I had it on a simple loop from there using a bash script.

After having taken pictures I used mencoder to put them all together into a video. Here’s an example of a command to use for mencoder.

mencoder mf://*.jpg -mf on:fps=25:type=jpeg -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1500:vhq -ofps 25 -o timelapse-25fps.avi

Then from there mencoder takes it and makes an mp4 video of all the pictures. It’s really kind of slick.

New Music…

May 20th, 2008

<img src=\I’ve been getting back into classical music.  It’s been really fun.  Sunday I downloaded two songs off of iTunes.  Both of them are from the 2005 movie Pride and Prejudice.  The songs are Dawn and Mrs. Darcy.  They are both very similar.  I am more familiar with Mrs. Darcy because it is a song that my sister frequently plays.  I like it when she does because I’m drawn to the room where the music is coming from.

Sunday night I set my iTunes to repeat and listened to these two songs over and over again until I went to bed.  I found myself more alive in the morning and was able to wake up faster. The morning went much better, especially for a Monday.

I think it’s really neat the effect that music can have on you.  In addition to this I’ve been listening to various songs by Percy Grainger (I played Children’s March in High School and it still gets stuck in my head!) and Adagio for Strings by Samuel Barber.

General Conference Podcast

April 9th, 2008

President Monson SpeakingA few people in my family have iPods. I have told my mother and my sisters before that they can download General Conference in mp3 format. They are always excited to hear that they can put general conference on their iPods and listen to it wherever. But the big problem is that it’s tedious to go through and click all the links and saving them to iTunes and sync to the iPod just to get them there.

The solution: Create a podcast of General Conference.

After much trial and error and manually editing xml (for shame…), I have managed to create a podcast for the most recent General Conference. Podcasts are very easy to subscribe to. You simply fire up iTunes, go to Advanced >> Subscribe to Podcast… then enter the url of the podcast. The URL is below.

http://www.gordonchild.com/conf/rss.xml

Whoever reads this, feel free to share the URL of this Podcast. It’s too great a thing not to share.

Update: As soon as the titles of the talks and the audio of the Priesthood Session is released I will update the podcast to include these.

Update 04-14-08: I just checked lds.org and it looks like they added podcast feeds for both mp3 and mp4 (video). These are not mine, they’re the official ones. :) Here’s a link:

http://lds.org/conference/sessions/display/0,5239,23-1-851,00.html