Setting the status line to something specific...

7 views
Skip to first unread message

Chris Jones

unread,
Nov 28, 2008, 6:00:07 PM11/28/08
to v...@vim.org

Hello vim users:

I currently use a script by Gary Johnson:
http://vim.sourceforge.net/scripts/script.php?script_id=610
(based on Alexey Marinichev's ctags.vim script)

to set my status line to include the current C++ function that I'm in on
the status line. I use this because of really long functions (yes I'm a
bad progammer), but sometimes just small windows.

I would like something similar for when I'm viewing a .diff file.
These can get very lengthy and similar to the functions I would like to
know what specific diff Index: file I'm looking at displayed in the the
status line.

Does someone have a script or simple solution to what I need?

Much appreciated.

Cheers,
Chris


--
Monday morning: BC Translink driver on a full bus and cranky passengers:
"I guess its because nobody won the 'Super-7' on Friday".

Tony Mechelynck

unread,
Nov 29, 2008, 5:58:50 AM11/29/08
to v...@vim.org
On 29/11/08 00:00, Chris Jones wrote:
>
> Hello vim users:
>
> I currently use a script by Gary Johnson:
> http://vim.sourceforge.net/scripts/script.php?script_id=610
> (based on Alexey Marinichev's ctags.vim script)
>
> to set my status line to include the current C++ function that I'm in on
> the status line. I use this because of really long functions (yes I'm a
> bad progammer), but sometimes just small windows.
>
> I would like something similar for when I'm viewing a .diff file.
> These can get very lengthy and similar to the functions I would like to
> know what specific diff Index: file I'm looking at displayed in the the
> status line.
>
> Does someone have a script or simple solution to what I need?
>
> Much appreciated.
>
> Cheers,
> Chris

Write a function which returns the name of the current file (if any)
when viewing a patch. There is not always an "Index:" line, see e.g.
Bram's patches at ftp://ftp.vim.org/pub/vim/patches/7.2/ with filenames
7.2.001 to (at the moment) 7.2.055

Then insert in your custom 'statusline' an expression part, for instance

%{(&ft\ ==\ 'diff')?IndexName():''}

which inserts the return value of the function when 'filetype' is set to
"diff", the empty string otherwise. (Remember that, as has been done
above, spaces, double quotes, vertical bars and literal backslashes must
be backslash-escaped in the argument of a ":set" command.)


Best regards,
Tony.
--
Beneath this stone a virgin lies,
For her life held no terrors.
A virgin born, a virgin died:
No hits, no runs, no errors.

Tony Mechelynck

unread,
Dec 2, 2008, 5:02:12 PM12/2/08
to Chris Jones, Vim List
On 02/12/08 22:10, Chris Jones wrote:
> Tony;
>
> I appreciate your response. I'm just having trouble with creating this
> function now.
>
> I guess I'm not familiar enough with vim's scripting to create something
> simple to just look back for the "Index:" line. Copy the rest of that
> line to a variable then go back to where I was.
>
> I know not all .diffs will have this, but all the ones I generate will,
> so this is a good starting point.
>
> If you could give me a pointer to the internals I can go do more
> digging.
>
> Cheers,
> Chris
>

First, I'm intentionally Cc-ing this reply to the vim-list so other
long-time Vim users will see it and maybe give a different or better reply.

Everything about Vim (and I mean _everything_) is explained in its help.
This may at times create a needle-and-haystack problem, but even to
overcome this there are built-in tools.

First, if you haven't yet, run the vimtutor program. It will teach you
the basics.

Then, at any time, you may want to use the following commands:

:help
opens the first page of help, with, at the bottom, the list of all
installed help files, with a clickable name (well, double-clickable or
Ctrl-]-able) and a one-line description for each of them.

:help {subject}
(where {subject} is as you see it: open-brace, small-ess, small-you,
small-bee, small-jay, small-ee, small-cee, small-tee, close-brace)
explains how to look for help on a given subject (if the help tag exists)

In 'nocompatible' mode, and with 'wildmenu' on (the latter is not the
default),
:help abc<Tab>
(where <Tab> means "hit the Tab key) will display on the bottom status
line a menu of all help subjects which include the letter-group abc (if
there are at least two of them). Similarly for other part-names, and you
can use the ? and * wildcards as in file names. Use <Left> or <Right> to
select an item, <Enter> to accept, <Esc> to cancel. If there is a > at
far right and/or a < at far left (or both) it means there are more menu
items than can be displayed on one line.
If there is only one match for what you typed it will be filled-in
(hit <Enter> to see that help page), and if nothing matches you'll get a
beep and nothing else will change (hit <Esc> to go back to Normal
editing mode).

:help abc<Ctrl-D>
(where you can use ? and * wildcards as above) will display all matches
at once, on several lines if necessary. If there are more than fill one
full screen, I think you'll see only the first screen (the "best"
matches, for a certain definition of "best"). You can then choose and
type what you want. (I personally prefer the menu method as with <Tab>
above, but I'm mentioning this too, in case you might prefer it.)

:helpgrep {pattern}
(where {pattern} is a Vim-style regular expression) will search the full
text of all the help for matches to the regular expression, and display
the first one if any. To see other matches, you can use the commands
:cnext
:cprev
:cfirst
:clast
:cnfile
:cpfile
You can even reassign these commands to keys (they are what is called
"quickfix" commands, see ":help quickfix.txt"), for instance as follows:

:map <F2> :cnext<CR>
:map <S-F2> :cprev<CR>


I'm afraid this does not directly answer your question about writing a
function for a particular purpose. Here are a few additional pointers:
:help :function
:help search()
:help pattern.txt
:help getline()
:help line()
:help substitute()
:help :substitute


Best regards,
Tony.
--
Good day to let down old friends who need help.

Reply all
Reply to author
Forward
0 new messages