Skip to main content
added 171 characters in body
Source Link
user359065
user359065
[ -e $1 ] && vim $1

is the core of a simple solution. I tested it by writing this one line to a file "pv.cmd" (p as in protected...) and defining a "new command" with

alias pv='source pv.cmd'

All this I think is needed because we want it to work via the (one and only, I hope...) argument.

Now I can go

pv filename<enter>

And, if that filename does not exist ( "-e" test), you get a new prompt line in 0.000 seconds (I really did time pv jjjjjj).

Otherwise the file simply opens in vim.

And even just pv without an arg starts vim - the welcome screen.

You have so many options from here: how you name your "pv" alias? A fast but risky "v" ? Where do you define this alias best? Do you alias over vim or vi? Make that one liner a bash executable? A shell function?

You know I wondered before if it's me or vim when that happens (editing an unwanted empty file). But now I go :q instantly, and no file ever gets created.

You cannot test that line in pv.cmd directly because it needs a first argument (called "$1" in bash). I think an alias to source a oneliner that checks argument $1 is the minimum required.

...or is there an OPTION IN VIM?


Using a function amounts to quite to the same, I would say --- matter of taste and how you are organized (or the how the SYSTEM organizes YOU :-)

[ -e $1 ] && vim $1

is the core of a simple solution. I tested it by writing this one line to a file "pv.cmd" (p as in protected...) and defining a "new command" with

alias pv='source pv.cmd'

All this I think is needed because we want it to work via the (one and only, I hope...) argument.

Now I can go

pv filename<enter>

And, if that filename does not exist ( "-e" test), you get a new prompt line in 0.000 seconds (I really did time pv jjjjjj).

Otherwise the file simply opens in vim.

And even just pv without an arg starts vim - the welcome screen.

You have so many options from here: how you name your "pv" alias? A fast but risky "v" ? Where do you define this alias best? Do you alias over vim or vi? Make that one liner a bash executable?

You know I wondered before if it's me or vim when that happens (editing an unwanted empty file). But now I go :q instantly, and no file ever gets created.

You cannot test that line in pv.cmd directly because it needs a first argument (called "$1" in bash). I think an alias to source a oneliner that checks argument $1 is the minimum required.

...or is there an OPTION IN VIM?

[ -e $1 ] && vim $1

is the core of a simple solution. I tested it by writing this one line to a file "pv.cmd" (p as in protected...) and defining a "new command" with

alias pv='source pv.cmd'

All this I think is needed because we want it to work via the (one and only, I hope...) argument.

Now I can go

pv filename<enter>

And, if that filename does not exist ( "-e" test), you get a new prompt line in 0.000 seconds (I really did time pv jjjjjj).

Otherwise the file simply opens in vim.

And even just pv without an arg starts vim - the welcome screen.

You have so many options from here: how you name your "pv" alias? A fast but risky "v" ? Where do you define this alias best? Do you alias over vim or vi? Make that one liner a bash executable? A shell function?

You know I wondered before if it's me or vim when that happens (editing an unwanted empty file). But now I go :q instantly, and no file ever gets created.

You cannot test that line in pv.cmd directly because it needs a first argument (called "$1" in bash). I think an alias to source a oneliner that checks argument $1 is the minimum required.

...or is there an OPTION IN VIM?


Using a function amounts to quite to the same, I would say --- matter of taste and how you are organized (or the how the SYSTEM organizes YOU :-)

Source Link
user359065
user359065

[ -e $1 ] && vim $1

is the core of a simple solution. I tested it by writing this one line to a file "pv.cmd" (p as in protected...) and defining a "new command" with

alias pv='source pv.cmd'

All this I think is needed because we want it to work via the (one and only, I hope...) argument.

Now I can go

pv filename<enter>

And, if that filename does not exist ( "-e" test), you get a new prompt line in 0.000 seconds (I really did time pv jjjjjj).

Otherwise the file simply opens in vim.

And even just pv without an arg starts vim - the welcome screen.

You have so many options from here: how you name your "pv" alias? A fast but risky "v" ? Where do you define this alias best? Do you alias over vim or vi? Make that one liner a bash executable?

You know I wondered before if it's me or vim when that happens (editing an unwanted empty file). But now I go :q instantly, and no file ever gets created.

You cannot test that line in pv.cmd directly because it needs a first argument (called "$1" in bash). I think an alias to source a oneliner that checks argument $1 is the minimum required.

...or is there an OPTION IN VIM?