Tag Archives: vim

Small Vim Shortcut for PHP Tags

The short tags in PHP have been deprecated as of 5.3.0. Short tags provided a shorter alternative to the annoying-to-type <?php and <?php echo. Instead, you could use <? and <?= respectively. This was great but it caused problems when working with XML files, and the short_tags option was disabled in the PHP config by default on some implementations.

To make life easier, I created this vim mapping that will expand <? to <?php and <?? to <?php echo. You may change the abbreviation as you see fit. Simply place this in your .vimrc

inoremap <??    <?php echo  ?><Left><Left><Left>
inoremap <?     <?php  ?><Left><Left><Left>

Re-open vim or type use :source ~/.vimrc to reload the config. Now just type <? or <?? in insert mode.

I Can’t Live Without My vim Config

I have updated the vim page with my vimrc/gvimrc configs. Instead of repeating myself, I will quote some parts of the page ..

More details and the vim config itself here

I recommend turning backups on if you have them off. I personally hate having the ~ files all over my OS, so I keep them along with the .swp files in 1 backup dir in ~/.vim/

The programming language skeleton stuff will detect what files you are editing and change options in vim by inheriting the specified files which I put in ~/.vim/skeletons and ~/.vim/inherit.

The skeletons are automatically inserted in new files that vim is aware of. For example, in my own config, I have ~/.vim/inherit/c which has all the usual includes and int main() code. When I make a new C file (“gvim hello.c”), the new file begins with the skeleton code already present. Neat huh?

The inherit files can be used to set specific options for each language. This can mean different bindings, whitespace options, themes, etc depending on what language you’re working with, automatically.

See the vim page

What options have helped you the most?

Top 5 Linux Apps That’ll Boost Your Productivity

These are not in any specific order. Also, some might be available on other operating systems.

Tomboy

This is the best note taking app I’ve ever used. It sits in your taskbar, doesn’t annoy you and doesn’t hog your cpu cycles or memory. When you wanna jot down something, hit a global shortcut, type away, and then close. Notes are saved as you type, and it automatically links notes together if you use CamelCase words. It’s written in C#, and still pretty young, but I’ve never had a problem with it in regard to stability or compatibility.

If your distro’s repository doesn’t have a package for the latest version (0.12.0, I highly recommend downloading a newer binary and/or install from trunk/)

Official site: http://www.gnome.org/projects/tomboy/
Subversion: http://svn.gnome.org/viewvc/tomboy/trunk/


Tilda and friends


You know those slide-down consoles in FPS games like Quake, UT, Half-Life, that you invoke by hitting tilde (~), and use to enter your leet r_picmip hacks? Tilda is a Quake style drop-down terminal that gives you the same quick access to your Linux console on any workspace. No more opening a new terminal window for every little task.

Official site: http://sourceforge.net/projects/tilda/

Tilda isn’t the only app of its kind. It’s not even the first. Check out the alternatives as well:
sjterm (“works well with Compiz”): https://gna.org/projects/stjerm/ (alt page)
Yet Another Kuake (Yakuake, for KDE): http://yakuake.uv.ro/
Kuake: http://www.nemohackers.org/kuake.php
Visor (OS X): http://docs.blacktree.com/visor/visor


RescueTime

RescueTime is a little program you download (Mac, Windows, Linux) that sits in the background and checks what windows/apps have focus, and uses this data to compile statistics about your computer habits and productivity. It creates neat graphs and shows how productive you are compared to others within a certain time frame.

The commercial versions have some great team features but the free one is enough to track your own productivity. If you’re paranoid, run it through a proxy or chew some Alprazolam or Zyprexa. It’s worth it.

An app sorta like this was an idea I had but never implemented. It was one of those wake up in the middle of the night with an epiphany, scramble to find a pen and paper to jot it down before it’s gone forever idea, that you then wake up and either find silly or just toss in the idea bin never to be thought of again. The idea stemmed from wanting to create a chart of how I spend my time and compare myself week by week. My proposed implementation was a lot simpler though. I was thinking about having it only track apps that you specify.

This differs from RT which has a gigantic db of categorized apps and lets you choose categories to tag as productive or not (i.e., rhythmbox and mplayer would go under audio/video) I like RT’s implementation.

Official Site: http://rescuetime.com/
Unofficial Linux client (works great): https://launchpad.net/rescuetime-linux-uploader


Screen


Screen is something you find on everybody’s list of Top/Fav Linux apps. If you use the console a lot, especially remotely, screen is a must have.

It keeps a persistent console session open, and lets you attach and detach from it anytime you want, which is great if you get disconnected while working over a network, or when you want to continue what you’re doing at home from work or while on the road. It also has neat features like split screen, tabbed consoles, etc.

When you first run it, you might not notice anything different, but you’re actually in a screen session. Press CTRL+a, followed by ‘?‘ to see a list of shortcuts. Tilda + screen = hacks.

Note: The CTRL+a keystroke is part of many of screen’s shortcuts. Unfortunately, it’s a shortcut in Bash that I frequently use (lets you jump to the beginning of the line), so this is annoying to me. There are ways around this but I’ve just gotten used to the workaround. To jump to the beginning of the line in screen, press CTRL+a, a

Official site: http://www.gnu.org/software/screen/

You might have it installed. If not:

sudo apt-get install screen

Also check out screenie, a wrapper for screen:

sudo apt-get install screenie


Google Calendar Prism


Digital calendars are either too lean (lack features), or are too bloated to keep open. I don’t need the email features that come with some of them, and hate the fact that they’re written in Java.

I tried a number of apps before trying web apps, and now use Google Calendar. It’s secure, fast and you can see your life anywhere. One nice feature is being able to add to or edit the calendar from your PDA or using text messages. I was initially weary of putting my calendar online, but the benefits outweigh the cons (paranoia).

Going back to desktop apps. The only decent one I’ve tried was Rainlendar, but it’s broken on Linux and it’s closed source. Besides, I only liked it because it was simple but synced with Google Cal. At the time, the only alternative I considered was keeping a tab open with Google Calendar, which I wasn’t going to do because Firefox needs to be xkill’d every few days. Then it hit me; Mozilla Prism!

Prism is (basically) a stripped down web browser that is meant to help integrate web apps onto your desktop. prism-google-calendar is a packaged Mozilla Prism setup with Google Calendar out of the box.

It runs independent of your browser and can be treated as a webApp. And since it has its own memory space, it doesn’t go sluggish with Firefox and never needs to be restarted.

I keep it open fullscreen on my second monitor, and can glance at it anytime I feel lost in life.

The only thing missing is a decent alarm feature. Javascript alert()s are shit, and I don’t want annoying emails about my events. I suppose there are hacks around the problem but I learned to glance at the calendar often and don’t need reminders so much anymore.

sudo apt-get install prism-google-calendar



Easily Installing Vim 7.2 From Source

Vim 7.2 beta was released last month, and 7.2 is now stable. First check to see if your distro offers a package, and if not, follow these simple instructions on how to install it from source, from the vim7.2 subversion branch.

cd /tmp/
svn co https://vim.svn.sourceforge.net/svnroot/vim/branches/vim7.2
cd vim7.2/
./configure --with-features=huge --enable-gui=gnome2 --enable-cscope --enable-pythoninterp
make

Now you can use sudo make install and you’re done,…but

I suggest using checkinstall (sudo apt-get install checkinstall) to keep track of the installed files, create a package, and have the option of easily removing whatever you installed easily (i.e., dpkg -r vim7.2).

sudo checkinstall -D

If the above command doesn’t work, you aren’t alone. It recently began giving me these errors:

cp vim /usr/local/bin/vim
chmod 755 /usr/local/bin/vim: setting permissions for `/usr/local/bin/vim': No such file or directory
make[1]: Leaving directory
… etc …
**** Installation failed. Aborting package creation.

I dug up some info about the problem, along with a solution:

There seems to be a bug in the filesystem translation code which has been
biting people using newer versions of glibc found in most recent linux
distributions. It is being worked on. If you find weird install errors
when running checkinstall but your software installs fine without
checkinstall then you can work around the bug by disabling the fs
translation code and forcing checkinstall to install the package. Use the
–fstrans=no and –install=yes command line options:

checkinstall <options> –fstrans=no –install=yes <install_command>

Source: http://oclug.on.ca/archives/oclug/2004-May/038916.html

From the man page:

–install Toggle installation of the created package.
–fstrans Enable/disable filesystem translation. Filesystem translation
enabled causes the install to proceed in a  temporary  directory, thus not actually touching your system.

sudo checkinstall --fstrans=no --install=yes

You can also have checkinstall create a package by passing in one of these flags:

–type  Choose packaging system. Can be one of ’slackware’,  ’debian’ or ’rpm’.
-D        Create a Debian package.
-R        Create a RPM package.
-S        Create a Slackware Package.

For example, to create a Debian package, I would do this:

sudo checkinstall --fstrans=no --install=yes -D:

Done. The new package has been installed and saved to
/home/mr.Gvim/vim7.2/vim7.2_20080824_amd64.deb

To see the changes from 7.1, use :help version-7.2

Has vim/rails.vim been crashing lately? Here’s why.

If you are experiencing segmentation faults with vim and rails.vim, it may be due to this bug, which appeared after 1.7.127, but has been resolved in 1.7.147 (patch log).

To check if your installation has this bug, type the following (cred goes to Ralph) in vim: :r ~fo<tab> (’fo’ being the start of a username present on the system, i.e., fo for foo, or kirb for kirby). This does not require having rails.vim installed.

You can check whether your distro has updated vim, or install vim from source (see this post on how to do that).

Using Vim as a Complete Ruby on Rails IDE

vi traced with an optical mouse

NOTE: If you are experiencing segmentation faults with vim and rails.vim, see this post.

When coding in Ruby on Rails, you’ll usually be switching between files and running scripts a lot. It can be time-consuming and frustrating coding Rails using a traditional text editor designed for working on big files individually. Vim lets you hop around within a file with enough speed to activate the cosmic treadmill – but without a plethora of hacks and custom key mappings, it’s weak as a Rails IDE. Fortunately, for those of us who are reluctant to kick the vim habit, Tim Pope comes to the rescue with rails.vim; A plugin that makes working with Rails in vim painless and efficient. In this guide, I will explain how to install and use rails.vim, along with a few other plugins you’ll find useful when writing Rails applications.
Continue reading Using Vim as a Complete Ruby on Rails IDE