visual-line-mode and evil

Frank Fischer frank.fischer at mathematik.tu-chemnitz.de
Mon Nov 14 16:58:58 CET 2011


On Mon, Nov 14, 2011 at 01:54:38PM +0100, Titus von der Malsburg wrote:
> Hi list,
> 
> I'm using visual-line-mode and like it very much (no more M-q or
> gqap).  However, commands like dd now delete whole paragraphs instead
> of just the current line.  Also selecting lines in visual mode doesn't
> work as expected.  My question: is there a way to make evil behave in
> the usual way when using visual-line-mode?

This is an issue we are aware of and the answer is: Maybe. 

The problem is that it is not always clear what a certain visual
selection really selects when visual-line mode is activated.
Especially block visual state is problematic, e.g, when one selects a
certain block and types "c", the dynamic behavior of visual-line-mode
may readjust the line so that the insertion-points in the selected
lines are no longer aligned. Similarly yanking/pasting of yanked lines
difficult: when some line is yanked/deleted, should it be put into the
kill-ring as lines or a simple text? The former solution requires a
modification of the yanked text (insertion of newlines at appropriate
positions), the latter makes pasting those lines unexpected (they
would not be inserted as lines but as ordinary text, this "P" would
insert the text before point not in the line above point). A
consistent behavior probably requires appropriate yank-handlers.

That said, what you want is indeed possible but no trivial task. I
would postpone it to a later version of evil and not for the upcoming
1.0 release where we should focus on stability and correctness of the
current features.

In the meantime, you may test the following quick hack (mainly
untested) which (perhaps) implements the first approach:

(evil-define-text-object evil-line (count)
  "Move COUNT - 1 lines down."
  (list (save-excursion
	  (beginning-of-visual-line)
	  (point))
	(save-excursion
	  (beginning-of-visual-line (1+ (or count 1)))
	  (point))))
	  
Explanation: `evil-line' is a special motion which simply moves point
COUNT - 1 lines down. This motion used for each operator that is
invoked via a "double-character" command, i.e., dd, cc, == and so on.
The above redefinition makes `evil-line' (which is a line motion by
default) a special text-objects which covers COUNT - 1 visual lines.
But note that "dd" does not delete lines anymore but simple characters
which happen to contain full lines. This means "P" and "p" do not
paste above/below the current line but before/after point.

Frank



More information about the implementations-list mailing list