On Mon, Jan 14, 2013 at 11:51 AM, Ben Fritz <[email protected]> wrote: > On Monday, January 14, 2013 10:32:04 AM UTC-6, Jack Gates wrote: >> >> > In what context? Do you want to insert the file name into the file? Access >> > the file name on the command-line? Something else? If you tell us what >> > you're trying to accomplish we can help better. >> >> I was thinking about using the file name in a mapping doing s/// >> editing a chunk of text dumped in the file from a register. I really >> don't know what to ask because I don't really understand this enough >> to figure out how I might use it. In one of my emails I was asking >> about doing s/// and using the contents from a register on the RHS. >> > > What would you need the filename for? Do you need to change it at all? > > You can put the filename unchanged into the command-line or the file text > using CTRL-R followed by % (if you're in the command-line, or in insert mode). > > You can access the filename in a script using expand("%"). You can add > modifiers, for example if the current file is /a/b/c.txt, you can get "/a/b" > with expand("%:p:h"). > > You can use the filename without ever expanding it in certain commands, for > example if you're editing myfile.c and want to also view myfile.h you can use > a command like: > > :split %:r.h > > See :help filename-modifiers, :help expand(), :help fnamemodify() > >> Doing this manually is easier to accomplish than it is trying to get a >> mapping to do things automated so I don't have to do it manually. >> >> Figuring out how to use "% will probably also answer my question in >> the newest post I made today. >> >> I have a series of commands that are nearly complete. So I can yank >> some text execute the mapping and have it create a new file from start >> to finish with the yanked text. >> > > If you build the name of the new file from the current file's name, it's > probably easiest to use the last method I show. > > For example, when editing a.txt, if you want to create file a.1.txt and > a.2.txt, you can use: > > :new %:r.1.%:e > > If it's more complex, for example if you want to include today's date in the > filename, you probably want to use the :execute and expand() instead: > > :execute "new" expand("%:r").strftime(".%Y-%m-%d.").expand("%:e") > > Also see my comment about using :write on your other thread. Maybe you don't > need to yank anything. >
Ben thanks! I will read those help sections and mess around with your examples. I think you just gave me what I was looking for. You Rock! -- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php
