" Run this as " vim -S fixTailCalls.vim myAssemblerFile.s " " Changes " rcall xx/ret " to " rjmp xx " and " rcall xx/.Lyy:/ret " to " .Lyy: rjmp xx " " and removes doubled ret calls. " " save a backup file w %.bak " remove comments too; it's easier this way. g/\/\*.*\*\//d " condense repeated newlines 1,$s#\n\n#\r#e " rcall/label/ret => label/rjmp 1,$s#^\(\s\+\)rcall\s\+\(\S\+\)\n\(\s*\.L\d\+:\)\s*\n\s\+ret\s*$#\3\r\1rjmp \2\r#e " rcall/ret => rjmp 1,$s#^\(\s\+\)rcall\s\+\(\S\+\)\n\s\+ret\s*$#\1rjmp \2\r#e " ret/ret => ret 1,$s#^\(\s\+\)ret\s*\n\s*ret\s*$#\1ret\r#e " write changed file w " and quit q