@@ -177,17 +177,22 @@ getcmdline(
177177 int histype ; /* history type to be used */
178178#endif
179179#ifdef FEAT_SEARCH_EXTRA
180- pos_T old_cursor ;
180+ pos_T search_start ; /* where 'incsearch' starts searching */
181+ pos_T save_cursor ;
181182 colnr_T old_curswant ;
183+ colnr_T init_curswant = curwin -> w_curswant ;
182184 colnr_T old_leftcol ;
185+ colnr_T init_leftcol = curwin -> w_leftcol ;
183186 linenr_T old_topline ;
184- pos_T cursor_start ;
187+ linenr_T init_topline = curwin -> w_topline ;
185188 pos_T match_start = curwin -> w_cursor ;
186189 pos_T match_end ;
187190# ifdef FEAT_DIFF
188191 int old_topfill ;
192+ int init_topfill = curwin -> w_topfill ;
189193# endif
190194 linenr_T old_botline ;
195+ linenr_T init_botline = curwin -> w_botline ;
191196 int did_incsearch = FALSE;
192197 int incsearch_postponed = FALSE;
193198#endif
@@ -230,8 +235,8 @@ getcmdline(
230235 ccline .overstrike = FALSE; /* always start in insert mode */
231236#ifdef FEAT_SEARCH_EXTRA
232237 clearpos (& match_end );
233- old_cursor = curwin -> w_cursor ; /* needs to be restored later */
234- cursor_start = old_cursor ;
238+ save_cursor = curwin -> w_cursor ; /* may be restored later */
239+ search_start = curwin -> w_cursor ;
235240 old_curswant = curwin -> w_curswant ;
236241 old_leftcol = curwin -> w_leftcol ;
237242 old_topline = curwin -> w_topline ;
@@ -1006,11 +1011,17 @@ getcmdline(
10061011 ccline .cmdbuff [ccline .cmdlen ] = NUL ;
10071012#ifdef FEAT_SEARCH_EXTRA
10081013 if (ccline .cmdlen == 0 )
1009- old_cursor = cursor_start ;
1010- else
10111014 {
1012- old_cursor = match_start ;
1013- decl (& old_cursor );
1015+ search_start = save_cursor ;
1016+ /* save view settings, so that the screen
1017+ * won't be restored at the wrong position */
1018+ old_curswant = init_curswant ;
1019+ old_leftcol = init_leftcol ;
1020+ old_topline = init_topline ;
1021+ # ifdef FEAT_DIFF
1022+ old_topfill = init_topfill ;
1023+ # endif
1024+ old_botline = init_botline ;
10141025 }
10151026#endif
10161027 redrawcmd ();
@@ -1040,7 +1051,7 @@ getcmdline(
10401051 }
10411052#ifdef FEAT_SEARCH_EXTRA
10421053 if (ccline .cmdlen == 0 )
1043- old_cursor = cursor_start ;
1054+ search_start = save_cursor ;
10441055#endif
10451056 redraw_cmdline = TRUE;
10461057 goto returncmd ; /* back to cmd mode */
@@ -1127,7 +1138,7 @@ getcmdline(
11271138 ccline .cmdbuff [ccline .cmdlen ] = NUL ;
11281139#ifdef FEAT_SEARCH_EXTRA
11291140 if (ccline .cmdlen == 0 )
1130- old_cursor = cursor_start ;
1141+ search_start = save_cursor ;
11311142#endif
11321143 redrawcmd ();
11331144 goto cmdline_changed ;
@@ -1476,7 +1487,7 @@ getcmdline(
14761487 if (did_incsearch )
14771488 {
14781489 curwin -> w_cursor = match_end ;
1479- if (!equalpos (curwin -> w_cursor , old_cursor ))
1490+ if (!equalpos (curwin -> w_cursor , search_start ))
14801491 {
14811492 c = gchar_cursor ();
14821493 /* If 'ignorecase' and 'smartcase' are set and the
@@ -1665,9 +1676,9 @@ getcmdline(
16651676#endif
16661677 goto cmdline_not_changed ;
16671678
1679+ #ifdef FEAT_SEARCH_EXTRA
16681680 case Ctrl_G : /* next match */
16691681 case Ctrl_T : /* previous match */
1670- #ifdef FEAT_SEARCH_EXTRA
16711682 if (p_is && !cmd_silent && (firstc == '/' || firstc == '?' ))
16721683 {
16731684 pos_T t ;
@@ -1693,25 +1704,25 @@ getcmdline(
16931704 -- emsg_off ;
16941705 if (i )
16951706 {
1696- old_cursor = match_start ;
1707+ search_start = match_start ;
16971708 match_end = t ;
16981709 match_start = t ;
16991710 if (c == Ctrl_T && firstc == '/' )
17001711 {
17011712 /* move just before the current match, so that
17021713 * when nv_search finishes the cursor will be
17031714 * put back on the match */
1704- old_cursor = t ;
1705- (void )decl (& old_cursor );
1715+ search_start = t ;
1716+ (void )decl (& search_start );
17061717 }
1707- if (lt (t , old_cursor ) && c == Ctrl_G )
1718+ if (lt (t , search_start ) && c == Ctrl_G )
17081719 {
17091720 /* wrap around */
1710- old_cursor = t ;
1721+ search_start = t ;
17111722 if (firstc == '?' )
1712- (void )incl (& old_cursor );
1723+ (void )incl (& search_start );
17131724 else
1714- (void )decl (& old_cursor );
1725+ (void )decl (& search_start );
17151726 }
17161727
17171728 set_search_match (& match_end );
@@ -1732,8 +1743,9 @@ getcmdline(
17321743 }
17331744 else
17341745 vim_beep (BO_ERROR );
1746+ goto cmdline_not_changed ;
17351747 }
1736- goto cmdline_not_changed ;
1748+ break ;
17371749#endif
17381750
17391751 case Ctrl_V :
@@ -1877,7 +1889,7 @@ getcmdline(
18771889 continue ;
18781890 }
18791891 incsearch_postponed = FALSE;
1880- curwin -> w_cursor = old_cursor ; /* start at old position */
1892+ curwin -> w_cursor = search_start ; /* start at old position */
18811893
18821894 /* If there is no command line, don't do anything */
18831895 if (ccline .cmdlen == 0 )
@@ -1995,9 +2007,18 @@ getcmdline(
19952007#ifdef FEAT_SEARCH_EXTRA
19962008 if (did_incsearch )
19972009 {
1998- curwin -> w_cursor = old_cursor ;
19992010 if (gotesc )
2000- curwin -> w_cursor = cursor_start ;
2011+ curwin -> w_cursor = save_cursor ;
2012+ else
2013+ {
2014+ if (!equalpos (save_cursor , search_start ))
2015+ {
2016+ /* put the '" mark at the original position */
2017+ curwin -> w_cursor = save_cursor ;
2018+ setpcmark ();
2019+ }
2020+ curwin -> w_cursor = search_start ;
2021+ }
20012022 curwin -> w_curswant = old_curswant ;
20022023 curwin -> w_leftcol = old_leftcol ;
20032024 curwin -> w_topline = old_topline ;
@@ -2140,13 +2161,18 @@ text_locked(void)
21402161 */
21412162 void
21422163text_locked_msg (void )
2164+ {
2165+ EMSG (_ (get_text_locked_msg ()));
2166+ }
2167+
2168+ char_u *
2169+ get_text_locked_msg (void )
21432170{
21442171#ifdef FEAT_CMDWIN
21452172 if (cmdwin_type != 0 )
2146- EMSG (_ (e_cmdwin ));
2147- else
2173+ return e_cmdwin ;
21482174#endif
2149- EMSG ( _ ( e_secure )) ;
2175+ return e_secure ;
21502176}
21512177
21522178#if defined(FEAT_AUTOCMD ) || defined(PROTO )
0 commit comments