The attached patch enhances the behaviour of CTRL-W_CTRL-_ in visual mode.

If CTRL-W_CTRL-_ is pressed in visual mode, Vim will try to change the
height of the current window to match the visual selection and scroll
the text so that all of the selection is visible.

I didn't know whether to document it in visual.txt or window.txt...
Left it in window.txt along with documentation for the original
CTRL-W_CTRL-_.

-- 
Cheers,
Lech

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

diff --git a/src/window.c b/src/window.c
index 81caee9..2324007 100644
--- a/src/window.c
+++ b/src/window.c
@@ -456,7 +456,27 @@ newwindow:
 #ifdef FEAT_GUI
 		need_mouse_correct = TRUE;
 #endif
-		win_setheight(Prenum ? (int)Prenum : 9999);
+#ifdef FEAT_VISUAL
+		if (VIsual_active)
+		{
+		    pos_T *start, *end;
+		    if (ltoreq(VIsual, curwin->w_cursor))
+		    {
+			start = &VIsual;
+			end = &curwin->w_cursor;
+		    }
+		    else
+		    {
+			start = &curwin->w_cursor;
+			end = &VIsual;
+		    }
+		    win_setheight(1 + (end->lnum - start->lnum));
+		    set_topline(curwin, start->lnum);
+		    reset_VIsual();
+		}
+		else
+#endif
+		    win_setheight(Prenum ? (int)Prenum : 9999);
 		break;
 
 #ifdef FEAT_VERTSPLIT
diff -Nacr vim7_runtime_orig/doc/windows.txt vim7_runtime/doc/windows.txt
*** vim7_runtime_orig/doc/windows.txt	2009-03-22 20:39:46.000000000 +0100
--- vim7_runtime/doc/windows.txt	2009-03-28 15:54:18.000000000 +0100
***************
*** 469,476 ****
  		If used after 'vertical': increase width by N.
  
  :res[ize] [N]
! CTRL-W CTRL-_					*CTRL-W_CTRL-_* *CTRL-W__*
  CTRL-W _	Set current window height to N (default: highest possible).
  
  z{nr}<CR>	Set current window height to {nr}.
  
--- 469,480 ----
  		If used after 'vertical': increase width by N.
  
  :res[ize] [N]
! CTRL-W CTRL-_		*CTRL-W_CTRL-_* *CTRL-W__* *v_CTRL-W_CTRL-_*  *v_CTRL-W__*
  CTRL-W _	Set current window height to N (default: highest possible).
+ 		If performed when visual mode is on, try to set the height of
+ 		the window to the number of lines of visual selection and try
+ 		to fit the visual selection in the window. Note that it will
+ 		not work correctly when 'scrolloff' is non-zero.
  
  z{nr}<CR>	Set current window height to {nr}.
  

Raspunde prin e-mail lui