开发者

vim: delete display lines instead of physical lines

When vim wraps long lines between words regular movements like j and k will jump from one physical line to the next. Mappings like "nnoremap j gj" as suggested here will do 开发者_JS百科the trick of moving the cursor by display lines instead of physical lines.

There's at least one problem with this approach though. For example, dj will delete two physical lines instead of two display lines.

Is there a way to fix this?


dd and yy:

:nnoremap dd g0dg$
:nnoremap yy g0yg$


Yes. Just use

:noremap j gj

instead of its version with two "n"-s. Unless you want the mapping work in visual mode as well, you may achieve the desired behavior with two mappings:

:nnoremap j gj
:onoremap j gj

Simulation of dd behavior is quite tricky, and I couldn't do this. This command means "delete current line linewise and put it in a linewise register". The following was my closest attempt, but it requires much trickier text processing:

:nnoremap dd g^dg$:call setreg(v:register,'','al')<BR>

(again, this doesn't work, but may point you to a helpful direction).

You may also be interested in the relevant help section:

:h map-modes


If you want dd and yy to only work on display lines, you would need to use the following mappings:

:nnoremap dd dg$
:nnoremap yy yg$
:nnoremap D dg$
:nnoremap Y 0yg$
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜