Vim [m运动与c#
发布时间:2020-12-16 01:24:08 所属栏目:安全 来源:网络整理
导读:Vim提供非常有用的运动命令跳转到下一个 方法的开始/结束:] m,] M,[m和] m. 这些工作适用于Java或类似的结构化语言. (如:help)m和:help 29.3) 似乎工作考虑到最外面的一对花括号作为课堂 声明和下一级的大括号作为方法声明. 当有一对外花括号时,这些运动
Vim提供非常有用的运动命令跳转到下一个
方法的开始/结束:] m,] M,[m和] m. 这些工作适用于Java或类似的结构化语言. 似乎工作考虑到最外面的一对花括号作为课堂 当有一对外花括号时,这些运动命令不起作用 我想知道是否有一些技巧来制作这些命令(单独和 namespace ABC.DEF { class A { protected string strID; public string PortID { get { return strID; } set { strID = value; } } protected MyType x; public MyType X { get { return x; } set { x = value; if ( x != null ) func1(); } } int func1() { return 1; } int func2(int flag) { if (flag == 0) return flag; if (flag > 3) { return flag; } return 2; } int func3() { return 3; } } }
我不认为这个m系列的映射可以定制.在这种情况下,通常的做法是用自定义逻辑来覆盖它.我想出了一些应该做你所描述的vimscript.基本上,它跳过大括号,看看相关的线条来决定要做什么.在这种情况下,它只是忽略“类”和“命名空间”声明.
nnoremap <buffer> ]m :<c-u>call <SID>JumpMethod('{','W','n')<cr> nnoremap <buffer> [m :<c-u>call <SID>JumpMethod('{','Wb','n')<cr> nnoremap <buffer> ]M :<c-u>call <SID>JumpMethod('}','n')<cr> nnoremap <buffer> [M :<c-u>call <SID>JumpMethod('}','n')<cr> xnoremap <buffer> ]m :<c-u>call <SID>JumpMethod('{','v')<cr> xnoremap <buffer> [m :<c-u>call <SID>JumpMethod('{','v')<cr> xnoremap <buffer> ]M :<c-u>call <SID>JumpMethod('}','v')<cr> xnoremap <buffer> [M :<c-u>call <SID>JumpMethod('}','v')<cr> onoremap <buffer> ]m :<c-u>call <SID>JumpMethod('{','o')<cr> onoremap <buffer> [m :<c-u>call <SID>JumpMethod('{','o')<cr> onoremap <buffer> ]M :<c-u>call <SID>JumpMethod('}','o')<cr> onoremap <buffer> [M :<c-u>call <SID>JumpMethod('}','o')<cr> function! s:JumpMethod(char,flags,mode) let original_cursor = getpos('.') if a:mode == 'v' normal! gv elseif a:mode == 'o' normal! v endif while search(a:char,a:flags) > 0 if a:char == '}' " jump to the opening one to analyze the definition normal! % endif let current_line = line('.') if getline(current_line) =~ '^s*{' " it's alone on the line,check the above one let method_line = current_line - 1 else let method_line = current_line endif let method_line_body = getline(method_line) if method_line_body =~ 'k+s*(.*)' && method_line_body !~ '&;(for|foreach|if|while|switch|using|catch|get|set)&;' " it's probably a function call if a:char == '}' " we need to go back to the closing bracket normal! % endif echo return else if a:char == '}' " we still need to go back to the closing bracket normal! % endif endif endwhile " if we're here,the search has failed,restore cursor position echo call setpos('.',original_cursor) endfunction 记住,我不太了解很多C#,所以在所有情况下都可能无法正常工作,但是如果给我一些破坏的例子,我可能会弄清楚一些事情. 要尝试,您应该将其放在vimfiles目录中的“ftplugin”下面的“cs.vim”中.任何以“cs”开头并以“.vim”结尾的其他文件名也很好,如果你已经有一个“cs.vim”文件. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |