Thursday, February 23, 2012

Re: Check if file is being edited with ++ff

On Feb 23, 1:50 pm, Christian Brabandt <cbli...@256bit.org> wrote:
> Hi Ben!
>
> On Do, 23 Feb 2012, Ben Fritz wrote:
>
>
>
>
>
> > I've got a BufReadPost autocmd in my .vimrc which will automatically
> > reload a file in DOS or Unix fileformat using e ++ff=dos or e +
> > +ff=unix if it is in mixed line-ending format, depending on whether
> > there are more lines with or without a trailing ^M.
>
> > It works well, but I sometimes want to force it to load one way or the
> > other, with an explicit :e ++ff=unix for example.
>
> > So, I'm trying to modify my autocmd to only act if I did not
> > explicitly specify the fileformat on the command-line. I've tried
> > using @:, but that does not seem to get updated until after my autocmd
> > fires. I've tried using getcmdline(), but that is invalid (and returns
> > an empty string) because the command-line is not currently being
> > edited when the autocmd fires.
>
> > My only other though is to set up a cnoremap <expr> mapping which maps
> > <CR> to a function which stores off the getcmdline() result to a
> > variable, then returns "\<CR>", so that it doesn't actually do
> > anything but allows access to the currently executing command.
>
> > I suspect this will work, but is there a better way?
>
> Check, if v:cmdarg helps you.
>

Exactly what I was looking for, thanks! Somehow I didn't think to
check for a v: variable. I'll remember next time I'm looking for
information to use in an autocmd!

--
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

No comments:

Post a Comment