Wikia

Vim Tips Wiki

Changes: When jumping on a tag, automatically split the window if the current buffer has been modified

Edit

Back to page

m (category and comment)
 
Line 9: Line 9:
 
|version=n/a
 
|version=n/a
 
|rating=17/7
 
|rating=17/7
|category1=
+
|category1=Navigation
 
|category2=
 
|category2=
 
}}
 
}}
Line 72: Line 72:
   
 
and you won't see "E37: No write since last change (add ! to override)"
 
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.

Latest revision as of 15:47, May 3, 2011

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
    split
  endif
  exe "tag ". expand("<cword>")
  let curfile=expand("%:p")
  if curfile == oldfile
    let pos=getpos(".")
    if &modified
      " if we have split before:
      quit
    endif
    call setpos('.', pos)
  endif
endfun
nmap <C-]> :call SPLITAG()<CR>z.

CommentsEdit

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

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

with

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?


Alternatively

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

Around Wikia's network

Random Wiki