@@ -111,9 +111,19 @@ use CTRL-G u. This is useful if you want an insert command to be undoable in
111
111
parts. E.g., for each sentence. | i_CTRL-G_u |
112
112
113
113
Setting the value of 'undolevels' also closes the undo block. Even when the
114
- new value is equal to the old value. In | Vim9 | script: >
115
- &undolevels = &undolevels
114
+ new value is equal to the old value. Use `g: undolevels ` to explicitly read
115
+ and write only the global value of 'undolevels' . In | Vim9 | script: >
116
+ &g:undolevels = &g:undolevels
116
117
In legacy script: >
118
+ let &g:undolevels = &g:undolevels
119
+
120
+ Note that the similar-looking assignment `let &undolevels=&undolevels` does not
121
+ preserve the global option value of 'undolevels' in the event that the local
122
+ option has been set to a different value. For example: >
123
+ " Start with different global and local values for 'undolevels'.
124
+ let &g:undolevels = 1000
125
+ let &l:undolevels = 2000
126
+ " This assignment changes the global option to 2000:
117
127
let &undolevels = &undolevels
118
128
119
129
==============================================================================
@@ -366,12 +376,20 @@ undo is possible. Use this if you are running out of memory.
366
376
When you set 'undolevels' to -1 the undo information is not immediately
367
377
cleared, this happens at the next change. To force clearing the undo
368
378
information you can use these commands: >
369
- :let old_undolevels = &undolevels
370
- :set undolevels=-1
379
+ :let old_undolevels = &l: undolevels
380
+ :setlocal undolevels=-1
371
381
:exe "normal a \<BS>\<Esc>"
372
- :let &undolevels = old_undolevels
382
+ :let &l: undolevels = old_undolevels
373
383
:unlet old_undolevels
374
384
385
+ Note use of `&l: undolevels ` to explicitly read the local value of 'undolevels'
386
+ and the use of `:setlocal ` to change only the local option (which takes
387
+ precedence over the corresponding global option value). Saving the option value
388
+ via the use of `&undolevels ` is unpredictable; it reads either the local value
389
+ (if one has been set) or the global value (otherwise). Also, if a local value
390
+ has been set, changing the option via `:set undolevels` will change both the
391
+ global and local values, requiring extra work to save and restore both values.
392
+
375
393
Marks for the buffer ('a to 'z) are also saved and restored, together with the
376
394
text.
377
395
0 commit comments