Skip to content

Commit 7f45e4d

Browse files
authored
Merge pull request #5 from Konfekt/main
simplify file tree and Readme
2 parents d564ef7 + b2fb9b3 commit 7f45e4d

File tree

5 files changed

+36
-79
lines changed

5 files changed

+36
-79
lines changed

README.md

Lines changed: 34 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,56 @@
11
# vim9-conversion-aid
22

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
166

177
- replace all occurrences of `func`, `function`, etc. with `def` and `enddef`,
188
- replace comment string `"` with `#`,
199
- replace `v:true, v:false` with `true, false`,
2010
- 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.
2313

24-
There is only one command available which is `Vim9Convert` that takes a buffer
25-
as optional arguments.
14+
## Caveats
2615

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.**
3118

19+
For example, if at script level you have the following statement:
3220
```
3321
let newdict = CreateDict()
3422
call PrintDictContent(newdict)
3523
```
36-
37-
it will be converted to the following:
38-
24+
then it will be converted to the following:
3925
```
4026
g:newdict = CreateDict()
4127
PrintDictContent(newdict)
4228
```
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.
4351

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.
7154

7255
## Limitations
7356

File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
vim9script
22

3-
import autoload '../../lib/vim9_convert_functions.vim' as vim9conv
3+
import autoload '../autoload/vim9_convert_functions.vim' as vim9conv
44
command! -nargs=? -complete=buffer -buffer Vim9Convert vim9conv.TransformBuffer(<f-args>)

plugin/vim9-conversion-aid.vim

Lines changed: 0 additions & 25 deletions
This file was deleted.

test/test_vim9_conversion_aid.vim

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ var WaitForAssert = common.WaitForAssert
88

99
var plugin_root = fnamemodify(getcwd(), ':h')
1010
&runtimepath = &runtimepath .. "," .. plugin_root
11-
&runtimepath = &runtimepath .. "," .. plugin_root .. "/after"
1211
filetype plugin on
13-
exe "source " .. plugin_root .. "/after/ftplugin/vim.vim"
12+
exe "source " .. plugin_root .. "/ftplugin/vim_9.vim"
1413

1514
# Tests start here
1615
def g:Test_converted_script()

0 commit comments

Comments
 (0)