mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-06 14:56:54 +02:00
Add space between separator and comment
Makes the comments get properly syntax-highlighted
This commit is contained in:
@@ -40,7 +40,7 @@ pwd " Displays the current working directory
|
|||||||
|
|
||||||
" Except for some commands it does not; use the command delemiter before the
|
" Except for some commands it does not; use the command delemiter before the
|
||||||
" comment (echo assumes that the quotation mark begins a string)
|
" comment (echo assumes that the quotation mark begins a string)
|
||||||
echo 'Hello world!' |" Displays a message
|
echo 'Hello world!' | " Displays a message
|
||||||
|
|
||||||
" Line breaks can be escaped by pacing a backslash as the first non-whitespace
|
" Line breaks can be escaped by pacing a backslash as the first non-whitespace
|
||||||
" character on the *following* line. Only works in script files, not on the
|
" character on the *following* line. Only works in script files, not on the
|
||||||
@@ -67,23 +67,23 @@ echo {
|
|||||||
" Numbers (|expr-number|)
|
" Numbers (|expr-number|)
|
||||||
" #######
|
" #######
|
||||||
|
|
||||||
echo 123 |" Decimal
|
echo 123 | " Decimal
|
||||||
echo 0b1111011 |" Binary
|
echo 0b1111011 | " Binary
|
||||||
echo 0173 |" Octal
|
echo 0173 | " Octal
|
||||||
echo 0x7B |" Hexadecimal
|
echo 0x7B | " Hexadecimal
|
||||||
echo 123.0 |" Floating-point
|
echo 123.0 | " Floating-point
|
||||||
echo 1.23e2 |" Floating-point (scientific notation)
|
echo 1.23e2 | " Floating-point (scientific notation)
|
||||||
|
|
||||||
" Note that an *integer* number with a leading `0` is in octal notation. The
|
" Note that an *integer* number with a leading `0` is in octal notation. The
|
||||||
" usual arithmetic operations are supported.
|
" usual arithmetic operations are supported.
|
||||||
|
|
||||||
echo 1 + 2 |" Addition
|
echo 1 + 2 | " Addition
|
||||||
echo 1 - 2 |" Subtraction
|
echo 1 - 2 | " Subtraction
|
||||||
echo - 1 |" Negation (unary minus)
|
echo - 1 | " Negation (unary minus)
|
||||||
echo + 1 |" Unary plus (does nothing really, but still legal)
|
echo + 1 | " Unary plus (does nothing really, but still legal)
|
||||||
echo 1 * 2 |" Multiplication
|
echo 1 * 2 | " Multiplication
|
||||||
echo 1 / 2 |" Division
|
echo 1 / 2 | " Division
|
||||||
echo 1 % 2 |" Modulo (remainder)
|
echo 1 % 2 | " Modulo (remainder)
|
||||||
|
|
||||||
" Booleans (|Boolean|)
|
" Booleans (|Boolean|)
|
||||||
" ########
|
" ########
|
||||||
@@ -92,19 +92,19 @@ echo 1 % 2 |" Modulo (remainder)
|
|||||||
" converted to numbers (see below). There are two pre-defined semantic
|
" converted to numbers (see below). There are two pre-defined semantic
|
||||||
" constants.
|
" constants.
|
||||||
|
|
||||||
echo v:true |" Evaluates to 1 or the string 'v:true'
|
echo v:true | " Evaluates to 1 or the string 'v:true'
|
||||||
echo v:false |" Evaluates to 0 or the string 'v:false'
|
echo v:false | " Evaluates to 0 or the string 'v:false'
|
||||||
|
|
||||||
" Boolean values can result from comparison of two objects.
|
" Boolean values can result from comparison of two objects.
|
||||||
|
|
||||||
echo x == y |" Equality by value
|
echo x == y | " Equality by value
|
||||||
echo x != y |" Unequality
|
echo x != y | " Unequality
|
||||||
echo x > y |" Greater than
|
echo x > y | " Greater than
|
||||||
echo x >= y |" Greater than or equal
|
echo x >= y | " Greater than or equal
|
||||||
echo x < y |" Smaller than
|
echo x < y | " Smaller than
|
||||||
echo x <= y |" Smaller than or equal
|
echo x <= y | " Smaller than or equal
|
||||||
echo x is y |" Instance identity (lists and dictionaries)
|
echo x is y | " Instance identity (lists and dictionaries)
|
||||||
echo x isnot y |" Instance non-identity (lists and dictionaries)
|
echo x isnot y | " Instance non-identity (lists and dictionaries)
|
||||||
|
|
||||||
" Strings are compared based on their alphanumerical ordering
|
" Strings are compared based on their alphanumerical ordering
|
||||||
" echo 'a' < 'b'. Case sensitivity depends on the setting of 'ignorecase'
|
" echo 'a' < 'b'. Case sensitivity depends on the setting of 'ignorecase'
|
||||||
@@ -118,19 +118,19 @@ echo 'a' <? 'B' | " True
|
|||||||
echo 'a' <# 'B' | " False
|
echo 'a' <# 'B' | " False
|
||||||
|
|
||||||
" Regular expression matching
|
" Regular expression matching
|
||||||
echo "hi" =~ "hello" |" Regular expression match, uses 'ignorecase'
|
echo "hi" =~ "hello" | " Regular expression match, uses 'ignorecase'
|
||||||
echo "hi" =~# "hello" |" Regular expression match, case sensitive
|
echo "hi" =~# "hello" | " Regular expression match, case sensitive
|
||||||
echo "hi" =~? "hello" |" Regular expression match, case insensitive
|
echo "hi" =~? "hello" | " Regular expression match, case insensitive
|
||||||
echo "hi" !~ "hello" |" Regular expression unmatch, use 'ignorecase'
|
echo "hi" !~ "hello" | " Regular expression unmatch, use 'ignorecase'
|
||||||
echo "hi" !~# "hello" |" Regular expression unmatch, case sensitive
|
echo "hi" !~# "hello" | " Regular expression unmatch, case sensitive
|
||||||
echo "hi" !~? "hello" |" Regular expression unmatch, case insensitive
|
echo "hi" !~? "hello" | " Regular expression unmatch, case insensitive
|
||||||
|
|
||||||
" Boolean operations are possible.
|
" Boolean operations are possible.
|
||||||
|
|
||||||
echo v:true && v:false |" Logical AND
|
echo v:true && v:false | " Logical AND
|
||||||
echo v:true || v:false |" Logical OR
|
echo v:true || v:false | " Logical OR
|
||||||
echo ! v:true |" Logical NOT
|
echo ! v:true | " Logical NOT
|
||||||
echo v:true ? 'yes' : 'no' |" Ternary operator
|
echo v:true ? 'yes' : 'no' | " Ternary operator
|
||||||
|
|
||||||
|
|
||||||
" Strings (|String|)
|
" Strings (|String|)
|
||||||
@@ -140,9 +140,9 @@ echo v:true ? 'yes' : 'no' |" Ternary operator
|
|||||||
" depends on the option |'encoding'|.
|
" depends on the option |'encoding'|.
|
||||||
|
|
||||||
" Literal constructors
|
" Literal constructors
|
||||||
echo "Hello world\n" |" The last two characters stand for newline
|
echo "Hello world\n" | " The last two characters stand for newline
|
||||||
echo 'Hello world\n' |" The last two characters are literal
|
echo 'Hello world\n' | " The last two characters are literal
|
||||||
echo 'Let''s go!' |" Two single quotes become one quote character
|
echo 'Let''s go!' | " Two single quotes become one quote character
|
||||||
|
|
||||||
" Single-quote strings take all characters are literal, except two single
|
" Single-quote strings take all characters are literal, except two single
|
||||||
" quotes, which are taken to be a single quote in the string itself. See
|
" quotes, which are taken to be a single quote in the string itself. See
|
||||||
@@ -150,21 +150,21 @@ echo 'Let''s go!' |" Two single quotes become one quote character
|
|||||||
|
|
||||||
" String concatenation
|
" String concatenation
|
||||||
" The .. operator is preferred, but only supported in since Vim 8.1.1114
|
" The .. operator is preferred, but only supported in since Vim 8.1.1114
|
||||||
echo 'Hello ' . 'world' |" String concatenation
|
echo 'Hello ' . 'world' | " String concatenation
|
||||||
echo 'Hello ' .. 'world' |" String concatenation (new variant)
|
echo 'Hello ' .. 'world' | " String concatenation (new variant)
|
||||||
|
|
||||||
" String indexing
|
" String indexing
|
||||||
echo 'Hello'[0] |" First byte
|
echo 'Hello'[0] | " First byte
|
||||||
echo 'Hello'[1] |" Second byte
|
echo 'Hello'[1] | " Second byte
|
||||||
echo 'Hellö'[4] |" Returns a byte, not the character 'ö'
|
echo 'Hellö'[4] | " Returns a byte, not the character 'ö'
|
||||||
|
|
||||||
" Substrings (second index is inclusive)
|
" Substrings (second index is inclusive)
|
||||||
echo 'Hello'[:] |" Copy of entire string
|
echo 'Hello'[:] | " Copy of entire string
|
||||||
echo 'Hello'[1:3] |" Substring, second to fourth byte
|
echo 'Hello'[1:3] | " Substring, second to fourth byte
|
||||||
echo 'Hello'[1:-2] |" Substring until second to last byte
|
echo 'Hello'[1:-2] | " Substring until second to last byte
|
||||||
echo 'Hello'[1:] |" Substring with starting index
|
echo 'Hello'[1:] | " Substring with starting index
|
||||||
echo 'Hello'[:2] |" Substring with ending index
|
echo 'Hello'[:2] | " Substring with ending index
|
||||||
echo 'Hello'[-2:] |" Substring relative to end of string
|
echo 'Hello'[-2:] | " Substring relative to end of string
|
||||||
|
|
||||||
" A negative index is relative to the end of the string. See
|
" A negative index is relative to the end of the string. See
|
||||||
" |string-functions| for all string-related functions.
|
" |string-functions| for all string-related functions.
|
||||||
@@ -176,23 +176,23 @@ echo 'Hello'[-2:] |" Substring relative to end of string
|
|||||||
" objects.
|
" objects.
|
||||||
|
|
||||||
" Literal constructor
|
" Literal constructor
|
||||||
echo [] |" Empty list
|
echo [] | " Empty list
|
||||||
echo [1, 2, 'Hello'] |" List with elements
|
echo [1, 2, 'Hello'] | " List with elements
|
||||||
echo [1, 2, 'Hello', ] |" Trailing comma permitted
|
echo [1, 2, 'Hello', ] | " Trailing comma permitted
|
||||||
echo [[1, 2], 'Hello'] |" Lists can be nested arbitrarily
|
echo [[1, 2], 'Hello'] | " Lists can be nested arbitrarily
|
||||||
|
|
||||||
" List concatenation
|
" List concatenation
|
||||||
echo [1, 2] + [3, 4] |" Creates a new list
|
echo [1, 2] + [3, 4] | " Creates a new list
|
||||||
|
|
||||||
" List indexing, negative is relative to end of list (|list-index|)
|
" List indexing, negative is relative to end of list (|list-index|)
|
||||||
echo [1, 2, 3, 4][2] |" Third element
|
echo [1, 2, 3, 4][2] | " Third element
|
||||||
echo [1, 2, 3, 4][-1] |" Last element
|
echo [1, 2, 3, 4][-1] | " Last element
|
||||||
|
|
||||||
" List slicing (|sublist|)
|
" List slicing (|sublist|)
|
||||||
echo [1, 2, 3, 4][:] |" Shallow copy of entire list
|
echo [1, 2, 3, 4][:] | " Shallow copy of entire list
|
||||||
echo [1, 2, 3, 4][:2] |" Sublist until third item (inclusive)
|
echo [1, 2, 3, 4][:2] | " Sublist until third item (inclusive)
|
||||||
echo [1, 2, 3, 4][2:] |" Sublist from third item (inclusive)
|
echo [1, 2, 3, 4][2:] | " Sublist from third item (inclusive)
|
||||||
echo [1, 2, 3, 4][:-2] |" Sublist until second-to-last item (inclusive)
|
echo [1, 2, 3, 4][:-2] | " Sublist until second-to-last item (inclusive)
|
||||||
|
|
||||||
" All slicing operations create new lists. To modify a list in-place use list
|
" All slicing operations create new lists. To modify a list in-place use list
|
||||||
" functions (|list-functions|) or assign directly to an item (see below about
|
" functions (|list-functions|) or assign directly to an item (see below about
|
||||||
@@ -206,14 +206,14 @@ echo [1, 2, 3, 4][:-2] |" Sublist until second-to-last item (inclusive)
|
|||||||
" are implicitly converted to strings).
|
" are implicitly converted to strings).
|
||||||
|
|
||||||
" Dictionary literal
|
" Dictionary literal
|
||||||
echo {} |" Empty dictionary
|
echo {} | " Empty dictionary
|
||||||
echo {'a': 1, 'b': 2} |" Dictionary literal
|
echo {'a': 1, 'b': 2} | " Dictionary literal
|
||||||
echo {'a': 1, 'b': 2, } |" Trailing comma permitted
|
echo {'a': 1, 'b': 2, } | " Trailing comma permitted
|
||||||
echo {'x': {'a': 1, 'b': 2}} |" Nested dictionary
|
echo {'x': {'a': 1, 'b': 2}} | " Nested dictionary
|
||||||
|
|
||||||
" Indexing a dictionary
|
" Indexing a dictionary
|
||||||
echo {'a': 1, 'b': 2}['a'] |" Literal index
|
echo {'a': 1, 'b': 2}['a'] | " Literal index
|
||||||
echo {'a': 1, 'b': 2}.a |" Syntactic sugar for simple keys
|
echo {'a': 1, 'b': 2}.a | " Syntactic sugar for simple keys
|
||||||
|
|
||||||
" See |dict-functions| for dictionary manipulation functions.
|
" See |dict-functions| for dictionary manipulation functions.
|
||||||
|
|
||||||
@@ -225,14 +225,14 @@ echo {'a': 1, 'b': 2}.a |" Syntactic sugar for simple keys
|
|||||||
" When stored in a variable the name of the variable has the same restrictions
|
" When stored in a variable the name of the variable has the same restrictions
|
||||||
" as a function name (see below).
|
" as a function name (see below).
|
||||||
|
|
||||||
echo function('type') |" Reference to function type()
|
echo function('type') | " Reference to function type()
|
||||||
" Note that `funcref('type')` will throw an error because the argument must be
|
" Note that `funcref('type')` will throw an error because the argument must be
|
||||||
" a user-defined function; see further below for defining your own functions.
|
" a user-defined function; see further below for defining your own functions.
|
||||||
echo funcref('type') |" Reference by identity, not name
|
echo funcref('type') | " Reference by identity, not name
|
||||||
" A lambda (|lambda|) is an anonymous function; it can only contain one
|
" A lambda (|lambda|) is an anonymous function; it can only contain one
|
||||||
" expression in its body, which is also its implicit return value.
|
" expression in its body, which is also its implicit return value.
|
||||||
echo {x -> x * x} |" Anonymous function
|
echo {x -> x * x} | " Anonymous function
|
||||||
echo function('substitute', ['hello']) |" Partial function
|
echo function('substitute', ['hello']) | " Partial function
|
||||||
|
|
||||||
|
|
||||||
" Regular expression (|regular-expression|)
|
" Regular expression (|regular-expression|)
|
||||||
@@ -254,12 +254,12 @@ substitute/hello/Hello/
|
|||||||
" number becomes its decimal notation as a string. A string becomes its
|
" number becomes its decimal notation as a string. A string becomes its
|
||||||
" numerical value if it can be parsed to a number, otherwise it becomes zero.
|
" numerical value if it can be parsed to a number, otherwise it becomes zero.
|
||||||
|
|
||||||
echo "1" + 1 |" Number
|
echo "1" + 1 | " Number
|
||||||
echo "1" .. 1 |" String
|
echo "1" .. 1 | " String
|
||||||
echo "0xA" + 1 |" Number
|
echo "0xA" + 1 | " Number
|
||||||
|
|
||||||
" Strings are treated like numbers when used as booleans
|
" Strings are treated like numbers when used as booleans
|
||||||
echo "true" ? 1 : 0 |" This string is parsed to 0, which is false
|
echo "true" ? 1 : 0 | " This string is parsed to 0, which is false
|
||||||
|
|
||||||
" ###########
|
" ###########
|
||||||
" Variables
|
" Variables
|
||||||
@@ -269,41 +269,41 @@ echo "true" ? 1 : 0 |" This string is parsed to 0, which is false
|
|||||||
" chosen by Vim. Use `:let` and `:const` to bind a value and `:unlet` to unbind
|
" chosen by Vim. Use `:let` and `:const` to bind a value and `:unlet` to unbind
|
||||||
" it.
|
" it.
|
||||||
|
|
||||||
let b:my_var = 1 |" Local to current buffer
|
let b:my_var = 1 | " Local to current buffer
|
||||||
let w:my_var = 1 |" Local to current window
|
let w:my_var = 1 | " Local to current window
|
||||||
let t:my_var = 1 |" Local to current tab page
|
let t:my_var = 1 | " Local to current tab page
|
||||||
let g:my_var = 1 |" Global variable
|
let g:my_var = 1 | " Global variable
|
||||||
let l:my_var = 1 |" Local to current function (see functions below)
|
let l:my_var = 1 | " Local to current function (see functions below)
|
||||||
let s:my_var = 1 |" Local to current script file
|
let s:my_var = 1 | " Local to current script file
|
||||||
let a:my_arg = 1 |" Function argument (see functions below)
|
let a:my_arg = 1 | " Function argument (see functions below)
|
||||||
|
|
||||||
" The Vim scope is read-only
|
" The Vim scope is read-only
|
||||||
echo v:true |" Special built-in Vim variables (|v:var|)
|
echo v:true | " Special built-in Vim variables (|v:var|)
|
||||||
|
|
||||||
" Access special Vim memory like variables
|
" Access special Vim memory like variables
|
||||||
let @a = 'Hello' |" Register
|
let @a = 'Hello' | " Register
|
||||||
let $PATH='' |" Environment variable
|
let $PATH='' | " Environment variable
|
||||||
let &textwidth = 79 |" Option
|
let &textwidth = 79 | " Option
|
||||||
let &l:textwidth = 79 |" Local option
|
let &l:textwidth = 79 | " Local option
|
||||||
let &g:textwidth = 79 |" Global option
|
let &g:textwidth = 79 | " Global option
|
||||||
|
|
||||||
" Access scopes as dictionaries (can be modified like all dictionaries)
|
" Access scopes as dictionaries (can be modified like all dictionaries)
|
||||||
" See the |dict-functions|, especially |get()|, for access and manipulation
|
" See the |dict-functions|, especially |get()|, for access and manipulation
|
||||||
echo b: |" All buffer variables
|
echo b: | " All buffer variables
|
||||||
echo w: |" All window variables
|
echo w: | " All window variables
|
||||||
echo t: |" All tab page variables
|
echo t: | " All tab page variables
|
||||||
echo g: |" All global variables
|
echo g: | " All global variables
|
||||||
echo l: |" All local variables
|
echo l: | " All local variables
|
||||||
echo s: |" All script variables
|
echo s: | " All script variables
|
||||||
echo a: |" All function arguments
|
echo a: | " All function arguments
|
||||||
echo v: |" All Vim variables
|
echo v: | " All Vim variables
|
||||||
|
|
||||||
" Constant variables
|
" Constant variables
|
||||||
const x = 10 |" See |:const|, |:lockvar|
|
const x = 10 | " See |:const|, |:lockvar|
|
||||||
|
|
||||||
" Function reference variables have the same restrictions as function names
|
" Function reference variables have the same restrictions as function names
|
||||||
let IsString = {x -> type(x) == type('')} |" Global: capital letter
|
let IsString = {x -> type(x) == type('')} | " Global: capital letter
|
||||||
let s:isNumber = {x -> type(x) == type(0)} |" Local: any name allowed
|
let s:isNumber = {x -> type(x) == type(0)} | " Local: any name allowed
|
||||||
|
|
||||||
" When omitted the scope `g:` is implied, except in functions, there `l:` is
|
" When omitted the scope `g:` is implied, except in functions, there `l:` is
|
||||||
" implied.
|
" implied.
|
||||||
@@ -419,8 +419,8 @@ endtry
|
|||||||
" Unscoped function names have to start with a capital letter
|
" Unscoped function names have to start with a capital letter
|
||||||
function! AddNumbersLoudly(x, y)
|
function! AddNumbersLoudly(x, y)
|
||||||
" Use a: scope to access arguments
|
" Use a: scope to access arguments
|
||||||
echo 'Adding' .. a:x .. 'and' .. a:y |" A side effect
|
echo 'Adding' .. a:x .. 'and' .. a:y | " A side effect
|
||||||
return a:x + a:y |" A return value
|
return a:x + a:y | " A return value
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Scoped function names may start with a lower-case letter
|
" Scoped function names may start with a lower-case letter
|
||||||
@@ -448,7 +448,7 @@ endfunction
|
|||||||
|
|
||||||
" Aborting functions, abort once error occurs (|:func-abort|)
|
" Aborting functions, abort once error occurs (|:func-abort|)
|
||||||
function! SourceMyFile() abort
|
function! SourceMyFile() abort
|
||||||
source my-file.vim |" Try sourcing non-existing file
|
source my-file.vim | " Try sourcing non-existing file
|
||||||
echo 'This will never be printed'
|
echo 'This will never be printed'
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -460,11 +460,11 @@ function! MakeAdder(x)
|
|||||||
return funcref('Adder')
|
return funcref('Adder')
|
||||||
endfunction
|
endfunction
|
||||||
let AddFive = MakeAdder(5)
|
let AddFive = MakeAdder(5)
|
||||||
echo AddFive(3) |" Prints 8
|
echo AddFive(3) | " Prints 8
|
||||||
|
|
||||||
" Dictionary functions, poor man's OOP methods (|Dictionary-function|)
|
" Dictionary functions, poor man's OOP methods (|Dictionary-function|)
|
||||||
function! Mylen() dict
|
function! Mylen() dict
|
||||||
return len(self.data) |" Implicit variable self
|
return len(self.data) | " Implicit variable self
|
||||||
endfunction
|
endfunction
|
||||||
let mydict = {'data': [0, 1, 2, 3], 'len': function("Mylen")}
|
let mydict = {'data': [0, 1, 2, 3], 'len': function("Mylen")}
|
||||||
echo mydict.len()
|
echo mydict.len()
|
||||||
@@ -486,7 +486,7 @@ call sign_undefine()
|
|||||||
|
|
||||||
" The call() function calls a function reference and passes parameters as a
|
" The call() function calls a function reference and passes parameters as a
|
||||||
" list, and returns the function's result.
|
" list, and returns the function's result.
|
||||||
echo call(function('get'), [{'a': 1, 'b': 2}, 'c', 3]) |" Prints 3
|
echo call(function('get'), [{'a': 1, 'b': 2}, 'c', 3]) | " Prints 3
|
||||||
|
|
||||||
" Recall that Vim script is embedded within the ex-commands, that is why we
|
" Recall that Vim script is embedded within the ex-commands, that is why we
|
||||||
" cannot just call a function directly, we have to use the `:call` ex-command.
|
" cannot just call a function directly, we have to use the `:call` ex-command.
|
||||||
@@ -547,10 +547,10 @@ autocmd BufWritePost $MYVIMRC source $MYVIMRC
|
|||||||
" without deleting the old ones, causing auto-commands to pile up over time.
|
" without deleting the old ones, causing auto-commands to pile up over time.
|
||||||
" Use auto-groups and the following ritual to guard against this.
|
" Use auto-groups and the following ritual to guard against this.
|
||||||
|
|
||||||
augroup auto-source |" The name of the group is arbitrary
|
augroup auto-source | " The name of the group is arbitrary
|
||||||
autocmd! |" Deletes all auto-commands in the current group
|
autocmd! | " Deletes all auto-commands in the current group
|
||||||
autocmd BufWritePost $MYVIMRC source $MYVIMRC
|
autocmd BufWritePost $MYVIMRC source $MYVIMRC
|
||||||
augroup END |" Switch back to default auto-group
|
augroup END | " Switch back to default auto-group
|
||||||
|
|
||||||
" It is also possible to assign a group directly. This is useful if the
|
" It is also possible to assign a group directly. This is useful if the
|
||||||
" definition of the group is in one script and the definition of the
|
" definition of the group is in one script and the definition of the
|
||||||
@@ -570,8 +570,8 @@ autocmd auto-source BufWritePost $MYVIMRC source $MYVIMRC
|
|||||||
" Sometimes we need to construct an ex-command where part of the command is not
|
" Sometimes we need to construct an ex-command where part of the command is not
|
||||||
" known until runtime.
|
" known until runtime.
|
||||||
|
|
||||||
let line = 3 |" Line number determined at runtime
|
let line = 3 | " Line number determined at runtime
|
||||||
execute line .. 'delete' |" Delete a line
|
execute line .. 'delete' | " Delete a line
|
||||||
|
|
||||||
" Executing normal-mode commands
|
" Executing normal-mode commands
|
||||||
" ##############################
|
" ##############################
|
||||||
@@ -579,11 +579,11 @@ execute line .. 'delete' |" Delete a line
|
|||||||
" Use `:normal` to play back a sequence of normal mode commands from the
|
" Use `:normal` to play back a sequence of normal mode commands from the
|
||||||
" command-line. Add an exclamation mark to ignore user mappings.
|
" command-line. Add an exclamation mark to ignore user mappings.
|
||||||
|
|
||||||
normal! ggddGp |" Transplant first line to end of buffer
|
normal! ggddGp | " Transplant first line to end of buffer
|
||||||
|
|
||||||
" Window commands can be used with :normal, or with :wincmd if :normal would
|
" Window commands can be used with :normal, or with :wincmd if :normal would
|
||||||
" not work
|
" not work
|
||||||
wincmd L |" Move current window all the way to the right
|
wincmd L | " Move current window all the way to the right
|
||||||
|
|
||||||
|
|
||||||
" ###########################
|
" ###########################
|
||||||
@@ -591,38 +591,38 @@ wincmd L |" Move current window all the way to the right
|
|||||||
" ###########################
|
" ###########################
|
||||||
|
|
||||||
" Feature check
|
" Feature check
|
||||||
echo has('nvim') |" Running Neovim
|
echo has('nvim') | " Running Neovim
|
||||||
echo has('python3') |" Support for Python 3 plugins
|
echo has('python3') | " Support for Python 3 plugins
|
||||||
echo has('unix') |" Running on a Unix system
|
echo has('unix') | " Running on a Unix system
|
||||||
echo has('win32') |" Running on a Windows system
|
echo has('win32') | " Running on a Windows system
|
||||||
|
|
||||||
|
|
||||||
" Test if something exists
|
" Test if something exists
|
||||||
echo exists('&mouse') |" Option (exists only)
|
echo exists('&mouse') | " Option (exists only)
|
||||||
echo exists('+mouse') |" Option (exists and works)
|
echo exists('+mouse') | " Option (exists and works)
|
||||||
echo exists('$HOSTNAME') |" Environment variable
|
echo exists('$HOSTNAME') | " Environment variable
|
||||||
echo exists('*strftime') |" Built-in function
|
echo exists('*strftime') | " Built-in function
|
||||||
echo exists('**s:MyFunc') |" User-defined function
|
echo exists('**s:MyFunc') | " User-defined function
|
||||||
echo exists('bufcount') |" Variable (scope optional)
|
echo exists('bufcount') | " Variable (scope optional)
|
||||||
echo exists('my_dict["foo"]') |" Variable (dictionary entry)
|
echo exists('my_dict["foo"]') | " Variable (dictionary entry)
|
||||||
echo exists('my_dict["foo"]') |" Variable (dictionary entry)
|
echo exists('my_dict["foo"]') | " Variable (dictionary entry)
|
||||||
echo exists(':Make') |" Command
|
echo exists(':Make') | " Command
|
||||||
echo exists("#CursorHold") |" Auto-command defined for event
|
echo exists("#CursorHold") | " Auto-command defined for event
|
||||||
echo exists("#BufReadPre#*.gz") |" Event and pattern
|
echo exists("#BufReadPre#*.gz") | " Event and pattern
|
||||||
echo exists("#filetypeindent") |" Auto-command group
|
echo exists("#filetypeindent") | " Auto-command group
|
||||||
echo exists("##ColorScheme") |" Auto-commnand supported for event
|
echo exists("##ColorScheme") | " Auto-commnand supported for event
|
||||||
|
|
||||||
" Various dynamic values (see |expand()|)
|
" Various dynamic values (see |expand()|)
|
||||||
echo expand('%') |" Current file name
|
echo expand('%') | " Current file name
|
||||||
echo expand('<cword>') |" Current word under cursor
|
echo expand('<cword>') | " Current word under cursor
|
||||||
echo expand('%:p') |" Modifier are possible
|
echo expand('%:p') | " Modifier are possible
|
||||||
|
|
||||||
" Type tests
|
" Type tests
|
||||||
echo type(my_var) == type(0) |" Number
|
echo type(my_var) == type(0) | " Number
|
||||||
echo type(my_var) == type('') |" String
|
echo type(my_var) == type('') | " String
|
||||||
echo type(my_var) == type([]) |" List
|
echo type(my_var) == type([]) | " List
|
||||||
echo type(my_var) == type({}) |" Dictionary
|
echo type(my_var) == type({}) | " Dictionary
|
||||||
echo type(my_var) == type(function('type')) |" Funcref
|
echo type(my_var) == type(function('type')) | " Funcref
|
||||||
|
|
||||||
" Format strings
|
" Format strings
|
||||||
echo printf('%d in hexadecimal is %X', 123, 123)
|
echo printf('%d in hexadecimal is %X', 123, 123)
|
||||||
@@ -647,5 +647,5 @@ let g:loaded_my_plugin = v:true
|
|||||||
|
|
||||||
" Get a default value: if the user defines a variable use it, otherwise use a
|
" Get a default value: if the user defines a variable use it, otherwise use a
|
||||||
" hard-coded default. Uses the fact that a scope is also a dictionary.
|
" hard-coded default. Uses the fact that a scope is also a dictionary.
|
||||||
l
|
let s:greeting = get(g:, 'my_plugin_greeting', 'Hello')
|
||||||
```
|
```
|
||||||
|
Reference in New Issue
Block a user