Browsing Posts published by Mads Navntoft Noe

I just came along the Inkscape Coding Style Guidelines. While written for the Inkscape project, I think it gives some food for thought when talking about code readability. Nice balance between being strict and pragmatic too. Whether you like the style or not, it worthy a read…

I have a Danish keyboard, but I find the English keyboard layout better to code with, so some time ago, I made some customizations using xmodmap to combine these. I wanted to use the English layout in general, but with the Danish characters æ, ø, and Ã¥ available using Alt Gr-;, Alt Gr-‘ and Alt Gr-[, respectively. Also, I wanted to be able to use Alt Gr as a modifier for FVWM shortcuts.

This turned out to be tricky to accomplish, actually. If I set XkbLayout=us in xorg.conf (English layout), I couldn’t get Alt Gr to work with the Danish Characters and as a modifier key at the same time. Mode_Switch or ISO_Level3_Shift either switched keycodes or acted as a modifier key, but not both. Even if I restored the previous Danish layout using dumps of keycodes and modifiers from xmodmap, it didn’t work.

So I made a hack: continue reading…

I like to have a small window at the top of a tab page for reference. Useful when you want to consult the exact wording of a assignment or task description. This function creates a split with the top window showing the area of your visual mode selection. If more than one window is visible, it reuses the top most. Update (2008-06-18): The script now yields two windows: A “main” one, and the one showing only the selection.

Put something like this in your .vimrc:

vnoremap <M-s> :<C-u>call VisualSplit()<Cr>

function! VisualSplit()
	let top = getpos("'<")[1]
	let bot = getpos("'>")[1]
	let height = bot - top + 1
	normal <Esc>
	execute "1 wincmd w"
	" position and size the top window
	execute "normal '<z" . height . "<Cr>z<Cr>"
	" return to 'main' window
	execute "normal <C-w>2<C-w>"

This is a simple, but important tip:

Tabbed interfaces have emerged everywhere, and also Vim 7 comes with support for it. For projects consisting of multiple files, I find it easier to work with tabs than with split windows and multiple buffers. Of course we need some better keybindings:

inoremap <M-n> <C-o>gt
inoremap <M-p> <C-o>gT
inoremap <M-w> <Esc>:tabclose<Cr>
inoremap <M-t> <Esc>:tabe<Cr>
nnoremap <M-n> gt
nnoremap <M-p> gT
nnoremap <M-w> :tabclose<Cr>
nnoremap <M-t> :tabe<Cr>

Also, making the tab bar always visible encourages you to use them more:

set showtabline=2

Now remember to use the -p parameter when you open Vim with multiple files:

vim -p *.tex

Having multiple files open in for instance LaTeX projects also allows you to use completion in references to labels in the corresponding files.

BTW add colon and underscore to iskeyword to enable completion for labels like fig:nice_figure. Oh yes, and use latex-suite

If you need more flexibility than fvwm-menu-directory can give you, you can do the same with GNU find. All you need to do is to create a dynamic menu in your fvwm config

DestroyMenu MenuDaimi
AddToMenu MenuDaimi
+ DynamicPopupAction PipeRead "$[FVWM_USERDIR]/menus/"

and let the shell script output the menu. I use it, for example, to keep a list of shortcuts to my assignments:

cat << eos
DestroyMenu recreate MenuDaimi
AddToMenu MenuDaimi

echo '+ "dADS1"    Title'
find $HOME/A/aflv_* -name "*.tex" -printf 
	'+ %%24x24/mimetypes/gnome-mime-application-x-tex.png%%"%f"t 
	Exec exec gvim -c "cd %H" %pn'

(Note that the find command should be written as one line.) This will list all LaTeX files in $HOME/A/aflv_*, and selecting an entry will start GVIM in the corresponding directory. Nice…

One could get creative and sort the files after date, skip files more than a week old etc. But please be careful not to forget to actually work on the assignments 🙂

Taking a course in Web Technology, I suddenly found myself editing a lot of XML files, so I hurried to fine-tune VIM to make editing more efficient. Please note that I am by no means an expert in XML, so please correct me, if I have misunderstood something. Configuration in xml.vim. Features:

  • Tag closing with code snippets from xmledit. Press <C-k> once to close the tag, and twice to close it and leave an empty line between.
  • Tag closing using omni-completion: <C-b>. This is used when the cursor is not at the end of the starting tag. Will insert the closing tag for the inner most unclosed starting tag.
  • Cycle between start and end tags with <LocalLeader>5 (typically 5 or ,5)
  • Remove outer tag with <LL>r
  • Goto parent tag with <LL>u (working on it, doesn’t work with <x/> tags. Anybody got a clue how to do this correctly?)
  • Document pretty printing with <LL>xf
  • Wellformedness checking (<LL>xx), DTD validation (<LL>xd) and XML Schema validation (<LL>xs) with XML Catalog support using xmllint (see below)

Have a look at Vim as XML Editor by Tobias Reif to find more tips. continue reading…

Update (2010-04-25): You might want to check out this add-on instead…

I just found a tip to display access keys in Firefox, like next[p], if the link has P as the access key. While (disappointingly) not featured extensively on the Internet, access keys might become handy for browsing online documentation (especially if you know what they keys are…). MediaWiki sites, and documentation like the vim-latex reference features access keys.

To use access keys in Firefox press Alt+Shift+<Key>.

If you want to spice up your desktop for Christmas, install xsnow by Rick Jansen, and run it with the commands:

$ xsnow &
$ xsnow -sc yellow &

Enjoy a real danish suburb Christmas! 🙂

If you want to include the XDG menus (used in gnome) in your FVWM menu, have a look at Piotr Zieliński‘s fvwm-xdg-menu. You’ll need PyXDG to make it work.

BTW he has many other exiting things in his config, so check it out.


Personally I prefer to start my applications from a terminal, but it is useful for programs you don’t use very often. And a little cool 🙂

Just read a great book about agile development. Available as paperback and PDF. Very structured. Has a nice “Keeping your balance” section in every chapter, so you can actually use the things discussed in the book in real life…

Many of the things I already knew, but reading the book has made me much more aware of them.

To be recommended for both experienced and less experienced developers…