0
我想配置我的.vimrc做一些自动语法检查。 这是我的问题,我想自动改变某些语法的另一个。 我处理计算机程序中的特定字符= =; ,。 ({[<vim语法检查空白
个例是胜于言:
void bibi(int param1,char *words)
{
unsigned int locale=param;
cout<<words<<endl;
}
变成了:
void bibi(int param1,char* words)
{
unsigned int locale = param;
cout << words << endl;
}
与补充一点,在格式化或删除一些空格
我写这篇文章:。
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Formating of text in code
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! ChangeSpaces()
"" search and replace "= " or " =" or "= " to " = "
silent! %s/\s*[=]\s*/ = /g
endfunction
""autocmd CursorMovedI * call ChangeSpaces()
""autocmd BufWrite * call ChangeSpaces()
autocmd FileAppendPre * call ChangeSpaces()
但我没有结果,在这种情况下,如果我写“i = e”,他们什么也不做,但是如果我写'i =',这是工作,正则表达式不运行,它们在结束后替换“模式”。顺便说一句,如果你有更“性感的方式”去做我想做的事,让我知道。 事实上,当我想添加一些其他的特定卡拉科特的代码变成了:
"function! ChangeSpaces()
"" search and replace "= " or " =" or "= " to " = "
"silent! %s/\s*[=]\s*/ = /g
""" search and replace "(" or " (" or "(" to " ("
"" silent! %s/\s*[(]\s*/ (/g
""" search and replace "[ " or " [" or "[" to " [ "
"" silent! %s/\s*[[]\s*/ [ /g
""" search and replace ", " or " ," or "," to " , "
"" silent! %s/\s*[,]\s*/ , /g
""" search and replace "== " or " ==" or "==" to " == "
"" silent! %s/\s*[==]\s*/ = /g
""" search and replace "> " or " >" or ">" to " > "
"" silent! %s/\s*[>]\s*/ > /g
""" search and replace ">= " or " >=" or ">=" to " >= "
" silent! %s/\s*[>=]\s*/ >= /g
""" search and replace "< " or " <" or "<" to " < "
"" silent! %s/\s*[<]\s*/ < /g
""" search and replace "<= " or " <=" or "<=" to " <= "
"" silent! %s/\s*[=]\s*/ <= /g
"" let repl=substitute(cline,\s*[= ]\s*," = ", "g")
"" call setline(".",repl)
"" let cline=line(".")
"" let ccol=col(".")
"" call cursor(cline, ccol)
"endfunction
""autocmd CursorMovedI * call ChangeSpaces()
""autocmd BufWrite * call ChangeSpaces()
"autocmd FileAppendPre * call ChangeSpaces()
最好的问候。 PS:我不好,我希望这种格式化,对于我使用的每种语言,不仅仅是C++。
感谢您的分享,但我希望此格式不仅适用于C++。 如果可能的话,只需一个编辑器vim和一些插件,而不是更多的软件。 – Max 2013-03-20 10:50:49