相当于Python文件的%移动
对于使用相当于Python文件的%移动,python,vim,Python,Vim,对于使用{}表示块的语言,vim具有万能的%键。python代码的等效移动是什么?或者至少移动到具有相同缩进的下一行/上一行。建议绑定,例如: nnoremap <M-,> k:call search('^'. matchstr(getline(line('.')+1), '\(\s*\)') .'\S', 'b')<CR>^ nnoremap <M-.> :call search('^'. matchstr(getline(line('.')), '\(\s
{}
表示块的语言,vim具有万能的%
键。python代码的等效移动是什么?或者至少移动到具有相同缩进的下一行/上一行。建议绑定,例如:
nnoremap <M-,> k:call search('^'. matchstr(getline(line('.')+1), '\(\s*\)') .'\S', 'b')<CR>^
nnoremap <M-.> :call search('^'. matchstr(getline(line('.')), '\(\s*\)') .'\S')<CR>^
nnoremap k:call search('^'.matchstr(getline(line('.')+1),'\(\s*\))'.\s',b')^
nnoremap:调用搜索('^'.matchstr(getline(line('.')),'\(\s*\))。\s')^
以及提供更全面的解决方案:
" Jump to the next or previous line that has the same level or a lower
" level of indentation than the current line.
"
" exclusive (bool): true: Motion is exclusive
" false: Motion is inclusive
" fwd (bool): true: Go to next line
" false: Go to previous line
" lowerlevel (bool): true: Go to line with lower indentation level
" false: Go to line with the same indentation level
" skipblanks (bool): true: Skip blank lines
" false: Don't skip blank lines
function! NextIndent(exclusive, fwd, lowerlevel, skipblanks)
let line = line('.')
let column = col('.')
let lastline = line('$')
let indent = indent(line)
let stepvalue = a:fwd ? 1 : -1
while (line > 0 && line <= lastline)
let line = line + stepvalue
if ( ! a:lowerlevel && indent(line) == indent ||
\ a:lowerlevel && indent(line) < indent)
if (! a:skipblanks || strlen(getline(line)) > 0)
if (a:exclusive)
let line = line - stepvalue
endif
exe line
exe "normal " column . "|"
return
endif
endif
endwhile
endfunction
" Moving back and forth between lines of same or lower indentation.
nnoremap <silent> [l :call NextIndent(0, 0, 0, 1)<CR>
nnoremap <silent> ]l :call NextIndent(0, 1, 0, 1)<CR>
nnoremap <silent> [L :call NextIndent(0, 0, 1, 1)<CR>
nnoremap <silent> ]L :call NextIndent(0, 1, 1, 1)<CR>
vnoremap <silent> [l <Esc>:call NextIndent(0, 0, 0, 1)<CR>m'gv''
vnoremap <silent> ]l <Esc>:call NextIndent(0, 1, 0, 1)<CR>m'gv''
vnoremap <silent> [L <Esc>:call NextIndent(0, 0, 1, 1)<CR>m'gv''
vnoremap <silent> ]L <Esc>:call NextIndent(0, 1, 1, 1)<CR>m'gv''
onoremap <silent> [l :call NextIndent(0, 0, 0, 1)<CR>
onoremap <silent> ]l :call NextIndent(0, 1, 0, 1)<CR>
onoremap <silent> [L :call NextIndent(1, 0, 1, 1)<CR>
onoremap <silent> ]L :call NextIndent(1, 1, 1, 1)<CR>
“跳转到具有相同级别或更低级别的下一行或上一行
“缩进级别大于当前行。
"
“排他性(bool):正确:运动是排他性的
“错:动议是包容性的
“前进(布尔):正确:转到下一行
“false:转到上一行
“lowerlevel(bool):true:转到具有较低缩进级别的行
false:转到具有相同缩进级别的行
“skipblanks(bool):true:跳过空行
false:不要跳过空行
function!NextIndent(独家、前向、低层、短板)
设line=line(“.”)
让列=列('.'))
设lastline=line(“$”)
设缩进=缩进(行)
设阶跃值=a:fwd?1:-1
while(第0行和第0行)
如果(a:独家)
让line=line-步长值
恩迪夫
exe行
exe“正常”列。“|”
返回
恩迪夫
恩迪夫
循环结束
端功能
在相同或较低缩进的行之间来回移动。
nnoremap[l:调用NextIndent(0,0,0,1)
nnoremap]l:调用下一个事件(0,1,0,1)
nnoremap[L:调用NextIndent(0,0,1,1)
nnoremap]L:调用下一个事件(0、1、1、1)
vnoremap[l:调用NextIndent(0,0,0,1)m'gv''
vnoremap]l:调用NextIndent(0,1,0,1)m'gv''
vnoremap[L:调用NextIndent(0,0,1,1)m'gv''
vnoremap]L:调用NextIndent(0,1,1,1)m'gv“”
onoremap[l:调用NextIndent(0,0,0,1)
onoremap]l:调用下一个事件(0,1,0,1)
onoremap[L:调用NextIndent(1,0,1,1)
onoremap]L:呼叫下一个事件(1,1,1,1)
它使用:
和[l
跳转到与当前行具有相同缩进级别的上一行或下一行]l
和[L
跳转到缩进级别低于当前行的上一行或下一行]L
Vim有
{
和}
运动在“段落”和相应的p
文本对象(vip
,dap
)之间移动
默认的Python ftplugin还(重新)定义了[[
和]
移动到下一个和上一个类,以及]m
和[m
移动到下一个和上一个方法
这对Python也是非常有用的。为什么不下载一个Python插件呢?或者至少用相同的缩进移到下一行/上一行-你能详细解释一下这是什么意思吗?呃,我希望我从来没有遇到过这样的编码风格。我只是在没有评论的情况下投了反对票。我理解这种编码风格并不令人愉快。我说过我会如果共享代码,请不要这样做。编码样式是允许在vim中移动
%
。对不起,缩进对象是什么?请链接?对不起,我的剪贴板中有URL,但我忘了把它放在答案中。虽然很容易找到。很酷,但缩进对象在正常模式下不工作。有没有办法强迫它在正常模式下工作正常模式?@emmasculateur,我不知道你的意思是什么:这个插件做它应该做的:vii
,dii
,cii
,yii
,=ii
,ai
,@romainlvii
将选择一个块,yii
复制它,=ai
缩进它,等等。我只想要它在正常模式下移动到块的开始/结束。第一个答案给出了一个解决方案,但是[L
和]L
对我不起作用,所以我认为这个插件可能会有所帮助。
class Game(object): # {
def __init__(self, num, end): # {
pass
# }
# }