Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
oh-my-zsh
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
github
oh-my-zsh
Commits
d87f29f5
Unverified
Commit
d87f29f5
authored
Sep 23, 2021
by
Marc Cornellà
Committed by
GitHub
Sep 23, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(vim-interaction): clean up code and open gvim instance if none open (#10209)
Co-authored-by:
Kevin Bader
<
keb@visotech.at
>
parent
5b3d2b2f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
21 deletions
+27
-21
vim-interaction.plugin.zsh
plugins/vim-interaction/vim-interaction.plugin.zsh
+27
-21
No files found.
plugins/vim-interaction/vim-interaction.plugin.zsh
View file @
d87f29f5
...
...
@@ -4,8 +4,7 @@
# Derek Wyatt (derek@{myfirstnamemylastname}.org
#
function
callvim
{
function
callvim
{
if
[[
$#
==
0
]]
;
then
cat
<<
EOH
usage: callvim [-b cmd] [-a cmd] [-n name] [file ... fileN]
...
...
@@ -19,11 +18,20 @@ EOH
return
0
fi
local
cmd
=
""
local
before
=
"<esc>"
local
after
=
""
# Look up the newest instance
# Look up the newest instance or start one
local
name
=
"
$(
gvim
--serverlist
|
tail
-n
1
)
"
[[
-n
"
$name
"
]]
||
{
# run gvim or exit if it fails
gvim
||
return
$?
# wait for gvim instance to fully load
while
name
=
$(
gvim
--serverlist
)
&&
[[
-z
"
$name
"
]]
;
do
sleep
0.1
done
}
local
before
=
"<esc>"
files after cmd
while
getopts
":b:a:n:"
option
do
case
$option
in
...
...
@@ -36,22 +44,20 @@ EOH
esac
done
shift
$((
OPTIND-1
))
if
[[
${
after
#
:
}
!=
$after
&&
${
after
%<cr>
}
==
$after
]]
;
then
after
=
"
$after
<cr>"
fi
if
[[
${
before
#
:
}
!=
$before
&&
${
before
%<cr>
}
==
$before
]]
;
then
before
=
"
$before
<cr>"
fi
local
files
if
[[
$#
-gt
0
]]
;
then
# absolute path of files resolving symlinks (:A) and quoting special chars (:q)
files
=
':args! '
"
${
@
:A:q
}
<cr>"
fi
# If before or after commands begin with : and don't end with <cr>, append it
[[
${
after
}
=
:
*
&&
${
after
}
!=
*
\<
cr
\>
]]
&&
after+
=
"<cr>"
[[
${
before
}
=
:
*
&&
${
before
}
!=
*
\<
cr
\>
]]
&&
before+
=
"<cr>"
# Open files passed (:A means abs path resolving symlinks, :q means quoting special chars)
[[
$#
-gt
0
]]
&&
files
=
':args! '
"
${
@
:A:q
}
<cr>"
# Pass the built vim command to gvim
cmd
=
"
$before$files$after
"
gvim
--servername
"
$name
"
--remote-send
"
$cmd
"
if
typeset
-f
postCallVim
>
/dev/null
;
then
postCallVim
fi
# Run the gvim command
gvim
--servername
"
$name
"
--remote-send
"
$cmd
"
||
return
$?
# Run postCallVim if defined (maybe to bring focus to gvim, see README)
((
!
$+
functions[postCallVim]
))
||
postCallVim
}
alias
v
=
callvim
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment