2022-06-03 21:59:47 +01:00
|
|
|
*usr_50.txt* For Vim version 8.2. Last change: 2022 Jun 03
|
2022-05-14 13:33:50 +01:00
|
|
|
|
|
|
|
|
VIM USER MANUAL - by Bram Moolenaar
|
|
|
|
|
|
|
|
|
|
Advanced Vim script writing
|
|
|
|
|
|
|
|
|
|
|
2022-06-03 21:59:47 +01:00
|
|
|
|50.1| Line continuation
|
|
|
|
|
|50.2| Restoring the view
|
2022-05-14 13:33:50 +01:00
|
|
|
|
|
|
|
|
Next chapter: |usr_51.txt| Create a plugin
|
|
|
|
|
Previous chapter: |usr_45.txt| Select your language (local)
|
|
|
|
|
Table of contents: |usr_toc.txt|
|
|
|
|
|
|
|
|
|
|
==============================================================================
|
2022-06-03 21:59:47 +01:00
|
|
|
*50.1* Line continuation
|
|
|
|
|
|
2022-06-06 20:52:59 +01:00
|
|
|
In legacy Vim script line continuation is done by preceding a continuation
|
|
|
|
|
line with a backslash: >
|
2022-06-03 21:59:47 +01:00
|
|
|
let mylist = [
|
|
|
|
|
\ 'one',
|
|
|
|
|
\ 'two',
|
|
|
|
|
\ ]
|
|
|
|
|
|
|
|
|
|
This requires the 'cpo' option to exclude the "C" flag. Normally this is done
|
|
|
|
|
by putting this at the start of the script: >
|
|
|
|
|
let s:save_cpo = &cpo
|
|
|
|
|
set cpo&vim
|
|
|
|
|
|
|
|
|
|
And restore the option at the end of the script: >
|
|
|
|
|
let &cpo = s:save_cpo
|
|
|
|
|
unlet s:save_cpo
|
|
|
|
|
|
|
|
|
|
A few more details can be found here: |line-continuation|.
|
|
|
|
|
|
|
|
|
|
In |Vim9| script the backslash can still be used, but in most places it is not
|
|
|
|
|
needed: >
|
|
|
|
|
var mylist = [
|
|
|
|
|
'one',
|
|
|
|
|
'two',
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
Also, the 'cpo' option does not need to be changed. See
|
|
|
|
|
|vim9-line-continuation| for details.
|
|
|
|
|
|
|
|
|
|
==============================================================================
|
|
|
|
|
*50.2* Restoring the view
|
|
|
|
|
|
|
|
|
|
Sometimes you want to make a change and go back to where the cursor was.
|
|
|
|
|
Restoring the relative position would also be nice, so that the same line
|
|
|
|
|
appears at the top of the window.
|
|
|
|
|
|
|
|
|
|
This example yanks the current line, puts it above the first line in the file
|
|
|
|
|
and then restores the view: >
|
|
|
|
|
|
|
|
|
|
map ,p ma"aYHmbgg"aP`bzt`a
|
|
|
|
|
|
|
|
|
|
What this does: >
|
|
|
|
|
ma"aYHmbgg"aP`bzt`a
|
|
|
|
|
< ma set mark a at cursor position
|
|
|
|
|
"aY yank current line into register a
|
|
|
|
|
Hmb go to top line in window and set mark b there
|
|
|
|
|
gg go to first line in file
|
|
|
|
|
"aP put the yanked line above it
|
|
|
|
|
`b go back to top line in display
|
|
|
|
|
zt position the text in the window as before
|
|
|
|
|
`a go back to saved cursor position
|
2022-05-14 13:33:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
==============================================================================
|
|
|
|
|
|
|
|
|
|
Next chapter: |usr_51.txt| Create a plugin
|
|
|
|
|
|
|
|
|
|
Copyright: see |manual-copyright| vim:tw=78:ts=8:noet:ft=help:norl:
|