Add a command viml
authorMikael Berthe <mikael@lilotux.net>
Wed, 18 Mar 2015 20:12:05 +0100
changeset 28 aa674a9c97c2
parent 27 77e442e4e486
child 29 e8353916b439
Add a command viml
zshrc.d/30-functions-vim.zrc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/zshrc.d/30-functions-vim.zrc	Wed Mar 18 20:12:05 2015 +0100
@@ -0,0 +1,16 @@
+
+# Change "viml file:n" to "vim file +n"
+# Based on http://www.zsh.org/mla/users/2011/msg00333.html
+#
+function viml() {
+    [[ "$#" != 1 || -r "$1" ]] && {
+        vim "$@"
+        return $?
+    }
+
+    local args
+    args=(${(s.:.)1})
+    [[ "$#args" -ge 2 && "$args[2]" == <-> ]] && \
+        command vim "$args[1]" "+$args[2]"    || \
+        command vim "$args[1]"
+}