summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/autocmd.txt17
-rw-r--r--runtime/doc/editing.txt25
-rw-r--r--runtime/doc/eval.txt64
-rw-r--r--runtime/doc/intro.txt11
-rw-r--r--runtime/doc/motion.txt6
-rw-r--r--runtime/doc/options.txt22
-rw-r--r--runtime/doc/tags9
-rw-r--r--runtime/doc/usr_41.txt475
-rw-r--r--runtime/doc/usr_toc.txt13
-rw-r--r--runtime/doc/various.txt5
-rw-r--r--runtime/syntax/vim.vim2
-rw-r--r--src/edit.c10
-rw-r--r--src/ex_cmds2.c11
-rw-r--r--src/ex_docmd.c8
-rw-r--r--src/ex_getln.c9
-rw-r--r--src/fileio.c14
-rw-r--r--src/gui_motif.c79
-rw-r--r--src/gui_xmebw.c19
-rw-r--r--src/move.c3
-rw-r--r--src/ops.c92
-rw-r--r--src/option.c11
-rw-r--r--src/option.h3
-rw-r--r--src/os_unix.c3
-rw-r--r--src/proto/gui_motif.pro1
-rw-r--r--src/quickfix.c65
-rw-r--r--src/structs.h1
-rw-r--r--src/version.h4
-rw-r--r--src/vim.h2
28 files changed, 795 insertions, 189 deletions
diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt
index 2b7edf5eca..c815f362aa 100644
--- a/runtime/doc/autocmd.txt
+++ b/runtime/doc/autocmd.txt
@@ -1,4 +1,4 @@
-*autocmd.txt* For Vim version 7.0aa. Last change: 2005 Jan 26
+*autocmd.txt* For Vim version 7.0aa. Last change: 2005 Feb 07
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -324,6 +324,7 @@ FuncUndefined When a user function is used but it isn't
defined. Useful for defining a function only
when it's used. Both <amatch> and <afile> are
set to the name of the function.
+ See |autoload-functions|.
*CursorHold*
CursorHold When the user doesn't press a key for the time
specified with 'updatetime'. Not re-triggered
@@ -520,6 +521,20 @@ TermResponse After the response to |t_RV| is received from
the terminal. The value of |v:termresponse|
can be used to do things depending on the
terminal version.
+QuickFixCmdPre *QuickFixCmdPre*
+ Before a quickfix command is run (|:make|,
+ |:grep|, |:grepadd|, |:vimgrep|,
+ |:vimgrepadd|). The pattern is matched against
+ the command being run. When |:grep| is used
+ but 'grepprg' is set to "internal" it still
+ matches "grep".
+ This command cannot be used to set the
+ 'makeprg' and 'grepprg' variables.
+ If this command causes an error, the quickfix
+ command is not executed.
+QuickFixCmdPost *QuickFixCmdPost*
+ like QuickFixCmdPre, but after a quickfix
+ command is run.
*UserGettingBored*
UserGettingBored When the user hits CTRL-C. Just kidding! :-)
*User*
diff --git a/runtime/doc/editing.txt b/runtime/doc/editing.txt
index e5acbb921e..ae7543e8d6 100644
--- a/runtime/doc/editing.txt
+++ b/runtime/doc/editing.txt
@@ -1,4 +1,4 @@
-*editing.txt* For Vim version 7.0aa. Last change: 2005 Jan 26
+*editing.txt* For Vim version 7.0aa. Last change: 2005 Feb 07
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -69,18 +69,21 @@ CTRL-G or *CTRL-G* *:f* *:fi* *:file*
buffer number is also given. {not in Vi}
*g_CTRL-G* *word-count* *byte-count*
-g CTRL-G Prints the current position of the cursor in four
- ways: Column, Line, Word and Byte. If there are
- characters in the line that take more than one
- position on the screen (<Tab> or special character),
- both the "real" column and the screen column are
- shown, separated with a dash. See also 'ruler'
- option. {not in Vi}
+g CTRL-G Prints the current position of the cursor in five
+ ways: Column, Line, Word, Character and Byte. If the
+ number of Characters and Bytes is the same then the
+ Character position is omitted.
+ If there are characters in the line that take more
+ than one position on the screen (<Tab> or special
+ character), both the "real" column and the screen
+ column are shown, separated with a dash.
+ See also 'ruler' option. {not in Vi}
*v_g_CTRL-G*
-{Visual}g CTRL-G Similar to "g CTRL-G", but Word, Line, and Byte counts
- for the visually selected region are displayed. In
- Blockwise mode, Column count is also shown. (For
+{Visual}g CTRL-G Similar to "g CTRL-G", but Word, Character, Line, and
+ Byte counts for the visually selected region are
+ displayed.
+ In Blockwise mode, Column count is also shown. (For
{Visual} see |Visual-mode|.)
{not in VI}
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index c0031e8531..450408c814 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -1,4 +1,4 @@
-*eval.txt* For Vim version 7.0aa. Last change: 2005 Feb 05
+*eval.txt* For Vim version 7.0aa. Last change: 2005 Feb 07
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -15,7 +15,7 @@ done, the features in this document are not available. See |+eval| and
1. Variables |variables|
1.1 Variable types
1.2 Function references |Funcref|
- 1.3 Lists |List|
+ 1.3 Lists |Lists|
1.4 Dictionaries |Dictionaries|
1.5 More about variables |more-variables|
2. Expression syntax |expression-syntax|
@@ -126,7 +126,7 @@ arguments: >
1.3 Lists ~
- *List* *E686*
+ *List* *Lists* *E686*
A List is an ordered sequence of items. An item can be of any type. Items
can be accessed by their index number. Items can be added and removed at any
position in the sequence.
@@ -410,7 +410,7 @@ a List in which each item is a List with two items, the key and the value: >
Dictionary identity ~
-
+ *dict-identity*
Just like Lists you need to use |copy()| and |deepcopy()| to make a copy of a
Dictionary. Otherwise, assignment results in referring to the same
Dictionary: >
@@ -1362,6 +1362,7 @@ USAGE RESULT DESCRIPTION ~
add( {list}, {item}) List append {item} to List {list}
append( {lnum}, {string}) Number append {string} below line {lnum}
+append( {lnum}, {list}) Number append lines {list} below line {lnum}
argc() Number number of files in the argument list
argidx() Number current index in the argument list
argv( {nr}) String {nr} entry of the argument list
@@ -1429,7 +1430,8 @@ getfsize( {fname}) Number size in bytes of file {fname}
getfontname( [{name}]) String name of font being used
getftime( {fname}) Number last modification time of file
getftype( {fname}) String description of type of file {fname}
-getline( {lnum}) String line {lnum} from current buffer
+getline( {lnum}) String line {lnum} of current buffer
+getline( {lnum}, {end}) List lines {lnum} to {end} of current buffer
getreg( [{regname}]) String contents of register
getregtype( [{regname}]) String type of register
getwinposx() Number X coord in pixels of GUI Vim window
@@ -4342,16 +4344,64 @@ the caller to set the names.
The recursiveness of user functions is restricted with the |'maxfuncdepth'|
option.
+
+AUTOMATICALLY LOADING FUNCTIONS ~
*autoload-functions*
When using many or large functions, it's possible to automatically define them
-only when they are used. Use the FuncUndefined autocommand event with a
-pattern that matches the function(s) to be defined. Example: >
+only when they are used. There are two methods: with an autocommand and with
+the "autoload" directory in 'runtimepath'.
+
+
+Using an autocommand ~
+
+The autocommand is useful if you have a plugin that is a long Vim script file.
+You can define the autocommand and quickly quit the script with |:finish|.
+That makes Vim startup faster. The autocommand should then load the same file
+again, setting a variable to skip the |:finish| command.
+
+Use the FuncUndefined autocommand event with a pattern that matches the
+function(s) to be defined. Example: >
:au FuncUndefined BufNet* source ~/vim/bufnetfuncs.vim
The file "~/vim/bufnetfuncs.vim" should then define functions that start with
"BufNet". Also see |FuncUndefined|.
+
+Using an autoload script ~
+
+Using a script in the "autoload" directory is simpler, but requires using
+exactly the right file name. A function that can be autoloaded has a name
+like this: >
+
+ :call filename:funcname()
+
+When such a function is called, and it is not defined yet, Vim will search the
+"autoload" directories in 'runtimepath' for a script file called
+"filename.vim". For example "~/.vim/autoload/filename.vim". That file should
+then define the function like this: >
+
+ function filename:funcname()
+ echo "Done!"
+ endfunction
+
+The file name and the name used before the colon in the function must match
+exactly, and the defined function must have the name exactly as it will be
+called.
+
+It is possible to use subdirectories. Every colon in the function name works
+like a path separator. Thus when calling a function: >
+
+ :call foo:bar:func()
+
+Vim will look for the file "autoload/foo/bar.vim" in 'runtimepath'.
+
+The name before the first colon must be at least two characters long,
+otherwise it looks like a scope, such as "s:".
+
+Note that the script will be sourced again and again if a function is called
+that looks like it is defined in the autoload script but it isn't.
+
==============================================================================
6. Curly braces names *curly-braces-names*
diff --git a/runtime/doc/intro.txt b/runtime/doc/intro.txt
index d984ce2594..935577724c 100644
--- a/runtime/doc/intro.txt
+++ b/runtime/doc/intro.txt
@@ -1,4 +1,4 @@
-*intro.txt* For Vim version 7.0aa. Last change: 2004 Dec 16
+*intro.txt* For Vim version 7.0aa. Last change: 2005 Feb 07
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -289,8 +289,7 @@ Vi "the original". Without further remarks this is the version
Posix From the IEEE standard 1003.2, Part 2: Shell and utilities.
Generally known as "Posix". This is a textual description of
how Vi is supposed to work.
- The version used is a draft from beginning 1996, so all remarks are
- "expected to comply to" this. Anything can change though...
+ See |posix-compliance|.
*Nvi*
Nvi The "New" Vi. The version of Vi that comes with BSD 4.4 and FreeBSD.
Very good compatibility with the original Vi, with a few extensions.
@@ -691,9 +690,9 @@ Q Switch to "Ex" mode. This is a bit like typing ":"
|vimrc_example.vim| script "Q" works like "gq".
*gQ*
-gQ Switch to "Ex" mode, but really behave like typing ":"
- commands after another. All command line editing,
- completion etc. is available.
+gQ Switch to "Ex" mode like with "Q", but really behave
+ like typing ":" commands after another. All command
+ line editing, completion etc. is available.
Use the ":vi" command |:visual| to exit "Ex" mode.
{not in Vi}
diff --git a/runtime/doc/motion.txt b/runtime/doc/motion.txt
index bee238e5e0..daaa6020e2 100644
--- a/runtime/doc/motion.txt
+++ b/runtime/doc/motion.txt
@@ -1,4 +1,4 @@
-*motion.txt* For Vim version 7.0aa. Last change: 2005 Jan 08
+*motion.txt* For Vim version 7.0aa. Last change: 2005 Feb 07
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -350,6 +350,10 @@ or the last line. The first two commands put the cursor in the same column
except after the "$" command, then the cursor will be put on the last
character of the line.
+If "k", "-" or CTRL-P is used with a [count] and there are less than [count]
+lines above the cursor and the 'cpo' option includes the "-" flag it is an
+error. |cpo--|.
+
==============================================================================
4. Word motions *word-motions*
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index d79aab72e2..e1c6f5ae40 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -1,4 +1,4 @@
-*options.txt* For Vim version 7.0aa. Last change: 2005 Jan 30
+*options.txt* For Vim version 7.0aa. Last change: 2005 Feb 07
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1382,7 +1382,8 @@ A jump table for the options with a short description can be found at |Q_op|.
global
{not in Vi}
Number of columns of the screen. Normally this is set by the terminal
- initialization and does not have to be set by hand.
+ initialization and does not have to be set by hand. Also see
+ |posix-screen-size|.
When Vim is running in the GUI or in a resizable window, setting this
option will cause the window size to be changed. When you only want
to use the size for the GUI, put the command in your |gvimrc| file.
@@ -1431,7 +1432,7 @@ A jump table for the options with a short description can be found at |Q_op|.
to the Vim defaults. Effectively, this means that when a ".vimrc"
file exists, Vim will use the Vim defaults, otherwise it will use the
Vi defaults. (Note: This doesn't happen for the system-wide vimrc
- file). Also see |compatible-default|.
+ file). Also see |compatible-default| and |posix-compliance|.
You can also set this option with the "-C" argument, and reset it with
"-N". See |-C| and |-N|.
Switching this option off makes the Vim defaults be used for options
@@ -1844,6 +1845,13 @@ A jump table for the options with a short description can be found at |Q_op|.
there is one). This works very well for C programs.
This flag is also used for other features, such as
C-indenting.
+ *cpo--*
+ - When included, a vertical movement command fails when
+ it would above the first line or below the last line.
+ Without it the cursor moves to the first or last line,
+ unless it already was in that line.
+ Applies to the commands "-", "k", CTRL-P, "+", "j",
+ CTRL-N and CTRL-J.
*cpo-+*
+ When included, a ":write file" command will reset the
'modified' flag of the buffer, even though the buffer
@@ -2804,7 +2812,7 @@ A jump table for the options with a short description can be found at |Q_op|.
VMS: "SEARCH/NUMBERS ")
global or local to buffer |global-local|
{not in Vi}
- Program to use for the ":grep" command. This option may contain '%'
+ Program to use for the |:grep| command. This option may contain '%'
and '#' characters, which are expanded like when used in a command-
line. The placeholder "$*" is allowed to specify where the arguments
will be included. Environment variables are expanded |:set_env|. See
@@ -2812,8 +2820,8 @@ A jump table for the options with a short description can be found at |Q_op|.
When your "grep" accepts the "-H" argument, use this to make ":grep"
also work well with a single file: >
:set grepprg=grep\ -nH
-< Special value: When 'grepprg' is set to "internal" the ":grep" works
- like ":vimgrep".
+< Special value: When 'grepprg' is set to "internal" the |:grep| command
+ works like |:vimgrep| and |:grepadd| like |:vimgrepadd|.
See also the section |:make_makeprg|, since most of the comments there
apply equally to 'grepprg'.
For Win32, the default is "findstr /n" if "findstr.exe" can be found,
@@ -3882,7 +3890,7 @@ A jump table for the options with a short description can be found at |Q_op|.
global
Number of lines of the Vim window.
Normally you don't need to set this. It is done automatically by the
- terminal initialization code.
+ terminal initialization code. Also see |posix-screen-size|.
When Vim is running in the GUI or in a resizable window, setting this
option will cause the window size to be changed. When you only want
to use the size for the GUI, put the command in your |gvimrc| file.
diff --git a/runtime/doc/tags b/runtime/doc/tags
index 8ad645313d..30611f86f5 100644
--- a/runtime/doc/tags
+++ b/runtime/doc/tags
@@ -1531,6 +1531,7 @@ $VIMRUNTIME starting.txt /*$VIMRUNTIME*
41.10 usr_41.txt /*41.10*
41.11 usr_41.txt /*41.11*
41.12 usr_41.txt /*41.12*
+41.13 usr_41.txt /*41.13*
41.2 usr_41.txt /*41.2*
41.3 usr_41.txt /*41.3*
41.4 usr_41.txt /*41.4*
@@ -3738,6 +3739,7 @@ Korean mbyte.txt /*Korean*
L motion.txt /*L*
Linux-backspace options.txt /*Linux-backspace*
List eval.txt /*List*
+Lists eval.txt /*Lists*
M motion.txt /*M*
MDI starting.txt /*MDI*
MS-DOS os_msdos.txt /*MS-DOS*
@@ -3833,6 +3835,8 @@ Q_vi quickref.txt /*Q_vi*
Q_vm quickref.txt /*Q_vm*
Q_wi quickref.txt /*Q_wi*
Q_wq quickref.txt /*Q_wq*
+QuickFixCmdPost autocmd.txt /*QuickFixCmdPost*
+QuickFixCmdPre autocmd.txt /*QuickFixCmdPre*
Quickfix quickfix.txt /*Quickfix*
R change.txt /*R*
RISC-OS os_risc.txt /*RISC-OS*
@@ -4378,6 +4382,7 @@ cpo-! options.txt /*cpo-!*
cpo-$ options.txt /*cpo-$*
cpo-% options.txt /*cpo-%*
cpo-+ options.txt /*cpo-+*
+cpo-- options.txt /*cpo--*
cpo-< options.txt /*cpo-<*
cpo-A options.txt /*cpo-A*
cpo-B options.txt /*cpo-B*
@@ -4524,6 +4529,7 @@ diW motion.txt /*diW*
dialog gui_w32.txt /*dialog*
dialogs-added version5.txt /*dialogs-added*
dib motion.txt /*dib*
+dict-identity eval.txt /*dict-identity*
dict-modification eval.txt /*dict-modification*
did_filetype() eval.txt /*did_filetype()*
diff diff.txt /*diff*
@@ -5460,6 +5466,7 @@ match() eval.txt /*match()*
match-highlight pattern.txt /*match-highlight*
matchend() eval.txt /*matchend()*
matchit-install usr_05.txt /*matchit-install*
+matchlist() eval.txt /*matchlist()*
matchstr() eval.txt /*matchstr()*
max() eval.txt /*max()*
mbyte-IME mbyte.txt /*mbyte-IME*
@@ -5830,6 +5837,8 @@ popup-menu gui.txt /*popup-menu*
popup-menu-added version5.txt /*popup-menu-added*
ports-5.2 version5.txt /*ports-5.2*
ports-6 version6.txt /*ports-6*
+posix-compliance vi_diff.txt /*posix-compliance*
+posix-screen-size vi_diff.txt /*posix-screen-size*
postscr-syntax syntax.txt /*postscr-syntax*
postscr.vim syntax.txt /*postscr.vim*
postscript-cjk-printing print.txt /*postscript-cjk-printing*
diff --git a/runtime/doc/usr_41.txt b/runtime/doc/usr_41.txt
index d90c24abfd..74c74fdb7c 100644
--- a/runtime/doc/usr_41.txt
+++ b/runtime/doc/usr_41.txt
@@ -1,4 +1,4 @@
-*usr_41.txt* For Vim version 7.0aa. Last change: 2005 Feb 04
+*usr_41.txt* For Vim version 7.0aa. Last change: 2005 Feb 07
VIM USER MANUAL - by Bram Moolenaar
@@ -16,11 +16,12 @@ script. There are a lot of them, thus this is a long chapter.
|41.5| Executing an expression
|41.6| Using functions
|41.7| Defining a function
-|41.8| Exceptions
-|41.9| Various remarks
-|41.10| Writing a plugin
-|41.11| Writing a filetype plugin
-|41.12| Writing a compiler plugin
+|41.8| Lists and Dictionaries
+|41.9| Exceptions
+|41.10| Various remarks
+|41.11| Writing a plugin
+|41.12| Writing a filetype plugin
+|41.13| Writing a compiler plugin
Next chapter: |usr_42.txt| Add new menus
Previous chapter: |usr_40.txt| Make new commands
@@ -42,7 +43,7 @@ Let's start with a simple example: >
:let i = 1
:while i < 5
: echo "count is" i
- : let i = i + 1
+ : let i += 1
:endwhile
<
Note:
@@ -50,8 +51,19 @@ Let's start with a simple example: >
them when you type a command. In a Vim script file they can be left
out. We will use them here anyway to make clear these are colon
commands and make them stand out from Normal mode commands.
+ Note:
+ You can try out the examples by yanking the lines from the text here
+ and executing them with :@"
+
+The output of the example code is:
+
+ count is 1 ~
+ count is 2 ~
+ count is 3 ~
+ count is 4 ~
-The ":let" command assigns a value to a variable. The generic form is: >
+In the first line the ":let" command assigns a value to a variable. The
+generic form is: >
:let {variable} = {expression}
@@ -66,61 +78,52 @@ the number one.
The statements until the matching ":endwhile" are executed for as long as the
condition is true. The condition used here is the expression "i < 5". This
is true when the variable i is smaller than five.
- The ":echo" command prints its arguments. In this case the string "count
-is" and the value of the variable i. Since i is one, this will print:
-
- count is 1 ~
+ Note:
+ If you happen to write a while loop that keeps on running, you can
+ interrupt it by pressing CTRL-C (CTRL-Break on MS-Windows).
-Then there is another ":let i =" command. The value used is the expression "i
-+ 1". This adds one to the variable i and assigns the new value to the same
-variable.
- The output of the example code is:
+The ":echo" command prints its arguments. In this case the string "count is"
+and the value of the variable i. Since i is one, this will print:
count is 1 ~
- count is 2 ~
- count is 3 ~
- count is 4 ~
- Note:
- If you happen to write a while loop that keeps on running, you can
- interrupt it by pressing CTRL-C (CTRL-Break on MS-Windows).
- Note:
- You can try out the examples by yanking the lines from the text here
- and executing them with :@"
+Then there is the ":let i += 1" command. This does the same thing as
+":let i = i + 1". This adds one to the variable i and assigns the new value
+to the same variable.
-The example was given to explain the commands, but you would really want to
+The example was given to explain the commands, but would you really want to
make such a loop it can be written much more compact: >
:for i in range(1, 4)
: echo "count is" i
:endfor
-We won't explain how |:for| and |range()| work right now. Follow the links if
-you are impatient.
+We won't explain how |:for| and |range()| work until later. Follow the links
+if you are impatient.
THREE KINDS OF NUMBERS
Numbers can be decimal, hexadecimal or octal. A hexadecimal number starts
-with "0x" or "0X". For example "0x1f" is 31. An octal number starts with a
-zero. "017" is 15. Careful: don't put a zero before a decimal number, it
-will be interpreted as an octal number!
+with "0x" or "0X". For example "0x1f" is decimal 31. An octal number starts
+with a zero. "017" is decimal 15. Careful: don't put a zero before a decimal
+number, it will be interpreted as an octal number!
The ":echo" command always prints decimal numbers. Example: >
:echo 0x7f 036
< 127 30 ~
A number is made negative with a minus sign. This also works for hexadecimal
-and octal numbers. A minus sign is also for subtraction. Compare this with
-the previous example: >
+and octal numbers. A minus sign is also used for subtraction. Compare this
+with the previous example: >
:echo 0x7f -036
< 97 ~
White space in an expression is ignored. However, it's recommended to use it
for separating items, to make the expression easier to read. For example, to
-avoid the confusion with a negative number, put a space between the minus sign
-and the following number: >
+avoid the confusion with a negative number above, put a space between the
+minus sign and the following number: >
:echo 0x7f - 036
@@ -151,7 +154,7 @@ example, one script contains this code: >
:let s:count = 1
:while s:count < 5
: source other.vim
- : let s:count = s:count + 1
+ : let s:count += 1
:endwhile
Since "s:count" is local to this script, you can be sure that sourcing the
@@ -202,15 +205,21 @@ exists() checks. That's not what you want.
The exclamation mark ! negates a value. When the value was true, it
becomes false. When it was false, it becomes true. You can read it as "not".
Thus "if !exists()" can be read as "if not exists()".
- What Vim calls true is anything that is not zero. Only zero is false.
+ What Vim calls true is anything that is not zero. Zero is false.
+ Note:
+ Vim automatically converts a string to a number when it is looking for
+ a number. When using a string that doesn't start with a digit the
+ resulting number is zero. Thus look out for this: >
+ :if "true"
+< The "true" will be interpreted as a zero, thus as false!
STRING VARIABLES AND CONSTANTS
So far only numbers were used for the variable value. Strings can be used as
-well. Numbers and strings are the only two types of variables that Vim
-supports. The type is dynamic, it is set each time when assigning a value to
-the variable with ":let".
+well. Numbers and strings are the basic types of variables that Vim supports.
+The type is dynamic, it is set each time when assigning a value to the
+variable with ":let". More about types in |41.8|.
To assign a string value to a variable, you need to use a string constant.
There are two types of these. First the string in double quotes: >
@@ -231,9 +240,9 @@ To avoid the need for a backslash, you can use a string in single quotes: >
:echo name
< "peter" ~
-Inside a single-quote string all the characters are as they are. The drawback
-is that it's impossible to include a single quote. A backslash is taken
-literally as well, thus you can't use it to change the meaning of the
+Inside a single-quote string all the characters are as they are. Only the
+single quote itself is special: you need to use two to get one. A backslash
+is taken literally, thus you can't use it to change the meaning of the
character after it.
In double-quote strings it is possible to use special characters. Here are
a few useful ones:
@@ -281,7 +290,8 @@ do something and restore the old value. Example: >
:let &ic = save_ic
This makes sure the "The Start" pattern is used with the 'ignorecase' option
-off. Still, it keeps the value that the user had set.
+off. Still, it keeps the value that the user had set. (Another way to do
+this would be to add "\C" to the pattern, see |/\C|.)
MATHEMATICS
@@ -387,7 +397,7 @@ ones:
The result is one if the condition is met and zero otherwise. An example: >
- :if v:version >= 600
+ :if v:version >= 700
: echo "congratulations"
:else
: echo "you are using an old version, upgrade!"
@@ -428,8 +438,8 @@ pattern, like what's used for searching. Example: >
:endif
Notice the use of a single-quote string for the pattern. This is useful,
-because backslashes need to be doubled in a double-quote string and patterns
-tend to contain many backslashes.
+because backslashes would need to be doubled in a double-quote string and
+patterns tend to contain many backslashes.
The 'ignorecase' option is used when comparing strings. When you don't want
that, append "#" to match case and "?" to ignore case. Thus "==?" compares
@@ -464,6 +474,8 @@ Example: >
The ":sleep" command makes Vim take a nap. The "50m" specifies fifty
milliseconds. Another example is ":sleep 4", which sleeps for four seconds.
+Even more looping can be done with the ":for" command, see below in |41.8|.
+
==============================================================================
*41.5* Executing an expression
@@ -503,6 +515,17 @@ This inserts "new text " in the current line. Notice the use of the special
key "\<Esc>". This avoids having to enter a real <Esc> character in your
script.
+If you don't want to execute a string but evaluate it to get its expression
+value, you can use the eval() function: >
+
+ :let optname = "path"
+ :let optval = eval('&' . optname)
+
+A "&" character is prepended to "path", thus the argument to eval() is
+"&path". The result will then be the value of the 'path' option.
+ The same thing can be done with: >
+ :exe 'let optval = &' . optname
+
==============================================================================
*41.6* Using functions
@@ -526,9 +549,9 @@ A function can be called in an expression. Example: >
:let repl = substitute(line, '\a', "*", "g")
:call setline(".", repl)
-The getline() function obtains a line from the current file. Its argument is
-a specification of the line number. In this case "." is used, which means the
-line where the cursor is.
+The getline() function obtains a line from the current buffer. Its argument
+is a specification of the line number. In this case "." is used, which means
+the line where the cursor is.
The substitute() function does something similar to the ":substitute"
command. The first argument is the string on which to perform the
substitution. The second argument is the pattern, the third the replacement
@@ -567,7 +590,6 @@ String manipulation:
submatch() get a specific match in a ":substitute"
strpart() get part of a string
expand() expand special keywords
- type() type of a variable
iconv() convert text from one encoding to another
List manipulation:
@@ -588,11 +610,10 @@ List manipulation:
join() join List items into a String
string() String representation of a List
call() call a function with List as arguments
+ index() index of a value in a list
max() maximum value in a List
min() minimum value in a List
count() count number of times a value appears in a List
- getline() get List with buffer lines
- append() append List of lines to the buffer
Dictionary manipulation:
get() get an entries without error for wrong key
@@ -622,9 +643,9 @@ Working with text in the current buffer:
wincol() window column number of the cursor
winline() window line number of the cursor
cursor() position the cursor at a line/column
- getline() get a line from the buffer
+ getline() get a line or list of lines from the buffer
setline() replace a line in the buffer
- append() append {string} below line {lnum}
+ append() append line or list of lines in the buffer
indent() indent of a specific line
cindent() indent according to C indenting
lispindent() indent according to Lisp indenting
@@ -713,6 +734,7 @@ Vim server:
remote_foreground() move the Vim server window to the foreground
Various:
+ type() type of a variable
mode() get current editing mode
visualmode() last visual mode used
hasmapto() check if a mapping exists
@@ -792,6 +814,15 @@ The complete function definition is as follows: >
: return smaller
:endfunction
+For people who like short functions, this does the same thing: >
+
+ :function Min(num1, num2)
+ : if a:num1 < a:num2
+ : return a:num1
+ : endif
+ : return a:num2
+ :endfunction
+
A user defined function is called in exactly the same way as a builtin
function. Only the name is different. The Min function can be used like
this: >
@@ -879,6 +910,9 @@ This uses the ":echohl" command to specify the highlighting used for the
following ":echo" command. ":echohl None" stops it again. The ":echon"
command works like ":echo", but doesn't output a line break.
+You can also use the a:000 variable, it is a List of all the "..." arguments.
+See |a:000|.
+
LISTING FUNCTIONS
@@ -915,8 +949,327 @@ To delete the Show() function: >
You get an error when the function doesn't exist.
+
+FUNCTION REFERENCES
+
+Sometimes it can be useful to have a variable point to one function or
+another. You can do it with the function() function. It turns the name of a
+function into a reference: >
+
+ :let result = 0 " or 1
+ :function! Right()
+ : return 'Right!'
+ :endfunc
+ :function! Wrong()
+ : return 'Wrong!'
+ :endfunc
+ :
+ :if result == 1
+ : let Afunc = function('Right')
+ :else
+ : let Afunc = function('Wrong')
+ :endif
+ :echo call(Afunc, [])
+< Wrong! ~
+
+Note that the name of a variable that holds a function reference must start
+with a capital. Otherwise it could be confused with the name of a builtin
+function.
+ The way to invoke a function that a variable refers to is with the call()
+function. Its first argument is the function reference, the second argument
+is a List with arguments.
+
+Function references are most useful in combination with a Dictionary, as is
+explained in the next section.
+
+==============================================================================
+*41.8* Lists and Dictionaries
+
+So far we have used the basic types String and Number. Vim also supports two
+composite types: List and Dictionary.
+
+A List is an ordered sequence of things. The things can be any kind of value,
+thus you can make a List of numbers, a List of Lists and even a List of mixed
+items. To create a List with three strings: >
+
+ :let alist = ['aap', 'mies', 'noot']
+
+The List items are enclosed in square brackets and separated by commas. To
+create an empty List: >
+
+ :let alist = []
+
+You can add items to a List with the add() function: >
+
+ :let alist = []
+ :call add(alist, 'foo')
+ :call add(alist, 'bar')
+ :echo alist
+< ['foo', 'bar'] ~
+
+List concatenation is done with +: >
+