4

I'm using MacVim and I usually have a number of tabs open. I'd like to be able to drop marks in any of my open files and jump between them. mK and K work great when the mark is in the same tab but I've got to use gt to find the tab and then K to find the marker... there must be a better way?

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
ad rees
  • 1,522
  • 2
  • 11
  • 16
  • 5
    This may be out of line, but I have a funny feeling [this](http://stackoverflow.com/questions/102384/using-vims-tabs-like-buffers/103590#103590) answer applies here. – Randy Morris Jan 05 '11 at 13:29
  • Yes I think you are right. I'm trying to make vim into my previous editor and actually I'd be better off trying doing away with tabs. – ad rees Jan 05 '11 at 15:42

1 Answers1

3

Here is a quick and dirty hack that answers your need.

let s:marks = {}

function! s:Mark(name)
  echomsg "new mark: " a:name
  " todo: record the winnr/bufnr as well
  let s:marks[a:name] = tabpagenr()
  exe 'normal! m'.a:name
endfunction

function! s:Jump(how, name)
  if has_key(s:marks, a:name)
    let nr = s:marks[a:name]
    tabfirst
    let first = tabpagenr()
    while tabpagenr() != nr
      tabnext
      if tabpagenr() == first
 break
      endif
    endwhile
    if tabpagenr() == nr
      exe 'normal! '.a:how.a:name
      " nominal termination
      return
    endif
  endif
  echoerr "tab-mark " . a:name . " not set"
endfunction

nnoremap m :call <sid>Mark(nr2char(getchar()))<cr>
nnoremap ` :call <sid>Jump('`', nr2char(getchar()))<cr>
nnoremap ' :call <sid>Jump("'", nr2char(getchar()))<cr>

Issues:

  • marks are different for each buffer normally. Here, all the marks are global. May be, we should instead provide mappings to \m, \', ang \*backtick*

  • This does not take split windows into account.

Luc Hermitte
  • 31,979
  • 7
  • 69
  • 83