Cir*_*四事件 21
C语言 [[
如果您的C代码是非埃及风格:
[[
Run Code Online (Sandbox Code Playgroud)
[m只有{}在函数周围有用时才有效,例如class { method(){} }Java/C++.
这是一个适用于埃及和非埃及大括号的好赌注:
?^[^ \t#]
Run Code Online (Sandbox Code Playgroud)
例子:
void egypt() {
#define DONTCARE 1
int indented code = 1;
}
void tpyge()
{
#define DONTCARE 1
int indented code = 1
}
Run Code Online (Sandbox Code Playgroud)
我花了几个小时来制作这个图案:/^\s*\(\i\+\_[ \t\*]\+\)\+\i\+\_s*(\_[^)]*)\_s*{,它对我很有用。
编辑:更好的模式(版本 2):/\(\(if\|for\|while\|switch\|catch\)\_s*\)\@64<!(\_[^)]*)\_[^;{}()]*\zs{
您可以在 .vimrc 中映射一些方便的绑定,例如:
" jump to the previous function
nnoremap <silent> [f :call search('^\s*\(\i\+\_[ \t\*]\+\)\+\i\+\_s*(\_[^)]*)\_s*{', "bw")<CR>
" jump to the next function
nnoremap <silent> ]f :call search('^\s*\(\i\+\_[ \t\*]\+\)\+\i\+\_s*(\_[^)]*)\_s*{', "w")<CR>
Run Code Online (Sandbox Code Playgroud)
编辑:更好的模式(版本 2):
" jump to the previous function
nnoremap <silent> [f :call
\ search('\(\(if\\|for\\|while\\|switch\\|catch\)\_s*\)\@64<!(\_[^)]*)\_[^;{}()]*\zs{', "bw")<CR>
" jump to the next function
nnoremap <silent> ]f :call
\ search('\(\(if\\|for\\|while\\|switch\\|catch\)\_s*\)\@64<!(\_[^)]*)\_[^;{}()]*\zs{', "w")<CR>
Run Code Online (Sandbox Code Playgroud)
2022年,护树人值得您关注。
内置函数[m使用词法规则,并且总是跳转到前一个{位置或最外层{位置。
相比之下,treesitter利用了句法信息,因此可以跳转到更精确的位置,并且没有如下所述的限制:
上面两个命令假设该文件包含一个带有方法的类。类定义被“{”和“}”包围。类中的每个方法 类中的每个方法也用“{”和“}”包围。这适用于 Java 语言。文件看起来像这样:>
如果您想了解更多信息,请查看https://github.com/nvim-treesitter/nvim-treesitter-textobjects
| 归档时间: |
|
| 查看次数: |
17795 次 |
| 最近记录: |