Patch 8.1.2231
Problem: Not easy to move to the middle of a text line.
Solution: Add the gM command. (Yasuhiro Matsumoto, closes #2070)
Files: 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
*** ../vim-8.1.2230/runtime/doc/index.txt 2019-08-21 14:36:29.395376065 +0200
--- runtime/doc/index.txt 2019-10-28 02:04:20.537523857 +0100
***************
*** 781,786 ****
--- 781,787 ----
|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
*** ../vim-8.1.2230/runtime/doc/motion.txt 2019-05-05 18:11:46.316590662 +0200
--- runtime/doc/motion.txt 2019-10-28 02:07:25.128745162 +0100
***************
*** 53,58 ****
--- 53,59 ----
|!| ! filter through an external program
|=| = filter through 'equalprg' or C-indenting if empty
|gq| gq text formatting
+ |gw| gw text formatting with no cursor movement
|g?| g? ROT13 encoding
|>| > shift right
|<| < shift left
***************
*** 226,231 ****
--- 227,238 ----
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
*** ../vim-8.1.2230/runtime/doc/quickref.txt 2019-09-09 22:04:19.362736959 +0200
--- runtime/doc/quickref.txt 2019-10-28 02:04:20.541523840 +0100
***************
*** 47,52 ****
--- 47,53 ----
|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
*** ../vim-8.1.2230/runtime/doc/usr_25.txt 2019-05-05 18:11:46.328590595 +0200
--- runtime/doc/usr_25.txt 2019-10-28 02:04:20.541523840 +0100
***************
*** 346,357 ****
g0 to first visible character in this line
g^ to first non-blank visible character in this line
! gm to middle of this line
g$ to last visible character in this line
! |<-- window -->|
! some long text, part of which is visible ~
! g0 g^ gm g$
BREAKING AT WORDS *edit-no-break*
--- 346,358 ----
g0 to first visible character in this line
g^ to first non-blank visible character in 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 in one line ~
! g0 g^ gm gM g$
BREAKING AT WORDS *edit-no-break*
*** ../vim-8.1.2230/src/normal.c 2019-10-18 20:53:30.697741631 +0200
--- src/normal.c 2019-10-28 02:10:31.483965000 +0100
***************
*** 5979,5984 ****
--- 5979,6002 ----
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. */
*** ../vim-8.1.2230/src/testdir/test_normal.vim 2019-10-28 00:42:17.645477101 +0100
--- src/testdir/test_normal.vim 2019-10-28 02:04:20.541523840 +0100
***************
*** 1733,1738 ****
--- 1733,1739 ----
set wrap listchars= sbr=
let lineA='abcdefghijklmnopqrstuvwxyz'
let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+ let lineC='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
$put =lineA
$put =lineB
***************
*** 1766,1774 ****
call assert_equal(15, col('.'))
call assert_equal('l', getreg(0))
" Test for gI
norm! gIfoo
! call assert_equal(['', 'fooabcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
" Test for gi
wincmd c
--- 1767,1796 ----
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(['', 'foo0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'], getline(1,'$'))
" Test for gi
wincmd c
*** ../vim-8.1.2230/src/version.c 2019-10-28 00:42:17.645477101 +0100
--- src/version.c 2019-10-28 02:11:11.479798152 +0100
***************
*** 743,744 ****
--- 743,746 ----
{ /* Add new patch number below this line */
+ /**/
+ 2231,
/**/
--
If someone questions your market projections, simply point out that your
target market is "People who are nuts" and "People who will buy any damn
thing". Nobody is going to tell you there aren't enough of those people
to go around.
(Scott Adams - The Dilbert principle)
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language --
http://www.Zimbu.org ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///