第一行换行接下一行时,没有加上行号,我希望像2、3行这样,一换行就默认为新的一行(加上行号),因为有时候一段东西太多的话都当成是一行中的内容,用行号来跳转的话有时候还要移动很多才能到达自己想要的位置(主要是我水平菜),如果每行都能是新的一行的话用行号来跳转就可以很方便地缩小范围,感觉效率会高点。所以特来请教各位大侠了

代码: 全选
function MapFlow()
noremap <buffer> j gj
noremap <buffer> k gk
noremap <buffer> 0 g0
noremap <buffer> ^ g^
noremap <buffer> $ g$
let b:old_textwidth=&l:tw
setl tw=0
endfunction
function UnMapFlow()
unmap <buffer> <silent> j
unmap <buffer> <silent> k
unmap <buffer> <silent> 0
unmap <buffer> <silent> ^
unmap <buffer> <silent> $
if exists('b:old_textwidth')
exec 'setl tw=' . b:old_textwidth
endif
endfunction
command MapFlow :call MapFlow()
command UnMapFlow :call UnMapFlow()
command MF :call MapFlow()
command UMF :call UnMapFlow()
代码: 全选
set textwidth=78
太强大了,那个代码虽然看不太懂,但感觉学到不少东西了,非常感谢Fermat618 写了:那个不是真正的一行,是屏幕行,是因为一行太长,屏幕放不下了,折叠过来的。
要是有比较多的太行的行的话,我是用下面的代码切换长短行模式。vim 中不推荐使用太行的行,而是限定一个行宽,然后自动或手动折行。一般推荐行宽在 80 列以内。代码: 全选
function MapFlow() noremap <buffer> j gj noremap <buffer> k gk noremap <buffer> 0 g0 noremap <buffer> ^ g^ noremap <buffer> $ g$ let b:old_textwidth=&l:tw setl tw=0 endfunction function UnMapFlow() unmap <buffer> <silent> j unmap <buffer> <silent> k unmap <buffer> <silent> 0 unmap <buffer> <silent> ^ unmap <buffer> <silent> $ if exists('b:old_textwidth') exec 'setl tw=' . b:old_textwidth endif endfunction command MapFlow :call MapFlow() command UnMapFlow :call UnMapFlow() command MF :call MapFlow() command UMF :call UnMapFlow()
代码: 全选
set textwidth=78