Skip navigation

teranex weblog

top menu

programming

Automate Github Pull Requests [splitbrain.org]

yEd - Graph Editor

yEd is a powerful diagram editor that can be used to quickly and effectively generate high-quality drawings of diagrams.
Create your diagrams manually or import your external data for analysis and auto-magically arrange even large data sets by just pressing a button.

http://www.yworks.com/en/products_yed_about.html

VIM: working with "light-projects"

While VIM certainly isn't an IDE, there are a lot of plugins in existence to make it more IDE-like. Although I have been working a lot inside IDE's the past few years, I don't really need all those fancy IDE features (and the bloat that comes with it). That's one of the many things I like so much about Vim, I can just add the features I need to the editor. So while there are certainly at least a few plugins to work with projects inside Vim, I came up with my own system for working with "projects" (call them "light-projects" if you wish). One small note: For the moment this method suits my needs, but since I'm only using Vim for about two months as my main editor, this might change obviously.

Basically, my solutions is based on an autocommand for every 'project' and the command-t plugin. Oh, and sessions as well. The autocommand detects when a file is read (or created) inside the project-directory. In this case, it will source the correct 'vimrc-project-file' and setup everything specific for the project. So as an example, suppose we have a project in ~/Projects/foobar/. In my .vimrc I add the following line (to be more correct, for most of the projects I would add the line in my host-specific vimrc-file, as I mostly use one specific computer to work on a specific project):

1
autocmd BufRead,BufNewFile ~/Projects/foobar/* source ~/.vim/projects/foobar.vim

This autocommand simply sources the foobar.vim file everytime a file in the foobar directory is read, or created. Since the foobar.vim project-file is just a regular vim-script file, you can do anything you want in it. I mostly use it to set some editor properties and add some additional mappings, such as:

1
2
3
4
56
7
8
9
10
" I use autochdir by default, but for this project I prefer
" to always be in the project-root. So we first disable the
" autochdir option
setlocal noautochdir 
 " and then we cd to the project-root
cd ~/Projects/foobar/
 
" in this project i like to use ant, so set it up as the make program inside vim
setlocal makeprg=ant\ -find\ build.xml

I have some other options in my project-vimrc file which are more specific to exploring and navigating code, but I will explain these in a later post I plan to write.

So that's it for automatically configuring vim with settings specific to your project when editing one of the files of that project. One other important aspect of working with projects is to be able to easily open any file of your project. Most IDE's have fancy file-explorers, and a lot of vim-users seem to love the NERDtree plugin. But a few years ago, when I found the OpenIt plugin for jEdit, I discovered that I can type faster than search my way through a tree-structure of directories and files. Resharper adds a similar feature to VS.NET (did I already mention that Visual Studio is just crap without Resharper?). Just press a shortcut, start typing what you need, and let the program do the searching.

For vim I found the command-t plugin. After installing the plugin you can launch command-t with <leader>t (unless you have changed your leader key it will be a backslash, so the correct mapping will be \t). Command-T will index your current directory and it's children. The fact that it indexes the current working directory is one of the reasons why I `cd` to the root of a project in my project-vimrc, so while working on a project Command-T will always index my entire project. The first time you launch it, command-t might take a few seconds before the indexing finishes (depending on the amount of files in the directory-tree), but the results are cached, so next time you launch Command-T it shows up almost instantly. Command-T will now show you a list of all the files in your project. Now you can just start typing parts of the filename (or even of the path to the file) and Command-T will filter out the matching files. If the correct file is selected, simply press enter and Command-T will open the file. I really find this a lot easier than hunting down the file myself.

One last feature of Vim I use for projects are sessions. If your Vim is compiled with session-support (it probably is), you can let Vim write a file which contains a list of all the buffers you have opened (and mappings etc which you have defined while editing). When you want to continue working on your project, you can simply instruct Vim to open the session from the session-file and Vim will restore all the opened buffers, mappings etc.

While this is already useful, I think it still requires to many manual actions. No problem, plugins to the rescue! The SessionMan plugin makes all of this a lot easier. The first time you start your project, simply save your session with :SessionSave. SessionMan will notice that you currently don't have a session and ask for a name, so you can enter 'foobar' (if that is the very original name of your project). When you start vim again to continue working on your project you can now simply use the command :SessionOpen foobar to open your foobar session. Also SessionMan will automatically save your session when quitting vim. Another useful command is :SessionList (which I have mapped to ,s). This shows a list of all your sessions and lets your select the session which you want to open.

So in short, when I want to continue working on a project:

  • I launch gvim
  • I type ,s to open the sessionlist
  • I select the correct session
  • Vim restores all my opened buffers and windows
  • Thanks to the autocommand for the project, vim is correctly setup for the project
  • I can quickly open files with \t

BashPitfalls - Greg's Wiki

This page shows common errors that Bash programmers make. The following examples are all flawed in some way

http://mywiki.wooledge.org/BashPitfalls

Learning Vim

When I started working on my first PHP project at Inuits I had to decide which editor or IDE to use. Obviously while I was still working in the .NET-world I used Visual Studio, just as almost everybody else. However I also used jEdit at home for PHP, Ruby etc. I always felt that learning a general purpose editor, and learning it very well, is more interesting than learning an IDE for one specific platform (VS.NET in this case).

One of my new colleagues recommended me to use NetBeans for PHP development, so I had a look at it. While I'm sure it has a lot to offer, it just didn't feel like the tool I wanted to use. Obviously I had also installed jEdit. While I have always loved jEdit, somehow I wasn't convinced anymore. I also had a look at gEdit, which certainly has potential if you install some extra plugins and configure it, but compared to other editors and IDE's it seems to be rather limited. So then there was still that other editor. The editor which has fascinated me since at least 5 years. The editor which I have been using from time to time to make small edits on config files. The one editor which has a history which dates back to 1976. Yes, indeed, I'm talking about vi and it's modern incarnation vim (Vi IMproved).

As I already mentioned I had been using vi for at least 5 years to make small changes to config files, mostly over SSH on webservers, so I knew the basics. But the basics are, imho, just not enough to do some serious development. Therefore I decided to try and learn at least one new thing about vim everyday. Be it a new shortcut, a plugin, whatever. Reading an entire article with lots and lots of vim-shortcuts really isn't the best method to learn vim, because it's impossible to memorize them all at once.

However after using other editors and IDE's, such as VS.NET, for so many years, it is difficult to just start with vim, because it has a steep learning curve. By example, I got used to navigating code with the arrow keys, certainly in combination with the control and shift keys, to move the cursor by words and select text. Because I did not yet know the correct vim keys and learning them all at once is impossible I had to find a solution to ease my transition. I found this solution in the mswin.vim script which comes with vim by default. You can enable this script by placing the following lines in your .vimrc file:

1
2
source $VIMRUNTIME/mswin.vim
behave mswin

This script makes vim behave more like other text editors. It's Vim with bicycle training wheels. You will be able to select text by using the arrow-keys in combination with shift, copy and paste with <CTRL+C> and <CTRL+V>, save with <CTRL+S> etc. Sadly it also uses some bindings, like <CTRL+Y>, which have, by default in vim, a different function thus making those default commands unavailable. While this script is very useful, my goal has always been to learn the real vi-shortcuts so in the end it should be possible to disable the script. You don't keep your training wheels either do you? And a few days ago I learned how to copy/paste from the global clipboard, which I believe was the last shortcut I was missing, so as of yesterday I have disabled the script. Now I hope I don't crash on my face because of the missing wheels :).

Another nice trick I found is to change the color of the statusline depending on the current status. When I'm in normal mode, my statusline is gray, the default for the Mustang colorscheme. But while I'm in insert mode the statusline turns green. To configure this add the following lines to your .vimrc:

1
2
3
4
5
" first make sure the statusline is always shown
set laststatus=2
" then define two autocommands
au InsertEnter * hi StatusLine term=reverse guibg=#005000
au InsertLeave * hi StatusLine term=reverse guibg=#444444

Please not that this configuration only works for gVim, not the terminal version. But it is possible to adapt it for the terminal version as well.

Oh and just as a reference, here are some of the shortcuts I use to replace most of the shortcuts in other editors:

  • w: move to the next word (replaces <CTRL+Right Arrow>)
  • b: move to the previous word (replaces <CTRL+Left Arrow>)
  • de: delete the next word (replaces <CTRL+DELETE>)
  • db: delete the previous word (replaces <CTRL+BACKSPACE>)
  • viw: select entire word (replaces <CTRL+SHIFT+Right Arrow>) Note: keep pressing 'w' to select additional words
  • "+p: paste from the global clipboard (replaces <CTRL+V> in case you want to paste text from another application)
  • "+y: copy to the global clipboard (replaces <CTRL+C> in case you want to copy text to another application)
  • "+d: cut to the global clipboard (replaces <CTRL+X> in case you want to cut text to another application)

I'm also using some very useful plugins to help me code, and I have some nice config-settings in my .vimrc, but i'll show these in another blogpost.

Vimposter Plugin | Rutherfurd.net

Vimposter provides vi/vim emulation for jEdit.

http://www.rutherfurd.net/jedit/plugins/vimposter/index.html

Vala - GNOME Live!

Vala is a new programming language that aims to bring modern programming language features to GNOME developers without imposing any additional runtime requirements and without using a different ABI compared to applications and libraries written in C.

http://live.gnome.org/Vala