I have this shortcut in my vimrc:
我的vimrc中有这个快捷方式:
map cmt :!start TortoiseProc.exe /command:commit /path:"%" /closeonend:3 <CR>
map cmt:!start TortoiseProc.exe / command:commit / path:“%”/ closeonend:3
What this does is whenever I press 'cmt', vim will open the commit dialog for the file I'm currently editing with vim.
这样做的是每当我按下'cmt'时,vim将打开我正在用vim编辑的文件的提交对话框。
What I'd like to do is write this command in such a way that if I put a number in front of it, it will open the commit dialog for the n-th level directory.
我想要做的是以这样一种方式编写这个命令:如果我在它前面放一个数字,它将打开第n级目录的提交对话框。
Example to make things clearer:
让事情更清晰的例子:
Let's say I have this file structure project/logs/access.log
. If I'm editing access.log
and
假设我有这个文件结构项目/ logs / access.log。如果我正在编辑access.log和
- press 'cmt' - I should get the dialog for committing
access.log
; - 按'cmt' - 我应该得到提交access.log的对话框;
- press '1cmt' - I should get the dialog for committing the
logs
directory; - 按'1cmt' - 我应该得到提交日志目录的对话框;
- press '2cmt' - I should get the dialog for committing the
project
directory; - 按'2cmt' - 我应该得到提交项目目录的对话框;
... and so on.
... 等等。
Note: I'm using gvim on Windows 7
注意:我在Windows 7上使用gvim
Hopefully someone can help me with this. Thanks.
希望有人可以帮助我。谢谢。
1 个解决方案
#1
1
I've implemented the desired functionality in the following function. It takes two arguments: a path to the file to start from, and a number of levels to go up. Then it cuts the specified number of tailing path components, and builds up the command to run (according to your example). Then it runs the command and checks exit code returned by shell after execution. If an error has occurred, error message together with command output are shown.
我在以下函数中实现了所需的功能。它需要两个参数:一个开始文件的路径,以及一些要升级的级别。然后它剪切指定数量的拖尾路径组件,并构建运行命令(根据您的示例)。然后它运行命令并在执行后检查shell返回的退出代码。如果发生错误,则会显示错误消息和命令输出。
function! TortoiseCommitDialog(path, count)
let pat = '[/\\]\@<=\%([^/\\]\+[/\\]\?\)\{' . a:count . '}$'
let path = substitute(a:path, pat, '', '')
let cmd = 'TortoiseProc.exe /command:commit ' .
\ '/path:' . shellescape(path) . ' /closeonend:3'
let out = system(cmd)
if v:shell_error
echoerr 'Failed to run Tortoise commit dialog'
echo out
end
endfunction
To use this function during editing, I recommend to define a command (because it can handle arguments unlike mapping) like this:
要在编辑期间使用此功能,我建议定义一个命令(因为它可以处理与映射不同的参数),如下所示:
command! -count Cmt call TortoiseCommitDialog(expand('%:p'), <count>)
Because of -count
flag you can run the command with count two ways: :3Cmt
and :Cmt 3
(or even without space: :Cmt3
).
由于-count标志,您可以通过两种方式运行命令:: 3Cmt和:Cmt 3(甚至没有空格:: Cmt3)。
#1
1
I've implemented the desired functionality in the following function. It takes two arguments: a path to the file to start from, and a number of levels to go up. Then it cuts the specified number of tailing path components, and builds up the command to run (according to your example). Then it runs the command and checks exit code returned by shell after execution. If an error has occurred, error message together with command output are shown.
我在以下函数中实现了所需的功能。它需要两个参数:一个开始文件的路径,以及一些要升级的级别。然后它剪切指定数量的拖尾路径组件,并构建运行命令(根据您的示例)。然后它运行命令并在执行后检查shell返回的退出代码。如果发生错误,则会显示错误消息和命令输出。
function! TortoiseCommitDialog(path, count)
let pat = '[/\\]\@<=\%([^/\\]\+[/\\]\?\)\{' . a:count . '}$'
let path = substitute(a:path, pat, '', '')
let cmd = 'TortoiseProc.exe /command:commit ' .
\ '/path:' . shellescape(path) . ' /closeonend:3'
let out = system(cmd)
if v:shell_error
echoerr 'Failed to run Tortoise commit dialog'
echo out
end
endfunction
To use this function during editing, I recommend to define a command (because it can handle arguments unlike mapping) like this:
要在编辑期间使用此功能,我建议定义一个命令(因为它可以处理与映射不同的参数),如下所示:
command! -count Cmt call TortoiseCommitDialog(expand('%:p'), <count>)
Because of -count
flag you can run the command with count two ways: :3Cmt
and :Cmt 3
(or even without space: :Cmt3
).
由于-count标志,您可以通过两种方式运行命令:: 3Cmt和:Cmt 3(甚至没有空格:: Cmt3)。