-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasics.vim
More file actions
123 lines (95 loc) · 2.34 KB
/
basics.vim
File metadata and controls
123 lines (95 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
" Set assignment can only set to single literal values
set textwidth=100
" Let assignments can determine the values
let &textwidth = &textwidth + 10
" Local variable assignment with prefixes
let &l:number = 1
" Variable local to buffer
let b:hello = "world"
" Conditionals
if 0
echom "if"
elseif "nope!"
echom "elseif"
else
echom "finally!"
endif
" Case Sensitivity is determined by the users settings
" the following will echo: vim is case sensitive
set noignorecase
if "foo" == "FOO"
echom "vim is case insensitive"
elseif "foo" == "foo"
echom "vim is case sensitive"
endif
" While this will echo: vim is case insensitive
set ignorecase
if "foo" == "FOO"
echom "vim is case insensitive"
elseif "foo" == "foo"
echom "vim is case sensitive"
endif
" Because of the above vim has two additional operators
" ==? Which is case-insensitive no matter what the user
" has set, and ==# which is case-sensitive.
" Functions must be defined with a capital letter.
function Meow()
echom "Meow!"
endfunction
" Calling
call Meow()
" Returning
function GetMeow()
return "Meow String!"
endfunction
echom GetMeow()
" Implicit returning, if nothing is returned it returns
" a 0
function TextwidthIsTooWide()
if &l:textwidth ># 80
return 1
endif
endfunction
set textwidth=80
if TextwidthIsTooWide()
echom "WARNING: Wide text!"
endif
" Arguments
function DisplayName(name)
echom "Hello! My name is:"
echom a:name
endfunction
" We provide the a: to represent the variable scope.
" otherwise vim won't be able to find the variable name.
" Varargs
function Varg(...)
echom a:0
echom a:1
echom a:000
endfunction
call Varg("a", "b")
" The ellipsis tells vim that this function can take any
" number of arguments. When we echo a:0 this will display 2
" since this argument tells us of how many args were passed.
" a:1 displays the first extra argument. etc.
"
" Args in the a: scope can not be reassigned.
" Numbers can be resolved from hex notation using echom.
echom 0xff
" String concatenation
" Vim has a concatenation operator, using .
echom "Hello, " . "world"
" Vim String Functions
" split - splits by a separator
" split('one, two, three', ',')
"
" join - joins by a separator
" join(['foo", 'bar'], '...')
"
" tolower - lowercases
" tolower('Foo')
"
" toupper - uppercases
" toupper('Foo')
"
" Chapter 38