|
1 | 1 | # vim9-conversion-aid
|
2 | 2 |
|
3 |
| -A little help for upgrading to Vim9. |
4 |
| - |
5 |
| -The tool is nothing but an aid to convert legacy Vim scripts to Vim 9 |
6 |
| -language. |
7 |
| - |
8 |
| -<!-- It does not make miracles, nor it is bullet proof, it is certainly --> |
9 |
| -<!-- buggy and have a questionable design, but it may help you in speeding up the --> |
10 |
| -<!-- conversion process. --> |
11 |
| - |
12 |
| -It does not make miracles, nor it is bullet proof, but it may help you in |
13 |
| -speeding up the conversion process. |
14 |
| - |
15 |
| -What it is supposed to do: |
| 3 | +A little help for upgrading to Vim9 by converting legacy Vim to Vim 9 |
| 4 | +script. |
| 5 | +No miracles, nor bullet proof, but giving a head start in the conversion process by a `:Vim9Convert` (that operates either on the current or supplied buffer) command to |
16 | 6 |
|
17 | 7 | - replace all occurrences of `func`, `function`, etc. with `def` and `enddef`,
|
18 | 8 | - replace comment string `"` with `#`,
|
19 | 9 | - replace `v:true, v:false` with `true, false`,
|
20 | 10 | - add leading/trailing space to `=` and to comparison signs as needed,
|
21 |
| -- Remove line continuation symbol `\`, |
22 |
| -- ... and more. |
| 11 | +- remove line continuation symbol `\`, |
| 12 | +- ... and so much more. |
23 | 13 |
|
24 |
| -There is only one command available which is `Vim9Convert` that takes a buffer |
25 |
| -as optional arguments. |
| 14 | +## Caveats |
26 | 15 |
|
27 |
| -The various `let` around won't be converted automatically, you have to set |
28 |
| -`g:vim9_conversion_aid_fix_let = true`. However, this feature **fix the |
29 |
| -variables definitions, but not their usage.** For example, if at script level |
30 |
| -you have the following statement: |
| 16 | +The `let` commands won't be converted automatically unless you set `g:vim9_conversion_aid_fix_let = true`, though rather **fix the |
| 17 | +variables definitions, but not their usage.** |
31 | 18 |
|
| 19 | +For example, if at script level you have the following statement: |
32 | 20 | ```
|
33 | 21 | let newdict = CreateDict()
|
34 | 22 | call PrintDictContent(newdict)
|
35 | 23 | ```
|
36 |
| - |
37 |
| -it will be converted to the following: |
38 |
| - |
| 24 | +then it will be converted to the following: |
39 | 25 | ```
|
40 | 26 | g:newdict = CreateDict()
|
41 | 27 | PrintDictContent(newdict)
|
42 | 28 | ```
|
| 29 | +That is, the argument to the function call shall be manually fixed. |
| 30 | + |
| 31 | +Finally, in a similar vein, neither are `a:`, `l:` and `s:` removed automatically. |
| 32 | + |
| 33 | +This way, you can better inspect if your script semantic is still valid. |
| 34 | +Once done inspecting, run a simple `:%s/\v(a:|s:|l:)//g`. |
| 35 | + |
| 36 | +Or, if you still prefer that to happen automatically, you can set `g:vim9_conversion_aid_fix_asl = true`. |
| 37 | + |
| 38 | +## Usage |
| 39 | + |
| 40 | +<!-- It is recommended to use the tool with a clean `.vimrc` file. --> |
| 41 | +<!-- That is, you can start Vim with `vim --clean` and then source the plugin manually (e.g. `:source /path/to/vim9-conversion-aid/plugin/vim9-conversion-aid.vim` or you can just download the `vim9-conversion-aid.vim` file and source it), and then use `Vim9Convert`. --> |
| 42 | + |
| 43 | +The converted file will most likely have errors, but the error messages should tell you what shall be fixed and how. |
| 44 | +Also, mind that `:h vim9` can be a great support for fixing the remaining errors if you really don't know how. |
| 45 | + |
| 46 | +You can line-by-line compare the old and converted script by opening them next to each other and running `windo setlocal scrollbind diffthis`. |
| 47 | + |
| 48 | +## Testing |
| 49 | + |
| 50 | +To see how the tool perform the upgrade you can take a look at the `./test/test_script.vim` and `./test/expected_script.vim` scripts. |
43 | 51 |
|
44 |
| -i.e. the argument to the function call shall be manually fixed. |
45 |
| - |
46 |
| -Finally, `a:, l:` and `s:` are not removed automatically. In this way you can |
47 |
| -better inspect if your script semantic is still valid. You can run a simple |
48 |
| -`:%s/\v(a:|s:|l:)//g` once done or, if you want that to happen automatically, |
49 |
| -you can set `g:vim9_conversion_aid_fix_asl = true`. |
50 |
| - |
51 |
| -It is recommended to use the tool with a clean `.vimrc` file. That is, you can |
52 |
| -start Vim with `vim --clean` and then source the plugin manually (e.g. |
53 |
| -`:source /path/to/vim9-conversion-aid/plugin/vim9-conversion-aid.vim` or you |
54 |
| -can just download the `vim9-conversion-aid.vim` file and source it), and then |
55 |
| -use `Vim9Convert`. |
56 |
| - |
57 |
| -The converted file will most likely have errors, but the error messages should |
58 |
| -tell you what shall be fixed and how. Also, mind that `:h vim9` can be a great |
59 |
| -support for fixing the remaining errors if you really don't know how. |
60 |
| - |
61 |
| -Finally, if you add a couple of lines on top of your legacy script, then you |
62 |
| -can perform an eye-candy line-by-line comparison between the old and the |
63 |
| -converted script. (Tip: use `:set scrollbind` or `:diffthis` on both buffers.) |
64 |
| - |
65 |
| -To see how the tool perform the upgrade you can take a look at the |
66 |
| -`./test/test_script.vim` and `./test/expected_script.vim` scripts. As you will |
67 |
| -see, some manual work is still required, but the starting point is rather |
68 |
| -favorable compared to starting from scratch. Note that |
69 |
| -`./test/test_script.vim` does not do anything special, it has been written |
70 |
| -with the sole purpose of hitting a reasonable amount of corners. |
| 52 | +As you will see, some manual work is still required, but the starting point is rather favorable compared to starting from scratch. |
| 53 | +Note that `./test/test_script.vim` does not do anything special, it has been written with the sole purpose of hitting a reasonable amount of corners. |
71 | 54 |
|
72 | 55 | ## Limitations
|
73 | 56 |
|
|
0 commit comments