1

UPDATE:

after playing around with my vimrc file I discovered this

this won't work

cd c:\myUsualFolder
set encoding=utf-8

but this will:

set encoding=utf-8
cd c:\myUsualFolder

If I launch Vim from powershell/cmd from different folder than "myUsualFolder" with a file (e.g gvim myfile.txt) it will open a empty buffer located in "myUsualFolder" (or if the file exist ther the wrong one). I tracked it down to the first line of my .vimrc

cd c:\myUsualFolder

If this line is removed everything works fine.

Does anyone has an idea how to keep the change directory part while opening the right file as well?


About my system: windows 10; vim version 8.0.586

  • Are you providing a full path to the filename? If not, does it exist in the myUsualFolder directory? Can you expand on what you mean by "...if the file exist the wrong one...?" Are you saying you specify one name and it opens another file with a different name? If not, what exactly happens? – Dan J. May 11 '18 at 18:13
  • @DanJ. I updated my question. the solution does work for me. but I really would like to know why ... – noob May 11 '18 at 19:35
3

If you want Vim to always start in a certain directory, then you should likely do that after it has finished handling normal startup. You can do that with the VimEnter autocommand.

Replace cd C:\myUsualFolder with

augroup vimrc
    autocmd!
    autocmd VimEnter * cd C:\myUsualFolder
augroup END

The augroup and autocmd! ensure you're not creating duplicate autocmds if you re-source your vimrc while you're running Vim.

:help autocmd-define gives more details on the behavior of autocmds.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.