[vim/vim] Add Chapter Two #5719 (#5729)

49 views
Skip to first unread message

Paul Desmond Parker

unread,
Mar 3, 2020, 9:06:31 AM3/3/20
to vim/vim, Subscribed

Add main English file runtime/tutor/tutor02

  • Lesson 8.1 The Named Registers
  • Lesson 8.2 The Expression Register
  • Lesson 8.3 The Numbered Registers
  • Lesson 8.4 The Beauty of Marks
  • Lesson 8 Summary
    Add copy of tutor02 at tutor02.utf-8
    Add source file tutor02.vim
  • coordinates translations
  • coordinates source for tmp copy
    Edit man page
  • add arguments
  • add Options
  • add Examples
  • trim description
    Edit main script src/vimtutor
  • add --list option
  • add --gui option
  • add -h, --help options
  • add -c, --chapter options
  • add -l, --language switches
  • add validations for languages and chapters
  • aimed at POSIX compliance

You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/5729

Commit Summary

  • Add Chapter Two #5719

File Changes

Patch Links:


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

Paul Desmond Parker

unread,
Mar 3, 2020, 9:10:10 AM3/3/20
to vim/vim, Subscribed

I made no attempt to modify vimtutor.bat to handle the second chapter. I could have copied to vimtutor2.bat and changed it trivially to work with chapter two; but... lipstick on a pig. It'll be better if someone familiar with dos bat files modifies vimtutor.bat to handle another cmdline argument.

Paul Desmond Parker

unread,
Mar 3, 2020, 8:55:41 PM3/3/20
to vim/vim, Push

@sunwukonga pushed 1 commit.


You are receiving this because you are subscribed to this thread.

View it on GitHub or unsubscribe.

Bram Moolenaar

unread,
Mar 4, 2020, 4:29:52 PM3/4/20
to vim/vim, Subscribed

Comments are welcome.

Nick Jensen

unread,
Mar 4, 2020, 5:01:33 PM3/4/20
to vim/vim, Subscribed

Lesson 8.2 does not work in Windows, where date by itself will expect input. However system('date /t') works to just output the date (on Windows 10 at least)

Nick Jensen

unread,
Mar 4, 2020, 5:10:02 PM3/4/20
to vim/vim, Subscribed

Lesson 8.3 includes a line that presumably should not be there, after point 5:

4. As each error is fixed press <ESC> to return to Normal mode

Also: NOTE: A whole line deletion stored in a named register is NOT also stored in the numbered registers. This is incorrect.

Paul Desmond Parker

unread,
Mar 4, 2020, 5:48:10 PM3/4/20
to vim/vim, Subscribed

Lesson 8.2 does not work in Windows, where date by itself will expect input. However system('date /t') works to just output the date (on Windows 10 at least)

Any suggestions for a system agnostic alternative, or just a NOTE: specifying the Windows specific behaviour?

Paul Desmond Parker

unread,
Mar 4, 2020, 5:49:39 PM3/4/20
to vim/vim, Subscribed
  1. As each error is fixed press to return to Normal mode
    [DELETING]

Also: NOTE: A whole line deletion stored in a named register is NOT also stored in the numbered registers. This is incorrect.

Oops. [DELETING]

Paul Desmond Parker

unread,
Mar 4, 2020, 5:54:42 PM3/4/20
to vim/vim, Subscribed

Also: NOTE: A whole line deletion stored in a named register is NOT also stored in the numbered registers. This is incorrect.

I didn't test this, but I also didn't guess at it either, my misapprehension came from this sentence under :h quote0

Numbered register 1 contains the text deleted by the most recent delete or
change command, unless the command specified another register or the text is
less than one line (the small delete register is used then).

Nick Jensen

unread,
Mar 4, 2020, 5:57:43 PM3/4/20
to vim/vim, Subscribed

Lesson 8.2 does not work in Windows, where date by itself will expect input. However system('date /t') works to just output the date (on Windows 10 at least)

Any suggestions for a system agnostic alternative, or just a NOTE: specifying the Windows specific behaviour?

I think making a NOTE: about the Windows behaviour would make sense. In this situtation users are presumably being exposed to Vim's integration with external tools for the first time, which will almost always require OS-specific tweaks. So a simple note to point out that system() and :r !... etc. are calling outside Vim seems like a good idea to me.

Paul Desmond Parker

unread,
Mar 4, 2020, 6:00:02 PM3/4/20
to vim/vim, Subscribed

[Question] Should I change the lesson numbering from 8.1 to 2.1.1 i.e. chapter.lesson.part. It would no longer be consistent with the original vimtutor numbering, but it would allow for much more flexibility in the future if the are multiple mutable chapters going forward.

Paul Desmond Parker

unread,
Mar 4, 2020, 6:26:00 PM3/4/20
to vim/vim, Push

@sunwukonga pushed 1 commit.

  • 3c47900 Remove incorrect statement about numbered registers


You are receiving this because you are subscribed to this thread.

Codecov

unread,
Mar 4, 2020, 6:48:22 PM3/4/20
to vim/vim, Subscribed

Codecov Report

Merging #5729 into master will increase coverage by 0.05%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@

##           master    #5729      +/-   ##

==========================================

+ Coverage   84.06%   84.11%   +0.05%     

==========================================

  Files         138      138              

  Lines      152376   152435      +59     

==========================================

+ Hits       128088   128225     +137     

+ Misses      24288    24210      -78
Impacted Files Coverage Δ
src/if_xcmdsrv.c 85.99% <0%> (-0.36%) ⬇️
src/gui_gtk_x11.c 58.06% <0%> (-0.25%) ⬇️
src/window.c 88.66% <0%> (-0.07%) ⬇️
src/term.c 81.34% <0%> (-0.06%) ⬇️
src/ops.c 89.65% <0%> (-0.05%) ⬇️
src/getchar.c 84.42% <0%> (-0.03%) ⬇️
src/if_python3.c 83.82% <0%> (ø) ⬆️
src/version.c 92.1% <0%> (ø) ⬆️
src/terminal.c 82.61% <0%> (+0.03%) ⬆️
src/gui.c 63.63% <0%> (+0.05%) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5381c7a...3c47900. Read the comment docs.

Bram Moolenaar

unread,
Mar 5, 2020, 4:56:35 AM3/5/20
to vim/vim, Subscribed

> > > Lesson 8.2 does not work in Windows, where `date` by itself will expect input. However `system('date /t')` works to just output the date (on Windows 10 at least)
> >
> > Any suggestions for a system agnostic alternative, or just a `NOTE:` specifying the Windows specific behaviour?
>
> I think making a `NOTE:` about the Windows behaviour would make sense.
> In this situtation users are presumably being exposed to Vim's
> integration with external tools for the first time, which will almost
> always require OS-specific tweaks. So a simple note to point out that
> `system()` and `:r !...` etc. are calling outside Vim seems like a
> good idea to me.

A higher level comment: Would it be possible to make multiple of these
tutor parts, and have a menu to select which one to take? Then we could
have a Windows specific one. We could also have one for specific
subjects, e.g. how to record and play back a macro.
The user would first do the main tutor, and then gets a menu to select
one of the advanced subjects.

Keep in mind that the tutor is interactive and is intended to "get
things in your fingers". Thus a section on writing Vim script is not a
good idea.

--
If Microsoft would build a car...
... Occasionally, executing a maneuver such as a left turn
would cause your car to shut down and refuse to restart, in
which case you would have to reinstall the engine.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Paul Desmond Parker

unread,
Mar 5, 2020, 5:41:35 AM3/5/20
to vim/vim, Subscribed

A higher level comment: Would it be possible to make multiple of these tutor parts, and have a menu to select which one to take?

Yes, the main tutor02 file could be spliced into sections along the lines of lesson parts with a generic part (linux) and then any number of variations (Windows, Plan9, etc), I imagine most sections would only need the generic section as they wouldn't touch anything system related. E.g. [tutor02-1, tutor_win02-1, tutor_osx2-1, etc]. The tutor02.vim script could select the appropriate sections based on the environment, concatenate, and copy to the temp file. It's not my place to be opinionated on this, but overall I feel it might a bridge too far UNLESS there is a serious intent to introduce content that is heavy on system calls.

We could also have one for specific subjects, e.g. how to record and play back a macro.

I already have lessons planned for macros, is there a system environment dependency I'm ignorant of?

The user would first do the main tutor, and then gets a menu to select one of the advanced subjects. Keep in mind that the tutor is interactive and is intended to "get things in your fingers". Thus a section on writing Vim script is not a good idea.

I agree.

Bram Moolenaar

unread,
Jun 7, 2020, 2:31:36 PM6/7/20
to vim/vim, Subscribed

I guess we are not going to have several parts. Even the second chapter may not grow much.
Therefore, to keep things simple, I propose to add the sections to the existing vimtutor, and use a kind of separator in between the parts. It would say something like "now you know the basics, you can quit and start using Vim, or you can continue and learn about some more advanced features".
We can even add a list of subjects, telling the user to use a search command to jump there. Hmm, this might be difficult to find, and we don't want to put at it the top. We could put the index at the bottom, so "G" takes the user there.

About the man page: the list of options at the top is hard to read. Why not just add [options] and mention them in a table further down.

Adam Stankiewicz

unread,
Jul 3, 2020, 10:34:57 AM7/3/20
to vim/vim, Subscribed

How about embedding vimtutor within vim and introducing :tutor command? This command could be mentioned on welcome screen of vim (e.g. Type :tutor to see Vim tutorial)

Bram Moolenaar

unread,
Jul 3, 2020, 12:08:53 PM7/3/20
to vim/vim, Subscribed

Moving the tutor-specific stuff into Vim would avoid the shell script and batch file - that helps.
The extra code won't be much. So that looks like a good direction to go in.
It would still be good to start the tutor from the command line. how about "vim --tutor" ?

Yegappan Lakshmanan

unread,
Jul 3, 2020, 12:13:41 PM7/3/20
to vim_dev, reply+ACY5DGF6DGYIC4QQ6I...@reply.github.com, vim/vim, Subscribed
Hi,

On Fri, Jul 3, 2020 at 9:08 AM Bram Moolenaar <vim-dev...@256bit.org> wrote:

Moving the tutor-specific stuff into Vim would avoid the shell script and batch file - that helps.
The extra code won't be much. So that looks like a good direction to go in.
It would still be good to start the tutor from the command line. how about "vim --tutor" ?


vim-dev ML

unread,
Jul 3, 2020, 12:14:00 PM7/3/20
to vim/vim, vim-dev ML, Your activity

Christian Brabandt

unread,
Nov 3, 2024, 2:50:16 PM11/3/24
to vim/vim, vim-dev ML, Comment

I am including this. It's a bit sad, that the new vimtutor shell script is no longer portable, but requires bash (so I changed that). I also made a few further enhancements so that we do not need a separate tutor02.vim file and made vimtutor.bat on Windows aware of a seperate chapter.

I hope I didn't brake anything. Please check it.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you commented.Message ID: <vim/vim/pull/5729/c2453556088@github.com>

Christian Brabandt

unread,
Nov 3, 2024, 2:55:37 PM11/3/24
to vim/vim, vim-dev ML, Comment

Closed #5729 via 17c71da.


Reply to this email directly, view it on GitHub.
You are receiving this because you commented.Message ID: <vim/vim/pull/5729/issue_event/15096250699@github.com>

Aliaksei Budavei

unread,
Nov 3, 2024, 6:06:30 PM11/3/24
to vim/vim, vim-dev ML, Comment

Would you like a POSIX shell port of vimtutor?

diff --git a/src/vimtutor b/src/vimtutor
index 3faf100b4..6e29a7602 100755
--- a/src/vimtutor
+++ b/src/vimtutor
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # Start Vim on a copy of the tutor file.
 
@@ -11,8 +11,7 @@
 
 # Vim could be called "vim" or "vi".  Also check for "vimN", for people who
 # have Vim installed with its version number.
-# We anticipate up to a future Vim 8.1 version :-).
-seq="vim vim81 vim80 vim8 vim74 vim73 vim72 vim71 vim70 vim7 vim6 vi"
+seq="vim vim91 vim90 vim81 vim80 vim8 vim74 vim73 vim72 vim71 vim70 vim7 vim6 vi"
 
 usage()
 {
@@ -31,94 +30,104 @@ usage()
 
 listOptions()
 {
-  declare -A language
-  language[bar]=Bavarian
-  language[bg]=Bulgarian
-  language[ca]=Catalan
-  language[cs]=Czech
-  language[da]=Danish
-  language[de]=German
-  language[el]=Greek
-  language[en]=English\(default\)
-  language[eo]=Esperanto
-  language[es]=Spanish
-  language[fr]=French
-  language[hr]=Croatian
-  language[hu]=Hungarian
-  language[it]=Italian
-  language[ja]=Japanese
-  language[ko]=Korean
-  language[lv]=Latvian
-  language[nb]=Bokmål
-  language[nl]=Dutch
-  language[no]=Norwegian
-  language[pl]=Polish
-  language[pt]=Portuguese
-  language[ru]=Russian
-  language[sk]=Slovak
-  language[sr]=Serbian
-  language[sv]=Swedish
-  language[tr]=Turkish
-  language[uk]=English
-  language[vi]=Vietnamese
-  language[zh]=Chinese
-
-  echo "==OPTIONS======================================================================================="
-  echo "Chapter: 1"
-  for code in bar bg ca cs da de el en eo es fr hr hu it ja ko lv nb nl no pl pt ru sk sr sv tr uk vi zh
-  do
-    printf "\tLang: %s => %s\n" ${code} ${language[${code}]}
-  done
-  echo "Chapter: 2"
-  for code in en
-  do
-    printf "\tLang: %s => %s\n" ${code} ${language[${code}]}
-  done
-  echo "================================================================================================"
+    echo "==OPTIONS======================================================================================="
+    echo "Chapter: 1"
+    printf "\tLang: %-3s => %s\n" \
+bar Bavarian \
+bg Bulgarian \
+ca Catalan \
+cs Czech \
+da Danish \
+de German \
+el Greek \
+en English\(default\) \
+eo Esperanto \
+es Spanish \
+fr French \
+hr Croatian \
+hu Hungarian \
+it Italian \
+ja Japanese \
+ko Korean \
+lv Latvian \
+nb Bokmål \
+nl Dutch \
+no Norwegian \
+pl Polish \
+pt Portuguese \
+ru Russian \
+sk Slovak \
+sr Serbian \
+sv Swedish \
+tr Turkish \
+uk English \
+vi Vietnamese \
+zh Chinese
+
+    echo "Chapter: 2"
+    printf "\tLang: %-3s => %s\n" \
+en English\(default\)
+    echo "================================================================================================"
 }
 
 validateLang()
 {
-  if [[ $xx =~ ^[^a-z]*$ ]]; then echo "Error: iso639 code must contain only [a-z]" && exit 1; fi
-  if [ ${#xx} == 2 ] || [ ${#xx} == 3 ]; then :; else echo "Error: iso639 code must be 2 or 3 characters only" && exit 1; fi
+  case "$xx" in
+    '' | *[!a-z]* )
+      echo "Error: iso639 code must contain only [a-z]"
+      exit 1
+  esac
+
+  case "${#xx}" in
+    [23] )
+      ;;
+    * )
+      echo "Error: iso639 code must be 2 or 3 characters only"
+      exit 1
+  esac
+
   export xx
 }
 
 validateChapter()
 {
-  if [[ $cc =~ ^[0-9]*$ ]]; then :; else echo "Error: chapter argument must contain digits only" && exit 1; fi
-  if [ $cc == "0" ]; then echo "Error: chapter must be non-zero" && exit 1; fi
-  if [ $cc == "00" ]; then echo "Error: chapter must be non-zero" && exit 1; fi
+  case "$cc" in
+    '' | *[!0-9]* )
+      echo "Error: chapter argument must contain digits only"
+      exit 1
+      ;;
+    0 | 00 )
+      echo "Error: chapter must be non-zero"
+      exit 1
+  esac
+
   export CHAPTER="$cc"
 }
 
-shopt -s extglob
 while [ "$1" != "" ]; do
-  case $1 in
+  case "$1" in
     -g | --gui )                    seq="gvim gvim91 gvim90 gvim81 gvim80 gvim8 gvim74 gvim73 gvim72 gvim71 gvim70 gvim7 gvim6 $seq"
                                     ;;
     -l | --language )               shift
-                                    xx=$1
+                                    xx="$1"
                                     validateLang
                                     ;;
-    -l[a-z][a-z]?([a-z]) )          xx=${1#*l}
-                                    validateLang
+    -l[a-z][a-z][a-z] | -l[a-z][a-z] )
+                                    export xx="${1#*l}"
                                     ;;
-    --language[a-z][a-z]?([a-z]) )  xx=${1#*e}
-                                    validateLang
+    --language[a-z][a-z][a-z] | --language[a-z][a-z] )
+                                    export xx="${1#*e}"
                                     ;;
-    [a-z][a-z]?([a-z]) )            xx=$1
-                                    validateLang
+    [a-z][a-z][a-z] | [a-z][a-z] )  export xx="$1"
                                     ;;
     -c | --chapter )                shift
-                                    cc=$1
+                                    cc="$1"
                                     validateChapter
                                     ;;
-    -c[0-9]?([0-9]) )               cc=${1#*c}
-                                    validateChapter
+    -c[1-9][0-9] | -c[1-9] )        export CHAPTER="${1#*c}"
                                     ;;
-    --chapter[0-9]?([0-9]) )        cc=${1#*r}
-                                    validateChapter
+    --chapter[1-9][0-9] | --chapter[1-9] )
+                                    export CHAPTER="${1#*r}"
                                     ;;
     -h | --help )                   usage
                                     exit
@@ -129,8 +138,8 @@ while [ "$1" != "" ]; do
     "" )                            ;;
     * )                             usage
                                     exit 1
-    esac
-    shift
+  esac
+  shift
 done
 
 
@@ -161,10 +170,10 @@ fi
 export TUTORCOPY
 
 # remove the copy of the tutor on exit
-trap "rm -rf $TODELETE" 0 1 2 3 9 11 13 15
+trap "rm -rf $TODELETE" EXIT HUP INT QUIT SEGV PIPE TERM
 
 for i in $seq; do
-    testvim=$(which $i 2>/dev/null)
+    testvim=$(command -v "$i" 2>/dev/null)
     if test -f "$testvim"; then
         VIM=$i
         break


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you commented.Message ID: <vim/vim/pull/5729/c2453611307@github.com>

Christian Brabandt

unread,
Nov 4, 2024, 7:08:54 AM11/4/24
to vim/vim, vim-dev ML, Comment

@zzzyxwvut nice, thanks for this. I'll check it later today


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you commented.Message ID: <vim/vim/pull/5729/c2454547650@github.com>

D. Ben Knoble

unread,
Nov 4, 2024, 1:41:44 PM11/4/24
to vim/vim, vim-dev ML, Comment

shellcheck will also warn for non-POSIX-portable constructs if the shebang line starts uses sh


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you commented.Message ID: <vim/vim/pull/5729/c2455444187@github.com>

Aliaksei Budavei

unread,
Nov 4, 2024, 1:50:19 PM11/4/24
to vim/vim, vim-dev ML, Comment

There will likely be other suggestions, let me draft a PR
then.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you commented.Message ID: <vim/vim/pull/5729/c2455459817@github.com>

Aliaksei Budavei

unread,
Nov 4, 2024, 3:32:20 PM11/4/24
to vim/vim, vim-dev ML, Comment

The patch is in the master branch. #15992 is a follow-up
PR draft.


Reply to this email directly, view it on GitHub.
You are receiving this because you commented.Message ID: <vim/vim/pull/5729/c2455643962@github.com>

Reply all
Reply to author
Forward
0 new messages