Saturday, September 13, 2014

Re: How to launch kdiff3 to compare 2 neighbouring windows in VIM

On Saturday, September 13, 2014 3:49:25 PM UTC-5, 颖黄 wrote:
> Hi
>
> I am trying to launch kdiff3 to compare two neighbouring windows in vim,
>
> could some one suggest me a solution?
>
> Currently my idea is trying to use " register to save the file name of the
>
> first window,

This is possible, but not necessary. It will also override any yank/copy or delete operation that you may already have in the "unnamed register" ". Is there some reason you put it in the unnamed register rather than some variable?

> and use %:p to get current file name, and then call kdiff3 to
>
> compare these two windows.
>
> But somehow, it does not work. Could someone help me with this issue?
>
> As shown bellow
>
>
>
> [code]nnoremap <leader>1 :let @"=expand("%:p")<CR>
>
>

This shows correct use of accessing the unnamed register in script. This is how you should do it, if you insist on using the register.

But it's probably better to use a variable instead, as I mentioned:

nnoremap <leader>1 :let file1=expand("%:p")<CR>

>
> function! CompareTwoFiles()
>
> !kdiff3 "" expand("%:p")
>

Here, inexplicably, you decide that accessing the unnamed register is done with "" rather than @" as you used before.

Additionally, the :! command does not accept strings for arguments, it just passes the text verbatim to the shell. So you need to use :execute, giving you this command instead:

execute '!kdiff3' @" expand("%:p")

Or, if using a variable rather than a register:

execute '!kdiff3' file1 expand("%:p")

(note from :help :execute that multiple expressions have their string result concatenated together with spaces prior to running the command)

> endfunc
>
>
>
> nnoremap <leader>2 :call CompareTwoFiles()<cr> [/code]
>

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: