blob: e4abf0534de70df5ecf04ab54bbfac3ffcc4a72e [file] [log] [blame]
Bram Moolenaarcfa8f9a2022-06-03 21:59:47 +01001*usr_50.txt* For Vim version 8.2. Last change: 2022 Jun 03
Bram Moolenaar30ab04e2022-05-14 13:33:50 +01002
3 VIM USER MANUAL - by Bram Moolenaar
4
5 Advanced Vim script writing
6
7
Bram Moolenaarcfa8f9a2022-06-03 21:59:47 +01008|50.1| Line continuation
9|50.2| Restoring the view
Bram Moolenaar30ab04e2022-05-14 13:33:50 +010010
11 Next chapter: |usr_51.txt| Create a plugin
12 Previous chapter: |usr_45.txt| Select your language (local)
13Table of contents: |usr_toc.txt|
14
15==============================================================================
Bram Moolenaarcfa8f9a2022-06-03 21:59:47 +010016*50.1* Line continuation
Bram Moolenaar30ab04e2022-05-14 13:33:50 +010017
Bram Moolenaarcfa8f9a2022-06-03 21:59:47 +010018In legacy Vim script line contination is done by preceding a contination line
19with a backslash: >
20 let mylist = [
21 \ 'one',
22 \ 'two',
23 \ ]
24
25This requires the 'cpo' option to exclude the "C" flag. Normally this is done
26by putting this at the start of the script: >
27 let s:save_cpo = &cpo
28 set cpo&vim
29
30And restore the option at the end of the script: >
31 let &cpo = s:save_cpo
32 unlet s:save_cpo
33
34A few more details can be found here: |line-continuation|.
35
36In |Vim9| script the backslash can still be used, but in most places it is not
37needed: >
38 var mylist = [
39 'one',
40 'two',
41 ]
42
43Also, the 'cpo' option does not need to be changed. See
44|vim9-line-continuation| for details.
45
46==============================================================================
47*50.2* Restoring the view
48
49Sometimes you want to make a change and go back to where the cursor was.
50Restoring the relative position would also be nice, so that the same line
51appears at the top of the window.
52
53This example yanks the current line, puts it above the first line in the file
54and then restores the view: >
55
56 map ,p ma"aYHmbgg"aP`bzt`a
57
58What this does: >
59 ma"aYHmbgg"aP`bzt`a
60< ma set mark a at cursor position
61 "aY yank current line into register a
62 Hmb go to top line in window and set mark b there
63 gg go to first line in file
64 "aP put the yanked line above it
65 `b go back to top line in display
66 zt position the text in the window as before
67 `a go back to saved cursor position
68
Bram Moolenaar30ab04e2022-05-14 13:33:50 +010069
70==============================================================================
71
72Next chapter: |usr_51.txt| Create a plugin
73
74Copyright: see |manual-copyright| vim:tw=78:ts=8:noet:ft=help:norl: