From ef02f16609ff0a26ffc6e20263523424980898fe Mon Sep 17 00:00:00 2001
From: Bram Moolenaar <Bram@vim.org>
Date: Sat, 7 May 2022 10:49:10 +0100
Subject: [PATCH] patch 8.2.4899: with latin1 encoding CTRL-W might go before
 the cmdline

Problem:    With latin1 encoding CTRL-W might go before the start of the
command line.
Solution:   Check already being at the start of the command line.
---
 src/ex_getln.c               | 11 +++++++----
 src/testdir/test_cmdline.vim |  3 +++
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/ex_getln.c b/src/ex_getln.c
index 68b4757..771a9cd 100644
--- a/src/ex_getln.c
+++ b/src/ex_getln.c
@@ -1583,10 +1583,13 @@ getcmdline_int(
 		    {
 			while (p > ccline.cmdbuff && vim_isspace(p[-1]))
 			    --p;
-			i = vim_iswordc(p[-1]);
-			while (p > ccline.cmdbuff && !vim_isspace(p[-1])
-				&& vim_iswordc(p[-1]) == i)
-			    --p;
+			if (p > ccline.cmdbuff)
+			{
+				i = vim_iswordc(p[-1]);
+				while (p > ccline.cmdbuff && !vim_isspace(p[-1])
+					&& vim_iswordc(p[-1]) == i)
+			 	   --p;
+			}
 		    }
 		    else
 			--p;
diff --git a/src/testdir/test_cmdline.vim b/src/testdir/test_cmdline.vim
index cbf7986..1ccdbe2 100644
--- a/src/testdir/test_cmdline.vim
+++ b/src/testdir/test_cmdline.vim
@@ -476,6 +476,9 @@ func Test_cmdline_remove_char()
 
     call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
     call assert_equal('"def', @:, e)
+
+    " This was going before the start in latin1.
+    call feedkeys(": \<C-W>\<CR>", 'tx')
   endfor
 
   let &encoding = encoding_save
-- 
1.8.3.1

