Vimscript: String concatenation, substring and character regex matches

The dot concatenates strings: let str = "one thing" . "another".

let pos = match("one thing", "thing") returns 4, the point where thing starts.

let str1 = str[0:pos] splits the string from position 0 until 4 (as above). It returns one .

With a string slice as above, you can use negative numbers, i.e. -1 means the end of the string.

function Hi()
  let str = "one thing " . "another"
  let pos = match(str, "thing")
  let str = str[pos:-1]
  echo str 

:call Hi() will print thing another.


Edit on github
comments powered by Disqus
Click me