From 18b7d86d7fa997bbb02a069dafacb32a0f73ca1e Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Wed, 17 Mar 2021 13:28:05 +0100 Subject: patch 8.2.2612: col('.') may get outdated column value Problem: col('.') may get outdated column value. Solution: Add a note to the help how to make this work and add a test for it. (closes #7971) --- runtime/doc/map.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'runtime') diff --git a/runtime/doc/map.txt b/runtime/doc/map.txt index bf391305dc..873d5d6d7a 100644 --- a/runtime/doc/map.txt +++ b/runtime/doc/map.txt @@ -263,6 +263,20 @@ input. Example: > endfunc nnoremap OpenPopup() +Also, keep in mind that the expression may be evaluated when looking for +typeahead, before the previous command has been executed. For example: > + func StoreColumn() + let g:column = col('.') + return 'x' + endfunc + nnoremap x StoreColumn() + nmap ! f!x +You will notice that g:column has the value from before executing "fx", +because "z" is evaluated before "fx" is executed. +This can be solved by inserting before the character that is +expression-mapped: > + nmap ! f!x + Be very careful about side effects! The expression is evaluated while obtaining characters, you may very well make the command dysfunctional. For this reason the following is blocked: -- cgit v1.2.3