Thursday, March 21, 2019

Re: Get highest Vim buffer number

On Thu, Mar 21, 2019 at 4:53 PM DwigtArmyOfChampions
<dwightarmyofchampions@hotmail.com> wrote:
>
> I have the following line in my vimrc file. This is for vimdiff:
>
> " dp will send middle pane changes to right pane and then immediately
> " update.
> nnoremap dp :diffput 3 <bar> :diffupdate<cr>
>
> However, this only works if I'm using vimdiff with three files. If I am diff'ing two files, then calling "diffput 3" gives an error message because there is no buffer #3. How do I change the 3 to "buffer of rightmost pane"? Or separate this command into two statements? Something like the following:
>
> If (two files are being compared) Then
> nnoremap dp :diffput 2 <bar> :diffupdate<cr>
>
> ElseIf (three files are being compared) Then
> nnoremap dp :diffput 3 <bar> :diffupdate<cr>
> End If

If you know the error number, you could call a function which would do
something like the following (replacing E123 by the actual error
number):

function s:DiffPut()
try
diffput 3
catch /^Vim\%((\a\+)\)\=:E123:/
diffput 2
endtry
diffupdate
endfunction
map dp call <SID>DiffPut()

see
:help try
and about two pages of scrolldown thereafter.

Note, however, that if you invoke the built-in help, every helpfile
you view will get its own buffer number. These files are
'nomodifiable' however, so you will get a different error number than
the one telling you you're trying to access a nonexistent buffer.

Best regards,
Tony.

--
--
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:

Post a Comment