1
0
Fork 0
mirror of https://github.com/vim/vim synced 2025-03-16 06:47:52 +01:00

runtime(vimtutor): Add a second chapter

fixes: 
closes: 

Signed-off-by: Paul Desmond Parker <pauldesmondparker@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Paul Desmond Parker 2024-11-03 20:47:53 +01:00 committed by Christian Brabandt
parent a54816b884
commit 17c71daf83
No known key found for this signature in database
GPG key ID: F3F92DA383FDDE09
10 changed files with 687 additions and 59 deletions

View file

@ -120,8 +120,11 @@ On Unix, if Vim has been properly installed, you can start it from the shell:
On MS-Windows you can find it in the Program/Vim menu. Or execute
vimtutor.bat in the $VIMRUNTIME directory.
This will make a copy of the tutor file, so that you can edit it without
the risk of damaging the original.
This will make a copy of chapter 1 tutor file, so that you can edit it without
the risk of damaging the original. To continue with chapter 2, you can use
the following command: >
vimtutor -c 2
<
There are a few translated versions of the tutor. To find out if yours is
available, use the two-letter language code. For French: >

View file

@ -41605,6 +41605,7 @@ Changed~
- the |help-TOC| package is included to ease navigating the documentation.
- an interactive tutor plugin has been included |vim-tutor-mode|, can be
started via |:Tutor|
- improve the |vimtutor| and add a second chapter for more advanced tips
*added-9.2*
Added ~

View file

@ -1,16 +1,18 @@
.TH VIMTUTOR 1 "2024 August 12"
.TH VIMTUTOR 1 "2024 November 03"
.SH NAME
vimtutor \- the Vim tutor
.SH SYNOPSIS
.br
.B vimtutor [\-g] [language]
.B vimtutor [\-l | \-\-language ISO639] [\-c | \-\-chapter NUMBER] [\-g | \-\-gui] [ISO639]
.br
.B vimtutor [\-h | \-\-help]
.br
.B vimtutor [\-\-list]
.SH DESCRIPTION
.B Vimtutor
starts the
.B Vim
tutor.
It copies the tutor file first, so that it can be modified without changing
the original file.
.PP
The
.B Vimtutor
@ -28,34 +30,91 @@ be used.
If a tutor in this language is available, it will be used.
Otherwise the English version will be used.
.PP
.B Vimtutor
only opens temporary copies of the original tutor files, there is no danger of overwriting the lessons.
.PP
.B Vim
is always started in Vi compatible mode.
is always started in
.B Vi
compatible mode.
.SH OPTIONS
.TP
.BR \-l ", " \-\-language =\fIISO639\fR
Set the two or three letter language code. E.g. 'it', 'es', 'bar'. Defaults to language of locale if available, else to English.
.TP
.BR \-c ", " \-\-chapter =\fINUMBER\fR
Set the one or two digit chapter number. Defaults to chapter one.
.TP
.BR \-g ", " \-\-gui
Start
.B vimtutor
in the GUI version of vim if available, otherwise fallback to console vim.
.TP
.BR \-h ", " \-\-help
Display usage information.
.TP
.BR \-\-list
Display chapters and languages.
.SH EXAMPLES
To start
.B vimtutor
in German on chapter one:
.PP
.nf
.RS
vimtutor de
.RE
.fi
.PP
In English on chapter two:
.PP
.nf
.RS
vimtutor -c2
.RE
.fi
.PP
Longform command for Bavarian in the GUI on chapter one:
.PP
.nf
.RS
vimtutor --language bar --chapter 1 --gui
.RE
.fi
.SH FILES
.TP 15
/usr/local/share/vim/vim??/tutor/tutor[.language]
The
.B Vimtutor
text file(s).
.br
.I vim??
is short version number, like vim91 for
.B Vim 9.1
chapter one text file(s).
.TP 15
/usr/local/share/vim/vim??/tutor/tutor.vim
The Vim script used to copy the
.B Vimtutor
text file.
.SH AUTHOR
/usr/local/share/vim/vim??/tutor/tutor02[.language]
The
.B Vimtutor
was originally written for Vi by Michael C. Pierce and Robert K. Ware,
Colorado School of Mines using ideas supplied by Charles Smith,
Colorado State University.
E-mail: bware@mines.colorado.edu (now invalid).
.br
It was modified for
chapter two text file(s).
.TP 15
/usr/local/share/vim/vim??/tutor/tutor.vim
The
.B Vim
script used to copy the
.B Vimtutor
chapter one text file.
.TP 15
/usr/local/share/vim/vim??/tutor/tutor02.vim
The
.B Vim
script used to copy the
.B Vimtutor
chapter two text file.
.SH AUTHOR
.B The Vi Tutorial
was originally written for Vi by Michael C. Pierce and Robert K. Ware, Colorado School of Mines using ideas supplied by Charles Smith, Colorado State University.
.B E-mail: bware@mines.colorado.edu.
.PP
Modified for
.B Vim
by Bram Moolenaar.
For the names of the translators see the tutor files.
.PP
Translation contributors are listed in the tutor files.
.SH SEE ALSO
vim(1)

View file

@ -1,16 +1,16 @@
VIMTUTOR(1) General Commands Manual VIMTUTOR(1)
NAME
vimtutor - the Vim tutor
SYNOPSIS
vimtutor [-g] [language]
vimtutor [-l | --language ISO639] [-c | --chapter NUMBER] [-g | --gui]
[ISO639]
vimtutor [-h | --help]
vimtutor [--list]
DESCRIPTION
Vimtutor starts the Vim tutor. It copies the tutor file first, so that
it can be modified without changing the original file.
Vimtutor starts the Vim tutor.
The Vimtutor is useful for people that want to learn their first Vim
commands.
@ -21,31 +21,73 @@ DESCRIPTION
The optional [language] argument is the two-letter name of a language,
like "it" or "es". If the [language] argument is missing, the language
of the current locale will be used. If a tutor in this language is
available, it will be used. Otherwise the English version will be
of the current locale will be used. If a tutor in this language is
available, it will be used. Otherwise the English version will be
used.
Vimtutor only opens temporary copies of the original tutor files, there
is no danger of overwriting the lessons.
Vim is always started in Vi compatible mode.
OPTIONS
-l, --language=ISO639
Set the two or three letter language code. E.g. 'it', 'es',
'bar'. Defaults to language of locale if available, else to Eng
lish.
-c, --chapter=NUMBER
Set the one or two digit chapter number. Defaults to chapter
one.
-g, --gui
Start vimtutor in the GUI version of vim if available, otherwise
fallback to console vim.
-h, --help
Display usage information.
--list Display chapters and languages.
EXAMPLES
To start vimtutor in German on chapter one:
vimtutor de
In English on chapter two:
vimtutor -c2
Longform command for Bavarian in the GUI on chapter one:
vimtutor --language bar --chapter 1 --gui
FILES
/usr/local/share/vim/vim??/tutor/tutor[.language]
The Vimtutor text file(s).
vim?? is short version number, like vim91 for Vim 9.1
The Vimtutor chapter one text file(s).
/usr/local/share/vim/vim??/tutor/tutor02[.language]
The Vimtutor chapter two text file(s).
/usr/local/share/vim/vim??/tutor/tutor.vim
The Vim script used to copy the Vimtutor text file.
The Vim script used to copy the Vimtutor chapter one
text file.
/usr/local/share/vim/vim??/tutor/tutor02.vim
The Vim script used to copy the Vimtutor chapter two
text file.
AUTHOR
The Vimtutor was originally written for Vi by Michael C. Pierce and
Robert K. Ware, Colorado School of Mines using ideas supplied by
Charles Smith, Colorado State University. E-mail: bware@mines.col
orado.edu (now invalid).
It was modified for Vim by Bram Moolenaar. For the names of the trans
lators see the tutor files.
The Vi Tutorial was originally written for Vi by Michael C. Pierce and
Robert K. Ware, Colorado School of Mines using ideas supplied by
Charles Smith, Colorado State University. E-mail: bware@mines.col
orado.edu.
Modified for Vim by Bram Moolenaar.
Translation contributors are listed in the tutor files.
SEE ALSO
vim(1)
2024 August 12 VIMTUTOR(1)
2024 November 03 VIMTUTOR(1)

View file

@ -945,10 +945,13 @@ NOTE: Completion works for many commands. Just try pressing CTRL-D and
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This concludes the Vim Tutor. It was intended to give a brief overview of
the Vim editor, just enough to allow you to use the editor fairly easily.
It is far from complete as Vim has many many more commands. Read the user
manual next: ":help user-manual".
This concludes Chapter 1 of the Vim Tutor. Consider continuing with Chapter 2.
It was intended to give a brief overview of the Vim editor, just enough to
allow you to use the editor fairly easily. It is far from complete as Vim
has many many more commands.
Read the user manual next: ":help user-manual".
For further reading and studying, this book is recommended:
Vim - Vi Improved - by Steve Oualline

View file

@ -180,8 +180,13 @@ if &enc == 'utf-8' && s:ext !~ '\.utf-8'
let s:ext .= '.utf-8'
endif
" 2. Build the name of the file:
let s:tutorfile = "/tutor/tutor"
" 2. Build the name of the file and chapter
let s:chapter = exists("$CHAPTER") ? $CHAPTER : ''
if s:chapter == "1"
let s:chapter = ''
endif
let s:tutorfile = "/tutor/tutor" . s:chapter
let s:tutorxx = $VIMRUNTIME . s:tutorfile . s:ext
" 3. Finding the file:

199
runtime/tutor/tutor2 Normal file
View file

@ -0,0 +1,199 @@
===============================================================================
= W e l c o m e t o t h e V I M T u t o r - Version 1.7 =
===============================================================================
= =
= C h a p t e r - T w o =
= =
===============================================================================
Hic Sunt Dracones: if this is your first exposure to vim and you
intended to avail yourself of the introductory chapter, kindly type
:q<enter> and try again.
The approximate time required to complete this chapter is 8-10 minutes,
depending upon how much time is spent with experimentation.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 2.1.1: THE NAMED REGISTERS
** Store two yanked words concurrently and then paste them **
1. Move the cursor to the line below marked --->
2. Navigate to any point on the word 'Edward' and type "ayiw
MNEMONIC: into register(") named (a) (y)ank (i)nner (w)ord
3. Navigate forward to the word 'cookie' (fk or 2fc or $2b or /co<enter>)
and type "byiw
4. Navigate to any point on the word 'Vince' and type ciw<C-r>a<ESC>
MNEMONIC: (c)hange (i)nner (w)ord with <contents of (r)egister> named (a)
5. Navigate to any point on the word 'cake' and type ciw<C-r>b<ESC>
---> a) Edward will henceforth be in charge of the cookie rations
b) In this capacity, Vince will have sole cake discretionary powers
NOTE: Delete also works into registers, i.e. "sdiw will delete the word under
the cursor into register s.
REFERENCE: Registers :h registers
Named Registers :h quotea
Motion :h motion.txt<enter> /inner<enter>
CTRL-R :h insert<enter> /CTRL-R<enter>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 2.1.2: THE EXPRESSION REGISTER
** Insert the results of calculations on the fly **
1. Move the cursor to the line below marked --->
2. Navigate to any point on the supplied number
3. Type ciw<C-r>=60*60*24<enter>
4. On the next line, enter insert mode and add today's date with
<C-r>=system('date')<enter>
NOTE: All calls to system are OS dependent, e.g. on Windows use
system('date /t') or :r!date /t
---> I have forgotten the exact number of seconds in a day, is it 84600?
Today's date is:
NOTE: the same can be achieved with :pu=system('date')
or, with fewer keystrokes :r!date
REFERENCE: Expression Register :h quote=
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 2.1.3: THE NUMBERED REGISTERS
** Press yy and dd to witness their effect on the registers **
1. Move the cursor to the line below marked --->
2. yank the zeroth line, then inspect registers with :reg<enter>
3. delete line 0. with "cdd, then inspect registers
(Where do you expect line 0 to be?)
4. continue deleting each successive line, inspecting :reg as you go
NOTE: You should notice that old full-line deletions move down the list
as new full-line deletions are added
5. Now (p)aste the following registers in order; c, 7, 4, 8, 2. i.e. "7p
---> 0. This
9. wobble
8. secret
7. is
6. on
5. axis
4. a
3. war
2. message
1. tribute
NOTE: Whole line deletions (dd) are much longer lived in the numbered registers
than whole line yanks, or deletions involving smaller movements
REFERENCE: Numbered Registers :h quote0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 2.1.4: THE BEAUTY OF MARKS
** Code monkey arithmetic avoidance **
NOTE: a common conundrum when coding is moving around large chunks of code.
The following technique helps avoid number line calculations associated
with operatins like "a147d or :945,1091d a or even worse using
i<C-r>=1091-945<enter> first
1. Move the cursor to the line below marked --->
2. Go to the first line of the function and mark it with ma
NOTE: exact position on line is NOT important!
3. Navigate to the end of the line and then the end of the code block
with $%
4. Delete the block into register a with "ad'a
MNEMONIC: into register(") named (a) put the (d)eletion from the cursor to the
LINE containing mark(') (a)
5. Paste the block between BBB and CCC "ap
NOTE: practice this operation multiple times to become fluent ma$%"ad'a
---> AAA
function itGotRealBigRealFast() {
if ( somethingIsTrue ) {
doIt()
}
// the taxonomy of our function has changed and it
// no longer makes alphabetical sense in it's current position
// imagine hundreds of lines of code
// naively you could navigate to the start and end and record or
// remember each line number
}
BBB
CCC
NOTE: marks and registers do not share a namespace, therefore register a is
completely independent of mark a. This is not true of registers and
macros.
REFERENCE: Marks :h marks
Mark Motions :h mark-motions (difference between ' and `)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 2.1 SUMMARY
1. To store (yank, delete) text into, and retrieve (paste) from, a total of
26 registers (a-z)
2. Yank a whole word from anywhere within a word: yiw
3. Change a whole word from anywhere within a word: ciw
4. Insert text directly from registers in insert mode: (C-r)a
5. Insert the results of simple arithmetic operations: (C-r)=60*60<enter>
in insert mode
6. Insert the results of system calls: (C-r)=system('ls -1')
in insert mode
7. Inspect registers with :reg
8. Learn the final destination of whole line deletions: dd in the numbered
registers, i.e. descending from register 1 - 9. Appreciate that whole
line deletions are preserved in the numbered registers longer than any
other operation
9. Learn the final destination of all yanks in the numbered registers and
how ephemeral they are
10. Place marks from command mode m[a-zA-Z0-9]
11. Move line-wise to a mark with '
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This concludes chapter two of the Vim Tutor. It is a work in progress.
This chapter was written by Paul D. Parker.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

199
runtime/tutor/tutor2.utf-8 Normal file
View file

@ -0,0 +1,199 @@
===============================================================================
= W e l c o m e t o t h e V I M T u t o r - Version 1.7 =
===============================================================================
= =
= C h a p t e r - T w o =
= =
===============================================================================
Hic Sunt Dracones: if this is your first exposure to vim and you
intended to avail yourself of the introductory chapter, kindly type
:q<enter> and try again.
The approximate time required to complete this chapter is 8-10 minutes,
depending upon how much time is spent with experimentation.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 2.1.1: THE NAMED REGISTERS
** Store two yanked words concurrently and then paste them **
1. Move the cursor to the line below marked --->
2. Navigate to any point on the word 'Edward' and type "ayiw
MNEMONIC: into register(") named (a) (y)ank (i)nner (w)ord
3. Navigate forward to the word 'cookie' (fk or 2fc or $2b or /co<enter>)
and type "byiw
4. Navigate to any point on the word 'Vince' and type ciw<C-r>a<ESC>
MNEMONIC: (c)hange (i)nner (w)ord with <contents of (r)egister> named (a)
5. Navigate to any point on the word 'cake' and type ciw<C-r>b<ESC>
---> a) Edward will henceforth be in charge of the cookie rations
b) In this capacity, Vince will have sole cake discretionary powers
NOTE: Delete also works into registers, i.e. "sdiw will delete the word under
the cursor into register s.
REFERENCE: Registers :h registers
Named Registers :h quotea
Motion :h motion.txt<enter> /inner<enter>
CTRL-R :h insert<enter> /CTRL-R<enter>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 2.1.2: THE EXPRESSION REGISTER
** Insert the results of calculations on the fly **
1. Move the cursor to the line below marked --->
2. Navigate to any point on the supplied number
3. Type ciw<C-r>=60*60*24<enter>
4. On the next line, enter insert mode and add today's date with
<C-r>=system('date')<enter>
NOTE: All calls to system are OS dependent, e.g. on Windows use
system('date /t') or :r!date /t
---> I have forgotten the exact number of seconds in a day, is it 84600?
Today's date is:
NOTE: the same can be achieved with :pu=system('date')
or, with fewer keystrokes :r!date
REFERENCE: Expression Register :h quote=
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 2.1.3: THE NUMBERED REGISTERS
** Press yy and dd to witness their effect on the registers **
1. Move the cursor to the line below marked --->
2. yank the zeroth line, then inspect registers with :reg<enter>
3. delete line 0. with "cdd, then inspect registers
(Where do you expect line 0 to be?)
4. continue deleting each successive line, inspecting :reg as you go
NOTE: You should notice that old full-line deletions move down the list
as new full-line deletions are added
5. Now (p)aste the following registers in order; c, 7, 4, 8, 2. i.e. "7p
---> 0. This
9. wobble
8. secret
7. is
6. on
5. axis
4. a
3. war
2. message
1. tribute
NOTE: Whole line deletions (dd) are much longer lived in the numbered registers
than whole line yanks, or deletions involving smaller movements
REFERENCE: Numbered Registers :h quote0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 2.1.4: THE BEAUTY OF MARKS
** Code monkey arithmetic avoidance **
NOTE: a common conundrum when coding is moving around large chunks of code.
The following technique helps avoid number line calculations associated
with operatins like "a147d or :945,1091d a or even worse using
i<C-r>=1091-945<enter> first
1. Move the cursor to the line below marked --->
2. Go to the first line of the function and mark it with ma
NOTE: exact position on line is NOT important!
3. Navigate to the end of the line and then the end of the code block
with $%
4. Delete the block into register a with "ad'a
MNEMONIC: into register(") named (a) put the (d)eletion from the cursor to the
LINE containing mark(') (a)
5. Paste the block between BBB and CCC "ap
NOTE: practice this operation multiple times to become fluent ma$%"ad'a
---> AAA
function itGotRealBigRealFast() {
if ( somethingIsTrue ) {
doIt()
}
// the taxonomy of our function has changed and it
// no longer makes alphabetical sense in it's current position
// imagine hundreds of lines of code
// naively you could navigate to the start and end and record or
// remember each line number
}
BBB
CCC
NOTE: marks and registers do not share a namespace, therefore register a is
completely independent of mark a. This is not true of registers and
macros.
REFERENCE: Marks :h marks
Mark Motions :h mark-motions (difference between ' and `)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 2.1 SUMMARY
1. To store (yank, delete) text into, and retrieve (paste) from, a total of
26 registers (a-z)
2. Yank a whole word from anywhere within a word: yiw
3. Change a whole word from anywhere within a word: ciw
4. Insert text directly from registers in insert mode: (C-r)a
5. Insert the results of simple arithmetic operations: (C-r)=60*60<enter>
in insert mode
6. Insert the results of system calls: (C-r)=system('ls -1')
in insert mode
7. Inspect registers with :reg
8. Learn the final destination of whole line deletions: dd in the numbered
registers, i.e. descending from register 1 - 9. Appreciate that whole
line deletions are preserved in the numbered registers longer than any
other operation
9. Learn the final destination of all yanks in the numbered registers and
how ephemeral they are
10. Place marks from command mode m[a-zA-Z0-9]
11. Move line-wise to a mark with '
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This concludes chapter two of the Vim Tutor. It is a work in progress.
This chapter was written by Paul D. Parker.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View file

@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
# Start Vim on a copy of the tutor file.
@ -13,15 +13,126 @@
# 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"
if test "$1" = "-g"; then
# Try to use the GUI version of Vim if possible, it will fall back
# on Vim if Gvim is not installed.
seq="gvim gvim81 gvim80 gvim8 gvim74 gvim73 gvim72 gvim71 gvim70 gvim7 gvim6 $seq"
shift
fi
xx=$1
export xx
usage()
{
echo "==USAGE========================================================================================="
echo "${0##*/} [-(-l)anguage ISO639] [-(-c)hapter) NUMBER] [-(-g)ui] | [-(-h)elp] | [--list]"
printf "\twhere:\n"
printf "\t\tISO639 (default=en) is a 2 or 3 character language code\n"
printf "\t\tNUMBER (default=01) is one or two digits representing the chapter number\n"
printf "\texamples:\n"
printf "\t\tvimtutor -l es -c 2 -g\n"
printf "\t\tvimtutor --language de --chapter 02\n"
printf "\t\tvimtutor fr\n"
echo "More information at 'man vimtutor'"
echo "================================================================================================"
}
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 "================================================================================================"
}
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
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
export CHAPTER="$cc"
}
shopt -s extglob
while [ "$1" != "" ]; do
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
validateLang
;;
-l[a-z][a-z]?([a-z]) ) xx=${1#*l}
validateLang
;;
--language[a-z][a-z]?([a-z]) ) xx=${1#*e}
validateLang
;;
[a-z][a-z]?([a-z]) ) xx=$1
validateLang
;;
-c | --chapter ) shift
cc=$1
validateChapter
;;
-c[0-9]?([0-9]) ) cc=${1#*c}
validateChapter
;;
--chapter[0-9]?([0-9]) ) cc=${1#*r}
validateChapter
;;
-h | --help ) usage
exit
;;
--list ) listOptions
exit
;;
"" ) ;;
* ) usage
exit 1
esac
shift
done
# We need a temp file for the copy. First try using a standard command.
tmp="${TMPDIR-/tmp}"
@ -68,6 +179,7 @@ fi
# Use Vim to copy the tutor, it knows the value of $VIMRUNTIME
# The script tutor.vim tells Vim which file to copy
$VIM -f -u NONE -c 'so $VIMRUNTIME/tutor/tutor.vim'
# Start vim without any .vimrc, set 'nocompatible' and 'showcmd'

View file

@ -1,7 +1,7 @@
:: Start Vim on a copy of the tutor file.
@echo off
:: Usage: vimtutor [-console] [xx]
:: Usage: vimtutor [-chapter 2] [-console] [xx]
::
:: -console means gvim will not be used
:: xx is a language code like "es" or "nl".
@ -25,6 +25,11 @@ GOTO end
:dir_ok
IF .%1==.-chapter (
SET CHAPTER=%2
SHIFT
SHIFT
)
SET xx=%1
IF NOT .%1==.-console GOTO use_gui