Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open file at Vim startup

Tags:

vim

I like to have Vim open a cheatsheet at startup. Adding this to _vimrc works nicely with MacVim:

:e *path-to-cheatsheet*

but on Windows, vim displays a message box at startup:

"~\Dropbox\vimfiles\myvim\vimcheat.txt"
"~\Dropbox\vimfiles\myvim\vimcheat.txt" [unix] 52L, 1735C

When the message box is dismissed, Vim completes startup and opens the cheatsheet. How do I get this to work cleanly with Windows Vim?

like image 739
Brad Dow Avatar asked Aug 01 '17 08:08

Brad Dow


People also ask

How do I open a new file in Vim editor without exit from that?

Opening a new file for editing If you're already in vim, then there's no need to exit it just to open a new file. That will open the file for editing. You can also use the tab-key for autocompletion of the path. Please note that the current file must be saved, or you've to use :e! to discard the unsaved changes.

How do I open a file in Vim editor?

Open a new or existing file with vim filename . Type i to switch into insert mode so that you can start editing the file. Enter or modify the text with your file. Once you're done, press the escape key Esc to get out of insert mode and back to command mode.

How do I open a .txt file in Vim?

Launching Vim In order to launch Vim, open a terminal, and type the command vim . You can also open a file by specifying a name: vim foo. txt .

How do I create a .vimrc file in Windows?

The system vimrc file can be created by an administrator to customize Vim for all users. In addition, each user can have his or her own user vimrc . Show activity on this post. It may be under [Your Installation Directory]/Vim/ .


1 Answers

The ~/.vimrc is processed at the very beginning of :help initialization. You can use the VimEnter event to open the file after all the startup stuff is done:

autocmd VimEnter * edit path/to/cheatsheet

If you don't want to see the messages, use silent edit. If you don't care about errors (if the cheatsheet isn't there), use silent!.

like image 66
Ingo Karkat Avatar answered Sep 20 '22 15:09

Ingo Karkat