栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

等效于Python文件的%移动

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

等效于Python文件的%移动

该VIM维基建议绑定,例如:

nnoremap <M-,> k:call search('^'. matchstr(getline(line('.')+1), '(s*)') .'S', 'b')<CR>^nnoremap <M-.> :call search('^'. matchstr(getline(line('.')), '(s*)') .'S')<CR>^

以及提供更全面的解决方案:

" 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 linesfunction! 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  endwhileendfunction" 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>

用途:

  • [l
    ]l
    跳到与当前行具有相同缩进级别的上一行或下一行。
  • [L
    ]L
    跳到缩进级别低于当前行的上一行或下一行。


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/372459.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号