so that syntax highlighting works in the
preview window. The "silent!" avoids an error message when the tag could not
be found. Also see |CursorHold|. To disable this again: >
:au! CursorHold
A nice addition is to highlight the found tag, avoid the ":ptag" when there
is no word under the cursor, and a few other things: >
:au! CursorHold *.[ch] ++nested call PreviewWord()
:func PreviewWord()
: if &previewwindow " don't do this in the preview window
: return
: endif
: let w = expand("<cword>") " get the word under cursor
: if w =~ '\a' " if the word contains a letter
:
: " Delete any existing highlight before showing another tag
: silent! wincmd P " jump to preview window
: if &previewwindow " if we really get there...
: match none " delete existing highlight
: wincmd p " back to old window
: endif
:
: " Try displaying a matching tag for the word under the cursor
: try
: exe "ptag " .. w
: catch
: return
: endtry
:
: silent! wincmd P " jump to preview window
: if &previewwindow " if we really get there...
: if has("folding")
: silent! .foldopen " don't want a closed fold
: endif
: call search("$", "b") " to end of previous line
: let w = substitute(w, '\\', '\\\\', "")
: call search('\<\V' .. w .. '\>') " position cursor on match
: " Add a match highlight to the word at this position
: hi previewWord term=bold ctermbg=green guibg=green
: exe 'match previewWord "\%' .. line(".") .. 'l\%' .. col(".") .. 'c\k*"'
: wincmd p " back to old window
: endif
: endif
:endfun
==============================================================================
11. Using hidden buffers *buffer-hidden*
A hidden buffer is not displayed in a window, but is still loaded into memory.
This makes it possible to jump from file to file, without the need to read or
write the file every time you get another buffer in a window.
*:buffer-!*
If the option 'hidden' ('hid') is set, abandoned buffers are kept for all
commands that start editing another file: ":edit", ":next", ":tag", etc. The
commands that move through the buffer list sometimes make the current buffer
hidden although the 'hidden' option is not set. This happens when a buffer is
modified, but is forced (with '!') to be removed from a window, and
'autowrite' is off or the buffer can't be written.
You can make a hidden buffer not hidden by starting to edit it with any
command, or by deleting it with the ":bdelete" command.
The 'hidden' is global, it is used for all buffers. The 'bufhidden' option
can be used to make an exception for a specific buffer. It can take these
values:
<empty> Use the value of 'hidden'.
hide Hide this buffer, also when 'hidden' is not set.
unload Don't hide but unload this buffer, also when 'hidden'
is set.
delete Delete the buffer.
*hidden-quit*
When you try to quit Vim while there is a hidden, modified buffer, you will
get an error message and Vim will make that buffer the current buffer. You
can then decide to write this buffer (":wq") or quit without writing (":q!").
Be careful: there may be more hidden, modified buffers!
A buffer can also be unlisted. This means it exists, but it is not in the
list of buffers. |unlisted-buffer|
:files[!] [flags] *:files*
:buffers[!] [flags] *:buffers* *:ls*
:ls[!] [flags]
Show all buffers. Example:
1 #h "/test/text" line 1 ~
2u "asdf" line 0 ~
3 %a + "version.c" line 1 ~
When the [!] is included the list will show unlisted buffers
(the term "unlisted" is a bit confusing then...).
Each buffer has a unique number. That number will not change,
thus you can always go to a specific buffer with ":buffer N"
or "N CTRL-^", where N is the buffer number.
Indicators (chars in the same column are mutually exclusive):
u an unlisted buffer (only displayed when [!] is used)
|unlisted-buffer|