我是如何使用vim在java代码中抽取函数的

时间:2022-06-12 18:03:59

Java has curly braces that encapsulate the entire class definition. So when using the parenthsis ({ or }) key in vim, it goes to the end of the class instead of going to the next blank line or the end of the function definition. So how can I yank entire function and comment as well? In another word, I can I jump to next blank line regardless of the position?

Java有大括号,它封装了整个类定义。因此,当在vim中使用parenthsis({或})键时,它会转到类的末尾,而不是转到下一个空行或函数定义的结尾。那么我怎么能抽出整个函数和评论呢?换句话说,无论位置如何,我都能跳到下一个空行?

3 个解决方案

#1


1  

I don't fully understand the problem, vim should match curly brackets, you can use shift-% to toggle your cursor position on matched brackets. With that said, if I understand you correctly(and trying it out myself) you are getting everything under the function header when you yank with ya{. Try this: on the end { of the function header, use ma to mark the position to register a, then % to move down to the end of the method, then y'a to yank it all. This will grab the entire function.

我不完全理解这个问题,vim应该与大括号匹配,你可以使用shift-%在匹配的括号上切换光标位置。话虽如此,如果我理解正确(并且自己尝试了),当你用ya {时,你会得到函数标题下的所有内容。试试这个:在函数头的末尾,使用ma来标记位置以注册a,然后使用%来向下移动到方法的末尾,然后y'a将它全部拉出来。这将抓住整个功能。

#2


0  

You can yank the contents of a method while the cursor is in the method with yi{, in other words y ank i nner {

当光标在yi {的方法中时,您可以抽取方法的内容,换句话说,y ank i nner {

#3


0  

This is answer I came up with and I am not happy with it. In my vimrc, I set tab to be 4 whitespaces. So if I know that my function is separated by line that has 4 white spaces, I can do

这是我想出的答案,我对此并不满意。在我的vimrc中,我将tab设置为4个空格。所以如果我知道我的函数是由具有4个空格的行分隔的,我可以这样做

y/^\s\s\s\s$

#1


1  

I don't fully understand the problem, vim should match curly brackets, you can use shift-% to toggle your cursor position on matched brackets. With that said, if I understand you correctly(and trying it out myself) you are getting everything under the function header when you yank with ya{. Try this: on the end { of the function header, use ma to mark the position to register a, then % to move down to the end of the method, then y'a to yank it all. This will grab the entire function.

我不完全理解这个问题,vim应该与大括号匹配,你可以使用shift-%在匹配的括号上切换光标位置。话虽如此,如果我理解正确(并且自己尝试了),当你用ya {时,你会得到函数标题下的所有内容。试试这个:在函数头的末尾,使用ma来标记位置以注册a,然后使用%来向下移动到方法的末尾,然后y'a将它全部拉出来。这将抓住整个功能。

#2


0  

You can yank the contents of a method while the cursor is in the method with yi{, in other words y ank i nner {

当光标在yi {的方法中时,您可以抽取方法的内容,换句话说,y ank i nner {

#3


0  

This is answer I came up with and I am not happy with it. In my vimrc, I set tab to be 4 whitespaces. So if I know that my function is separated by line that has 4 white spaces, I can do

这是我想出的答案,我对此并不满意。在我的vimrc中,我将tab设置为4个空格。所以如果我知道我的函数是由具有4个空格的行分隔的,我可以这样做

y/^\s\s\s\s$