Handmade Hero»Forums»Code
10 posts
Gedit - editor setup
I recently started following this project on Linux (using lovely SDL port guide by David Gow). In past few weeks I tried out bunch of code editors for Linux and none of them felt really right to me (although I'm willing to give Atom another try). They either missed some functionality I wanted, or setting them up was rather bothersome, or their learning curve looked kinda like Mount Everest (I'm looking at you Vim and Emacs). So I thought: "Why not try gedit?" The standard text editor that comes with installation of Ubuntu (and probably some other distros as well). And surprisingly... it's not that bad.

You can change most settings from window menu -> Edit -> Preferences. Lot of stuff there is up to your personal preferences (like whether to show line numbers or what color scheme to use), so I won't got into much detail on how I set it up. I think you would want to turn on the Enable automatic indentation from the Editor tab, so that you don't have to indent every line by hand.

You can also enable and disable plugins from Plugins tab. Here I would enable External tools plugin (which allows you to execute scripts and bind them to keyboard shortcuts), if you want to be able to build directly from editor, the way I'm doing it. Additional "official" plugins can be also installed by downloading gedit-plugins package ("sudo apt-get install gedit-plugins" on Ubuntu). From the plugins there I'm currently using only External tools and Code comment (that allows you to comment out whole selection on code in one go).

I also downloaded the Intelligent text completion plugin from ze here: https://github.com/nymanjens/gedit-intelligent-text-completion

You can also disable Toolbar and Statusbar from the window menu -> View if you think they're getting in the way.

And finally, in order to comfortably build from editor, without having to go to terminal, I went to window menu -> Tools -> Manage external tools. Here I added two tools (named them MyBuild and MyRun cause of my abundance of creativity). I bound them to CTRL+B and CTRL+R respectively but you can do whatever you want.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
#MyBuild

EHOME=`echo $HOME | sed "s/#/\#/"`
DIR=$GEDIT_CURRENT_DOCUMENT_DIR
while test "$DIR" != "/"; do
  for m in build.sh; do #list of possible names for your build scripts
    if [ -f "${DIR}/${m}" ]; then
      echo "Using ${m} from ${DIR}" | sed "s#$EHOME#~#" > /dev/stdout
      pushd "${DIR}" &> /dev/null
      ./build.sh
      popd &> /dev/null
      exit
    fi
  done
  DIR=`dirname "${DIR}"`
done
echo "No build script found!" > /dev/stderr

#!/bin/bash
#MyRun

EHOME=`echo $HOME | sed "s/#/\#/"`
DIR=$GEDIT_CURRENT_DOCUMENT_DIR
while test "$DIR" != "/"; do
  for d in build; do #list of possible names for your build folder
    if [ -d "${DIR}/${d}" ]; then
      DIR="${DIR}/${d}"
      for e in game; do #list of possible names for you executable files
        if [ -f "${DIR}/${e}" ]; then
          echo "Executing ${e} from ${DIR}" | sed "s#$EHOME#~#" > /dev/stdout
          pushd "${DIR}" &> /dev/null
          chmod +x ${e}
          ./${e}
          popd &> /dev/null
          exit
        fi
      done
      DIR=`dirname "${DIR}"`
    fi
  done
  DIR=`dirname "${DIR}"`
done
echo "No executable found!" > /dev/stderr


These are in no way bulletproof scripts (please don't stone me to death for how bad they are) and if you know even little of bash scripting, I would strongly advise you to write something better. Basically what the do is to look from the location of current file to the system root folder and look for build.sh file (in case of MyBuild) or "game" file inside build folder (in case of MyRun) and execute them. I should say, that I changed compiler output file name to game, so that MyRun script works on any project as long as its output is called game. I also set the Save option to All documents and Output option to Display in bottom pane for both MyBuild and MyRun.

I'm planning to play around with few more plugins but for now, this setup is plenty enough for me and I quite like it so far. Although I don't rule out, that I'll have look on other editors as well.
Andrew Chronister
194 posts / 2 projects
Developer, administrator, and style wrangler
Gedit - editor setup
Good to know this is an option! I picked up sublime text on windows and liked it, and luckily its also on linux, but it looks like gedit is a good backup in case something craps out.
David Roguin
15 posts
Gedit - editor setup
Have you tried qtcreator?