]> granicus.if.org Git - vim/commitdiff
patch 8.1.2231: not easy to move to the middle of a text line v8.1.2231
authorBram Moolenaar <Bram@vim.org>
Mon, 28 Oct 2019 01:13:05 +0000 (02:13 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 28 Oct 2019 01:13:05 +0000 (02:13 +0100)
Problem:    Not easy to move to the middle of a text line.
Solution:   Add the gM command. (Yasuhiro Matsumoto, closes #2070)

runtime/doc/index.txt
runtime/doc/motion.txt
runtime/doc/quickref.txt
runtime/doc/usr_25.txt
src/normal.c
src/testdir/test_normal.vim
src/version.c

index 6b7c82205245bf6f09a52b759d64338a3e5877a6..d6957f51283d087d245066ce3ada0952b2861637 100644 (file)
@@ -781,6 +781,7 @@ tag         char          note action in Normal mode        ~
 |gn|           gn            1,2  find the next match with the last used
                                   search pattern and Visually select it
 |gm|           gm              1  go to character at middle of the screenline
+|gM|           gM              1  go to character at middle of the text line
 |go|           go              1  cursor to byte N in the buffer
 |gp|           ["x]gp          2  put the text [from register x] after the
                                   cursor N times, leave the cursor after it
index f0935da0eba104eef008c17fbbecaf409edd0407..9ac460a7387efc200eed4328ee29dcbe2523c1b4 100644 (file)
@@ -1,4 +1,4 @@
-*motion.txt*    For Vim version 8.1.  Last change: 2019 Jun 02
+*motion.txt*    For Vim version 8.1.  Last change: 2019 Oct 28
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -227,6 +227,12 @@ g^                 When lines wrap ('wrap' on): To the first non-blank
 gm                     Like "g0", but half a screenwidth to the right (or as
                        much as possible).
 
+                                                       *gm* *gM*
+gM                     Like "g0", but to halfway the text of the line.
+                       With a count: to this percentage of text in the line.
+                       Thus "10gM" is near the start of the text and "90gM"
+                       is near the end of the text.
+
                                                        *g$* *g<End>*
 g$ or g<End>           When lines wrap ('wrap' on): To the last character of
                        the screen line and [count - 1] screen lines downward
index fa15bca8d8c6e3dbdca082cad7fe4d77a9e2b65e..76067f593473df767c70afad3223e96f06007696 100644 (file)
@@ -47,6 +47,7 @@ N is used to indicate an optional count that can be given before the command.
 |g$|   N  g$           to last character in screen line (differs from "$"
                           when lines wrap)
 |gm|      gm           to middle of the screen line
+|gM|      gM           to middle of the line
 |bar|  N  |            to column N (default: 1)
 |f|    N  f{char}      to the Nth occurrence of {char} to the right
 |F|    N  F{char}      to the Nth occurrence of {char} to the left
index 7f65a852e0f37057bc055ac1405751d18a1a8bb7..1f71f3e356bbe3846ad1d43813d6dea82434f41c 100644 (file)
@@ -346,12 +346,13 @@ scroll:
 
        g0              to first visible character in this line
        g^              to first non-blank visible character in this line
-       gm              to middle of this line
+       gm              to middle of screen line
+       gM              to middle of the text in this line
        g$              to last visible character in this line
 
-               |<--     window    -->|
-       some long    text, part of which is visible ~
-                g0  g^    gm        g$
+               |<--      window     -->|
+       some long    text, part of which is visible in one line ~
+                g0  g^    gm      gM g$
 
 
 BREAKING AT WORDS                              *edit-no-break*
index f66a97c34b9e53f854fcde135d69f978bbc73a49..17db06a16766ac27d28b195dad71768991b0ba37 100644 (file)
@@ -5979,6 +5979,24 @@ nv_g_cmd(cmdarg_T *cap)
        curwin->w_set_curswant = TRUE;
        break;
 
+    case 'M':
+       {
+           char_u  *ptr = ml_get_curline();
+
+           oap->motion_type = MCHAR;
+           oap->inclusive = FALSE;
+           if (has_mbyte)
+               i = mb_string2cells(ptr, STRLEN(ptr));
+           else
+               i = (int)STRLEN(ptr);
+           if (cap->count0 > 0 && cap->count0 <= 100)
+               coladvance((colnr_T)(i * cap->count0 / 100));
+           else
+               coladvance((colnr_T)(i / 2));
+           curwin->w_set_curswant = TRUE;
+       }
+       break;
+
     case '_':
        /* "g_": to the last non-blank character in the line or <count> lines
         * downward. */
index b37f613edef14d3d307611d7b18562f97f383bb6..c4b38b1c6cc195ed6fac4349217dd7a3219ef5ac 100644 (file)
@@ -1733,6 +1733,7 @@ fun! Test_normal33_g_cmd2()
   set wrap listchars= sbr=
   let lineA='abcdefghijklmnopqrstuvwxyz'
   let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+  let lineC='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
   $put =lineA
   $put =lineB
 
@@ -1766,9 +1767,30 @@ fun! Test_normal33_g_cmd2()
   call assert_equal(15, col('.'))
   call assert_equal('l', getreg(0))
 
+  norm! 2ggdd
+  $put =lineC
+
+  " Test for gM
+  norm! gMyl
+  call assert_equal(73, col('.'))
+  call assert_equal('0', getreg(0))
+  " Test for 20gM
+  norm! 20gMyl
+  call assert_equal(29, col('.'))
+  call assert_equal('S', getreg(0))
+  " Test for 60gM
+  norm! 60gMyl
+  call assert_equal(87, col('.'))
+  call assert_equal('E', getreg(0))
+
+  " Test for g Ctrl-G
+  set ff=unix
+  let a=execute(":norm! g\<c-g>")
+  call assert_match('Col 87 of 144; Line 2 of 2; Word 1 of 1; Byte 88 of 146', a)
+
   " Test for gI
   norm! gIfoo
-  call assert_equal(['', 'fooabcdefghijk   lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
+  call assert_equal(['', 'foo0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'], getline(1,'$'))
 
   " Test for gi
   wincmd c
index 07a8cd9e514bb11f6978de6a7d289f684eabc460..99f15701b5a8dfbc01bbea4ba7d6edd2d8960b09 100644 (file)
@@ -741,6 +741,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2231,
 /**/
     2230,
 /**/