In Vim, what is the “alternate file”?

The alternate file is the file that was last edited in the current window. Actually when you use some command to open a new buffer, if the buffer that was displayed had a filename associated with it, that filename is recorded as alternate file name.

Up vote 1 down vote favorite share g+ share fb share tw.

I just ran :help registers in Vim and noticed that # 'contains the name of the alternate file'. I have seen an example for renaming files that goes like this: " Save the current file, foo. Txt, as bar.

Txt :w bar. Txt " Start editing bar. Txt :e# So apparently in that case, the file you just saved out is the "alternate file.

" Can someone give me a more general definition for the "alternate file" and what else you might use it for? Vim link|improve this question asked Mar 3 '11 at 15:32Nathan Long9,618853108 68% accept rate.

– Nathan Long Mar 3 '11 at 15:32 Ooops - I meant to ask this on Superuser. Is it still possible to migrate questions from here to there? – Nathan Long Mar 3 '11 at 16:06 It can still be migrated, but it isn't off topic here.

From the stackoverflow.com FAQ: "if your question generally covers...software tools commonly used by programmers...then you’re in the right place to ask your question! " – DrAl Mar 3 '11 at 16:11.

The alternate file is the file that was last edited in the current window. Actually when you use some command to open a new buffer, if the buffer that was displayed had a filename associated with it, that filename is recorded as alternate file name. See :help alternate-file.

Very useful for... Pasting in the name of a file I've just been looking at into the current file. You can use # for this in insert mode or "#p in normal mode. Not that useful for... Jumping back and forth between two files.

It does the job very well, but this is just something I don't generally need to do. Even in the example given, I'd probably use:saveas bar. Txt instead.

An Example: Say if you're doing a bit of C programming and want to call some function. You can't remember the name of the function, so you place a mark on your current location mA and jump into several different files using tags or grep to find out where the function is declared and what it's actually called. Ah - found it.

You can copy the name and return to the mark yiw'A Uh-oh - we also need to #include the file! Easy - just use the alternate file name register to paste the file name in... Gi#include"#" Be pleased that you've avoided the distraction of having to go back to the function's declaration and copy out the file name via :let @"=@% or something similar. What I'd rather do when jumping between files: When editing two files, it's probably easier to split them, so you can keep both on screen at the same time.

If I'm editing 2 files I'll usually be comparing them in some way. Usually I'm interested in 1-3 files (any more and I get confused). I'll often jump into or directly open many other files.

Marking the interesting files, or traversing the jump list is usually the way to get around in this case. If you're editing C/C++ where you're switching between a file and it's header, use a plugin! It will be much more convenient.

I use it in the buffer context to return to the last buffer that I was editing vim foo bar :n :e# will take you back to foo in that case.

I 've always interpreted the "alternate file" as being the "previous file", so it is an handy way to jump back to the buffer you were editing.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions