diff --git a/examples/example1.vim b/examples/example1.vim new file mode 100644 index 0000000..bf243cd --- /dev/null +++ b/examples/example1.vim @@ -0,0 +1,12 @@ +python << endpython +from vim_bridge import bridged + +@bridged +def SayHello(first, last): + return "Hello, %s %s!" % (first, last) + +endpython + +" Now call directly into the Python function! +echo SayHello("John", "Doe") + " prints "Hello, John Doe!" diff --git a/examples/example2.vim b/examples/example2.vim new file mode 100644 index 0000000..10770b9 --- /dev/null +++ b/examples/example2.vim @@ -0,0 +1,11 @@ +python << endpython +from vim_bridge import bridged + +@bridged +def GetLongest(list): + return max(map(lambda s: len(s), list)) + +endpython + +echo GetLongest(['one', 'two', 'three', 'four']) + " returns 5 (because "three" is 5 chars long) diff --git a/examples/example3.vim b/examples/example3.vim new file mode 100644 index 0000000..8bd7310 --- /dev/null +++ b/examples/example3.vim @@ -0,0 +1,20 @@ +python << endpython +from vim_bridge import bridged + +@bridged +def WillCauseException(): + raise Exception("Oops") + +endpython + +" This will throw an error to the user... +echo WillCauseException() + +" But here's how you can catch that in Vim +try + echo WillCauseException() +catch + echo "Something went wrong. Aborting." +finally + echo "Cleaning up." +endtry diff --git a/examples/example4.vim b/examples/example4.vim new file mode 100644 index 0000000..e8b86cc --- /dev/null +++ b/examples/example4.vim @@ -0,0 +1,11 @@ +python << END +import os.path +from vim_bridge import bridged + +@bridged +def NormalizePath(path): + return os.path.realpath(path) +END + +echo NormalizePath("/this/../or/./.././that/is/./a/.//very/../obscure/..//././long/./../path/name") +echo NormalizePath("..")