Executing a Regular Expression Set in VI

I have a list of regular expressions that I would like to run in my C code files. This is simple formatting material and will save me the trouble until my code is reviewed.

Here they are

this removes two or more blank lines in one blank line

:%s/\n\{3,}/\r\r/e 

this adds the missing space at the end of the comment, e.g. / * blah blah * / to / * blah blah * /

 :%s/\([^ *]\)\*\//\1 \*\//gc 

this adds the missing space at the beginning of the comment, e.g. / blah blah / to / * blah blah * / Note that it ignores / **

 :%s/\/\*\([^ *]\)/\/\* \1/gc 

removes empty lines after opening the bracket {

 :%s/{\s*$\n\{2,}/{\r/gc 

removes empty lines before closing the bracket}

 :%s/\n\{2,}\(\s*\)}/\r\1}/gc 

in the comments, a space after the decimal point is added if there are no TODO hints and error E16 if no patterns match

 :g/\/\*/ ,/\*\// s/,\([^ ]\)/, \1/gc 

I saved them in a file called fix.txt. Is there a way that I can run them from within VI one by one? something like

 :run fix.txt ? 
+7
source share
2 answers

You must complete:

:source fix.txt

See :help :source .

+6
source
 " put this function in your vimrc file and call them with <leader>f " to more information read :help leader " also read :help keepjumps fun! FixSourceCode() :%s/\n\{3,}/\r\r/e :%s/\([^ *]\)\*\//\1 \*\//gc :%s/\/\*\([^ *]\)/\/\* \1/gc :%s/{\s*$\n\{2,}/{\r/gc :%s/\n\{2,}\(\s*\)}/\r\1}/gc :g/\/\*/ ,/\*\// s/,\([^ ]\)/, \1/gc Endfun nmap <silent> <leader>f :keepjumps call FixSourceCode()<cr> 
0
source

All Articles