Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect vim command-line arguments in vimscript?

Tags:

vim

I want to know when I should call RestoreSession() function and when not. Because when I open single file, I don't want to see my project's files, which i save to vim session before.

For example if I call vim like this: vim -n test.rb. How me to detect n key in vimrc? (I want use n key as something like custom indicator for my purpose)

It's all, small question :-)

like image 634
milushov Avatar asked Nov 06 '12 23:11

milushov


2 Answers

In private conversation, @Nicklasos suggest me another way how to do what I need - using argv() function. It is just:

if argc() == 0
  autocmd VimEnter * call RestoreSess()
end
like image 117
milushov Avatar answered Oct 09 '22 00:10

milushov


You can run vim with -c key (Execute command upon startup)

vim -c RestoreSession foo.txt

Also, you can write bash alias.

like image 37
Nicklasos Avatar answered Oct 09 '22 01:10

Nicklasos