changeset 11573:c8fd52807897 v8.0.0669

patch 8.0.0669: CTRL-N at start of the buffer does not work correctly commit https://github.com/vim/vim/commit/24a9e348aa88a6c60ae0cdf5c4a777d8c03b08ca Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jun 24 15:39:07 2017 +0200 patch 8.0.0669: CTRL-N at start of the buffer does not work correctly Problem: In Insert mode, CTRL-N at start of the buffer does not work correctly. (zuloloxi) Solution: Wrap around the start of the buffer. (Christian Brabandt)
author Christian Brabandt <cb@256bit.org>
date Sat, 24 Jun 2017 15:45:04 +0200
parents 4f9d321dbd2b
children 9a74b20327e4
files src/edit.c src/testdir/test_popup.vim src/version.c
diffstat 3 files changed, 27 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/edit.c
+++ b/src/edit.c
@@ -4308,9 +4308,17 @@ ins_compl_get_exp(pos_T *ini)
 	    {
 		ins_buf = curbuf;
 		first_match_pos = *ini;
-		/* So that ^N can match word immediately after cursor */
-		if (ctrl_x_mode == 0)
-		    dec(&first_match_pos);
+		/* Move the cursor back one character so that ^N can match the
+		 * word immediately after the cursor. */
+		if (ctrl_x_mode == 0 && dec(&first_match_pos) < 0)
+		{
+		    /* Move the cursor to after the last character in the
+		     * buffer, so that word at start of buffer is found
+		     * correctly. */
+		    first_match_pos.lnum = ins_buf->b_ml.ml_line_count;
+		    first_match_pos.col =
+				 (colnr_T)STRLEN(ml_get(first_match_pos.lnum));
+		}
 		last_match_pos = first_match_pos;
 		type = 0;
 
--- a/src/testdir/test_popup.vim
+++ b/src/testdir/test_popup.vim
@@ -612,5 +612,19 @@ func Test_complete_func_mess()
   set completefunc=
 endfunc
 
+func Test_complete_CTRLN_startofbuffer()
+  new
+  call setline(1, [ 'organize(cupboard, 3, 2);',
+        \ 'prioritize(bureau, 8, 7);',
+        \ 'realize(bannister, 4, 4);',
+        \ 'moralize(railing, 3,9);'])
+  let expected=['cupboard.organize(3, 2);',
+        \ 'bureau.prioritize(8, 7);',
+        \ 'bannister.realize(4, 4);',
+        \ 'railing.moralize(3,9);']
+  call feedkeys("qai\<c-n>\<c-n>.\<esc>3wdW\<cr>q3@a", 'tx')
+  call assert_equal(expected, getline(1,'$'))
+  bwipe!
+endfunc
 
 " vim: shiftwidth=2 sts=2 expandtab
--- a/src/version.c
+++ b/src/version.c
@@ -765,6 +765,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    669,
+/**/
     668,
 /**/
     667,