Monday, November 2, 2009

Knowing Where You Are

If you want to know the current filename, what percentage of the current file you're editing, whether the current file has been modified, or the character or line position, all you have to do is hit ctrl-g from normal mode inside Vim.


Anonymous said...

I love these little tidbits -- please keep 'em coming!

arthur said...

g^g will also give you a word count.

dan said...

If you think that info is useful and want to see it all the time, put this in your .vimrc (hopefully it will format well in these comments):

set laststatus=2
set statusline=%f\ \ %y\ \ %3.3m%4.4r%=%l\ /\ %L,\ %c\ \

Feel free to customize... key:
%f - filename
%y - file type
%m - modified flag
%l - line lumber of cursor
%L - total number of lines
%c - column number of cursor

See ':help statusline' for more options
%r - read only

Alex said...

I have a script up on that can search backwards for the most recent function declaration to tell you what function you're editing in, and what line number it starts on. It catches most styles of function declarations in C, C++, Python, and Perl. I'm working on beefing up the regex to include Objective-C. Jave is a little bit tricky since function/method declarations are harder to find when they don't start at column 0...

Lukyn said...

Dan, thanks a lot for your post. That's great to know where you are ;-)