Skip to content

Commit

Permalink
Add some example Vim sciprts that use the bridge.
Browse files Browse the repository at this point in the history
  • Loading branch information
nvie committed Jul 27, 2010
1 parent b5cc723 commit 91b4578
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
12 changes: 12 additions & 0 deletions 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!"
11 changes: 11 additions & 0 deletions 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)
20 changes: 20 additions & 0 deletions 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
11 changes: 11 additions & 0 deletions 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("..")

0 comments on commit 91b4578

Please sign in to comment.