Last active
May 27, 2017 05:29
-
-
Save nick96/0637c1b35dcf1718887a60dbdad0a251 to your computer and use it in GitHub Desktop.
Coded up an assignment in C99 but the uni server is only C89. One of the main issues was declaring counters in the for-loop. This the regexp I used in VIM to move counteres outside.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" This was a massive help for me cause I could just run one command on a file and it would compile to C89. | |
" Hopefully this is useful to anyone who runs into the same problem :) | |
" It's a bit long winded so I put an explanation below: | |
" 1 = spacing, this allows the counter declaration to be easily indented the same amount no matter the | |
" indentation. | |
" 2 = 'for (' | |
" 3 = the counter type | |
" 4 = is for if the counter is pointer, like if you're iterating over a linked list | |
" 5 = the counter variable name | |
" 6 = the rest of the for-loop | |
%s/\(\s\+\)\(for (\)\(\w\+\) \(*\?\)\(\w\+\)\( .\+\)/\1\3 \4\5;\r\1\2\5\6/ | |
" \s = whitespace | |
" \+ = one or more | |
" \? = one or none | |
" . = anything but an end of line character | |
" \<n> = refers to the nth grouping between \( and \) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Relevant xkcd