Tip 1484 Printable Monobook Previous Next

created January 21, 2007 · complexity intermediate · author alpt · version n/a

Suppose you open file.c, you edit it and then you jump on a tag, defined in another file, using <C-]>.

If you didn't save the modified buffer you'll just get:

"E37: No write since last change (add ! to override)"

To overcome this, put the following code in your vimrc.

fun! SPLITAG() range
  let oldfile=expand("%:p")
  if &modified
  exe "tag ". expand("<cword>")
  let curfile=expand("%:p")
  if curfile == oldfile
    let pos=getpos(".")
    if &modified
      " if we have split before:
    call setpos('.', pos)
nmap <C-]> :call SPLITAG()<CR>z.


To use this tip for 'gf' it should be sufficient to replace

exe "tag ". expand("<cword>")


exe "normal gf"

:set switchbuf=split
:help 'switchbuf

Ctrl-W Ctrl-]

CTRL-W CTRL-] doesn't give the same level of laziness of this tip. Why should I remember to use CTRL-W CTRL-], when I can press CTRL-] all the time?


:set hidden

and you won't see "E37: No write since last change (add ! to override)"

Or, add "set confirm" and you will be prompted to save, abandon changes, or cancel.

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.