Skip to main content
added 102 characters in body
Source Link

What it's indirectly saying is, to avoid a space in the resulting string that's executed, use .. instead of no operator at all. When there's no operator at all, each string or potentially variable is considered a separate argument.

First of all, I don't know if it's a typo on your end or if that's the actual result you're getting, but :echo 'a' 'b' for me (Vim 8.2 1-3013) echos a b. The point behind using the .. operator is to do string concatenation instead of applying "simulated" varargs that have a space appended between each argument. In a manner of speaking, the way echo and execute works can be compared to Python's print() function: If you print('a', 'b'), you get a b, but if you print(a + b), you get ab. The point is, this demonstrates that . and .. do the same thing in this specific context: it does string concatenation instead of passing "multiple arguments" to echo. You've already noticed this on your own, but combined with how execute and echo work with space-separated strings, it might be more obvious that it's just normal string concatenation. Demonstration aside, let's look at some actual evidence of that from the help.

What it's indirectly saying is, to avoid a space, use .. instead of no operator at all. When there's no operator at all, each string or potentially variable is considered a separate argument.

First of all, I don't know if it's a typo on your end or if that's the actual result you're getting, but :echo 'a' 'b' for me (Vim 8.2 1-3013) echos a b. The point behind using the .. operator is to do string concatenation instead of applying "simulated" varargs that have a space appended between each argument. In a manner of speaking, the way echo works can be compared to Python's print() function: If you print('a', 'b'), you get a b, but if you print(a + b). The point is, this demonstrates that . and .. do the same thing in this specific context: it does string concatenation instead of passing "multiple arguments" to echo. Demonstration aside, let's look at some actual evidence of that from the help.

What it's indirectly saying is, to avoid a space in the resulting string that's executed, use .. instead of no operator at all. When there's no operator at all, each string or potentially variable is considered a separate argument.

The point behind using the .. operator is to do string concatenation instead of applying "simulated" varargs that have a space appended between each argument. In a manner of speaking, the way echo and execute works can be compared to Python's print() function: If you print('a', 'b'), you get a b, but if you print(a + b), you get ab. The point is, this demonstrates that . and .. do the same thing in this specific context: it does string concatenation instead of passing "multiple arguments" to echo. You've already noticed this on your own, but combined with how execute and echo work with space-separated strings, it might be more obvious that it's just normal string concatenation. Demonstration aside, let's look at some actual evidence of that from the help.

added 14 characters in body
Source Link

First of all, I don't know if it's a typo on your end or if that's the actual result you're getting, but :echo 'a' 'b' for me (Vim 8.2 1-3013) echos a b. The point behind using the .. operator is to do string concatenation instead of applying "simulated" varargs that have a space appended between each argument. In a manner of speaking, the way echo works can be compared to Python's print() function: If you print('a', 'b'), you get a b, but if you print(a + b). The point is, this demonstrates that . and .. do the same thing in this specific context: it does string concatenation instead of passing "multiple arguments" to echo. Demonstration aside, let's look at some actual evidence of that from the help.

expr6 . expr6   String concatenation              *expr-.*  
expr6 .. expr6 
  String concatenation              *expr-..*

[...]

For String concatenation ".." is preferred, since "." is ambiguous, it
is also used for |Dict| member access and floating point numbers. When
|vimscript-version| is 2 or higher, using "." is not allowed.

First of all, I don't know if it's a typo on your end or if that's the actual result you're getting, but :echo 'a' 'b' for me (Vim 8.2 1-3013) echos a b. The point behind using the .. operator is to do string concatenation instead of applying "simulated" varargs that have a space appended between each argument. In a manner of speaking, the way echo works can be compared to Python's print() function: If you print('a', 'b'), you get a b, but if you print(a + b). The point is, this demonstrates that . and .. do the same thing in this specific context: it does string concatenation instead of passing "multiple arguments" to echo. Demonstration aside, let's look at some actual evidence of that.

expr6 . expr6   String concatenation              *expr-.* expr6 .. expr6 
 String concatenation              *expr-..*

[...]

For String concatenation ".." is preferred, since "." is ambiguous, it
is also used for |Dict| member access and floating point numbers. When
|vimscript-version| is 2 or higher, using "." is not allowed.

First of all, I don't know if it's a typo on your end or if that's the actual result you're getting, but :echo 'a' 'b' for me (Vim 8.2 1-3013) echos a b. The point behind using the .. operator is to do string concatenation instead of applying "simulated" varargs that have a space appended between each argument. In a manner of speaking, the way echo works can be compared to Python's print() function: If you print('a', 'b'), you get a b, but if you print(a + b). The point is, this demonstrates that . and .. do the same thing in this specific context: it does string concatenation instead of passing "multiple arguments" to echo. Demonstration aside, let's look at some actual evidence of that from the help.

expr6 . expr6   String concatenation              *expr-.* 
expr6 .. expr6  String concatenation              *expr-..*

[...]

For String concatenation ".." is preferred, since "." is ambiguous, it
is also used for |Dict| member access and floating point numbers. When
|vimscript-version| is 2 or higher, using "." is not allowed.
added 310 characters in body
Source Link

As for finding it, I personally wrote :h .<tab> and used wildmenu to navigate until I found something that looked like it could workbe relevant ("expr-. looks awfully relevant given that it's used in an expression"). A more searchable option (in this case) would've been to use :helpgrep \cstring concatenation (\c means case-insensitive). This also gives a lot of additional help that covers . and .., and some of which again repeats how . is ambiguous and that .. is preferred.

See also this fantastic answer on navigating Vim's documentation - a part of it is still guessing relevant keywords, although that's not too different from using a search engine if you prefer thinking about it like that. (Documentation sprawl doesn't help either :) )

As for finding it, I personally wrote :h .<tab> and used wildmenu to navigate until I found something that looked like it could work. A more searchable option (in this case) would've been to use :helpgrep \cstring concatenation (\c means case-insensitive). This also gives a lot of additional help that covers . and .., and some of which again repeats how . is ambiguous.

See also this fantastic answer on navigating Vim's documentation.

As for finding it, I personally wrote :h .<tab> and used wildmenu to navigate until I found something that looked like it could be relevant ("expr-. looks awfully relevant given that it's used in an expression"). A more searchable option (in this case) would've been to use :helpgrep \cstring concatenation (\c means case-insensitive). This also gives a lot of additional help that covers . and .., and some of which again repeats how . is ambiguous and that .. is preferred.

See also this fantastic answer on navigating Vim's documentation - a part of it is still guessing relevant keywords, although that's not too different from using a search engine if you prefer thinking about it like that. (Documentation sprawl doesn't help either :) )

Source Link
Loading