Intellij IDEA and Linux: Not Like Peanut Butter and Chocolate

I love me some Intellij and I love me some Linux. Unfortunately, they don't play too well together. Lots of keyboard shortcuts do operating system commands.

For instance, CTRL+ALT+L reformats your code in Intellij but it never gets a chance to that because that keyboard sequence locks the desktop on Ubuntu. Besides changing quite a few keyboard shortcuts in the administration screen, does anyone have any tips or tricks?

Add a comment
Category: editor Tags:

Editing Huge Amounts of Files Easily

Where I work, we have tons of static html files that are published using our custom built Content Management System. Sometimes, we have to change a single line on every single page. For example, the latest case involved a change involving the size of ads that were on the pages. Rather than use publishing and database resources just to make this relatively simple change, I use the power of the shell. Specifically, I use find, sed and a shell script that I wrote. It's based on a shell script in the Unix Power Tools book.

First off, we need to find all the files. I usually accomplish this with something simple like

$ find /www -type f -name "*.html" -print

This simply finds that end with .html in the /www directory. You can do more complex things with find like find all files modified in the last 2 days by Frank if you needed to change files like that.

The results of this will be passed off to a file named located in my ~/bin directory. is reproduced here:

echo -n "editing $1: "
if test "$1" = sedscr; then
    echo -n "Not editing sedscript!"
elif test -s $1; then
         sed -f sedscr $1 > $temp
    if test -s "$temp"; then
        if cmp -s "$1" $temp; then
            echo -n "FILE NOT CHANGED: "
            # save original, just in case
            # mv $1 $1.bak
            cp $temp "$1"
        echo -n "done"
        echo -n "Sed produced an empty file \
- check your sedscript".
rm -f $temp

So, the command we would run would now look like this:

$ find /www -type f \
      -name "*.html" \
      -exec ~/bin/ {} \;

This does the same as above but passes each file found by the find command above to the ~/bin/ script.

You'll notice that the file calls sed using a file named sedscr. The next step is creating the sedscr file.

The sedscr files simple contains sed commands. It must exist in the same directory that you call the find command above from. Here's a sample sedscr that just does a simple replace.


You can enter in as many complex sed commands as you want. It's sed so the power is there!

This simply replaces all instances of BigHonkingAd with NiceSmallAd in each of your files found by the find command. The nice thing about the script is that it will not edit the file if the contents of your sedscr don't produce an altered file. Also, if you want the to make a backup of your original file, just uncomment the mv line.

Using this methodology, I'm able to edit about 5000 files a minute. It could probably be faster if I used xargs and the output of is a little verbose but this solution has worked for me for years and if it ain't broke, why fix it?

Add a comment
Category: programming Tags:

Vim Tip: Select Column

Columns in vim

How many times have you wanted to replace a column of text with something. With vim it's easy. Just use CTRL-V to select a column using a visual block.

Once it's selected, you can do a search and replace, yank, cut and other actions. For example, here's the keystrokes to change a column.

  • Put cursor and beginning of text to select
  • Press CTRL-V to begin select of the column
  • When you reach the end of your select, type 'c'
  • Type the new text. Note that this will only replace the first instance.
  • Now hit <ESC><ESC>. All the text has been changed!

The same thing works with plain old 'v' (select character by character) and SHIFT-V (select by line).

Happy vimming!

Add a comment
Category: editor Tags:

Just Cuz'

OK, I've decided that the next programming langauge I learn is Lisp. I just love all the parenthesis I guess. An excellent Lisp tutorial is Peter Siebel's book Practical Common Lisp.

Fun stuff.

Add a comment
Category: personal Tags:

Command Line Fun

If you use the command line in bash, you should check out the CDPATH environment variable. It'll make your life tons easier.

From the bash man pages, CDPATH is defined as:

The search path for the cd command. This is a colon-separated list of directories in which the shell looks for destination directories specified by the cd command. A sample value is “.:\~:/usr”.

In my .bashrc, I've got the following defined: CDPATH='.:..:../..:~/projects'

This allows me to just type cd app when I want to go to ~/projects/app. Another great part of it is that if I am in /var/log and want to go to /var/www I only need to type cd www. The .. in the CDPATH takes care of finding it.

The important part of it is the first one. The single period allows for cd to work normally and find directories in your current directory.

Add a comment
Category: shell Tags:

Ten Keyboard Shortcuts for IntelliJ IDEA

IntellJ Shortcuts

For my day job I use Java quite a bit. And to edit I use IntelliJ IDEA. I used to use Eclipse but work paid for an IntelliJ IDEA license and I've become hooked. The refactorings and clean interface are a boon to my productivity.

Well this post isn't an IntelliJ IDEA fanboy post so let's get back on track. Here's a list of shortcuts that I find most helpful for use with IntelliJ IDEA. Note that these aren't the obvious ones (like Alt-Space for code completion). These are some hidden ones that you might not know about it.

Comment out the selected lines with //.
Copy the current line and paste it.
Delete the current line.
Delete to word end from cursor.
Delete to word start from cursor.
Select the current word. Press it again and it selects more of the code block.
Run the configuration
Debug the configuration
Find usages of the current word
Bring up the Live Template context menu. If you don't know about Live Templates, you can save major keystrokes by defining them.

For a complete list of keyboard shortcuts for IntelliJ IDEA, there's a PDF issued by JetBrains floating around.

Add a comment
Category: editor Tags:

Linux Cut and Paste

Linux logo

Since I'm in the process of switching to Ubuntu I've been hunting down tips and tricks. One great resource is the Ubuntu Blog. Today they had a great tip for copying and pasting in GNOME.

Basically, what you do is highlight the text in one application (for example Firefox), switch to another application and then click the middle mouse button where you want the text to show up. Your highlighted text is now exactly where you want it. If you don't feel like using the mouse, you can use Shift+Insert in the second application to paste the text.

Add a comment
Category: shell Tags:

Cygwin And SSH Tip

cygwin logo

Auto completion for ssh under cygwin was driving me nuts. It wasn't parsing the ~/.ssh/known_hosts file like it should have and using those values to auto-complete. Investigating, (by using ssh -v) I found out that my known_hosts didn't exist in ${HOME}/.ssh and ssh was using the one in C:/Documents and Settings/smason/.ssh. Uh, excuse me? My $HOME is /home/smason. I cd ~ and I'm in /home/smason. Bafflement ensued.

Turns out my /etc/passwd was all mucked up. It had my HOME directory set to the one in my Documents and Settings directory. I manually edited my /etc/passwd and now ssh auto completion works.

Wow, the second post in a row dealing with auto completion. I guess I really like auto-completion. Think of the keystrokes I'm saving you!

Add a comment
Category: shell Tags:

.bashrc Fun With Subversion

Do you use Subversion a lot from the command line in bash? Then this tip is for you.

Add the following to your .bashrc

# svn completion
_svn ()
    local cur prev
    if [ $COMP_CWORD -eq 1 ] || [ "${prev:0:1}" = "-" ]; then
        COMPREPLY=( $( compgen -W 'add blame cat checkout cleanup \
        commit copy delete diff export help import info list lock \
        log merge mkdir move propdel propedit propget proplist \
        propset resolved revert status switch unlock update' $cur ))
        COMPREPLY=( $( compgen -f $cur ))
    return 0
ccomplete -F _svn -o default -X '@(*/.svn|.svn)' svn

Save your .bashrc, source it (using source .bashrc) and now Subversion commands will complete. For example, enter svn upd press the Tab key and you'll get svn update.

Think of all the keystrokes you'll be saving.

Update: I just found Subversion's own bash completion script which has a ton more options. Mine is easier to maintain. :)

Add a comment
Category: shell Tags:

Got Ugly SQL?

SQL Formatter screen shot

Sometimes you have a bunch of SQL statements that are very long, very verbose and very unreadable. Would you spend minutes of your time to format the SQL in strings so that it's readable? Would you paste the ugly SQL in your source code letting some future maintainer try and decipher it? Well, I'm about to save you a metric ton of time as well as your reputation with maintainers of your code. Use SQL Formatter and it'll do all the grunt work for you.

It's bloody easy to use. Just Accept the usage agreement, paste in your offending SQL statement and choose the formatting and output you want. Bingo! Nicely formatted SQL. You can even choose to format it as a string in the language of your choice so you can just copy and paste it into your source.

If you don't feel comfortable using an online tool, there's a desktop version that's postcardware.

Give it a whirl!

Add a comment
Category: programming Tags:

© Seth Mason 2014

Themed using aboutwilson

Powered by Pelican