Vim 为什么是'&书信电报;和'&燃气轮机;未在此脚本中设置?
我试图编写一个VimScript来转换C++声明,例如:Vim 为什么是'&书信电报;和'&燃气轮机;未在此脚本中设置?,vim,Vim,我试图编写一个VimScript来转换C++声明,例如: virtual int funct(int aaa=one, float b=two); 定义如下: int SomeClass::funct(int aaa, float b) { } 。。然后我会向其中添加代码。我希望它能够处理运动和视觉模式选择,因此我从vim帮助中获取了if语句,然后将我的东西放在后面 nmap <silent> <F4> :set opfunc=TestMe<CR>g@ v
virtual int funct(int aaa=one, float b=two);
定义如下:
int SomeClass::funct(int aaa, float b) {
}
。。然后我会向其中添加代码。我希望它能够处理运动和视觉模式选择,因此我从vim帮助中获取了if语句,然后将我的东西放在后面
nmap <silent> <F4> :set opfunc=TestMe<CR>g@
vmap <silent> <F4> :<C-U>call TestMe(visualmode(), 1)<CR>
function! TestMe(type, ...)
" I grabbed the below from the help, but removed
" the 'y' at the end of each exe commands.
let sel_save = &selection
let &selection = "inclusive"
let reg_save = @@
if a:0 " Invoked from Visual mode, use gv command.
silent exe "normal! gv"
elseif a:type == 'line'
silent exe "normal! '[V']"
else
silent exe "normal! `[v`]"
endif
" My code below:
" gets rid of virtual keyword
exec "'<,'>s/\\(\\s*\\)virtual\\s\\+/\\1/ge"
" gets rid of optional parameter assignments
exec "'<,'>s/\\s*=\\s*[a-zA-Z_0-9\:]\\+//ge"
" adds <contents of A register>:: in front of function name
exec "'<,'>g/\\s*[^\\s]*\\s*(.*)\\s*;\\s*$/norm! ==%%b\"aPa::"
" replaces ; with {} and newlines
exec "'<,'>s/\\s*;\\s*$/ {\r\t}\r/g"
" The following is from vim help again:
let &selection = sel_save
let @@ = reg_save
endfunction
我认为会发生的是if语句将使用适当的v命令来选择相关的文本,然后运行exec命令。然后,这些exec语句将使用“,您需要在函数之后添加
范围。例如:
function! TestMe(type, ...) range
然后使用a:firstline
和a:lastline
参见:h函数范围示例
可能不需要c++
标记,这确实是一个纯粹的vim
问题。虽然我以为我添加了vim和vimscript标记,但我只看到了一个vim标记。我不知道哪里出了问题,也不知道如何修复。注意:这是一个复杂的主题,有很多事情要做:-提取当前类名(可以嵌入到其他类和名称空间中);-删除可能的评论;-甚至可以使用多行声明;-删除一些说明符(virtual
,override
,static
…);-保留一些其他(异常规范,const
…);-等等我有超过700行VIM脚本代码+几百个用于解码C++构造的代码(参见<代码>:GotoIMPL//COD>特性)
function! TestMe(type, ...) range