tags:

views:

193

answers:

3

When vim wrap 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 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?

+4  A: 

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
Pavel Shved
`noremap` partially solved the problem. The cursor moves by display lines and even `dj` works as I expected. The problem that remains is that commands like `dd` or `yy` deletes or yanks the entire physical line and not the display line.
Pablo
+2  A: 

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$
too much php
It works fine, but the mapping will only emulate `dd` behavior if the cursor is at the first column of the display line. Otherwise it will behave as `d$`.
Pablo
+3  A: 

dd and yy:

:nnoremap dd g0dg$
:nnoremap yy g0yg$
Jacques Viviers
Brilliant! It works just right.
Pablo