Post

Setting up Vim for Windows

Using Vim on Windows

I wanted to make Vim my default application for opening .txt, .c, .py, and other files, but the it took awhile to set up Vim well on Windows. Here are the steps you should follow if you want Vim to be your default text editor for files on Windows:

  1. Install it from vim.org.
  2. Make Vim the standard application for opening files with certain extensions; do this in the Default apps section within settings.
  3. Change backup settings. When you double-click an app with Vim set as the Default app to open it, a GUI version of Vim will pop open the file. But when you save an quit vim, there will be additionally files in the directory of the file you just edited. For example, after editing a file called bar, my directory looked like this:
    1
    2
    
    $ ls -a
    .  ..  .bar.un~  bar  bar~
    

    The .bar.un~ file is the vim undo file, and the bar~ is a vim backup file. It was confusing to me as to why the latter was appearing because the vim docs for backup files say that backup should be unset by default. For whatever reason, I found this to be untrue when installing vim on Windows. This was causing vim to create backups of files but then not delete them after saving/quitting the file. If you want vim to create a backup while you’re editing the file but not keep it after you save and quit the file, then you should set the writebackup option and unset the backup option. writebackup should be set by default. To unset backup permanently, add :set nobackup to the end of you vimrc file. In Windows, your vimrc file may be in a subdirectory of C:\Program Files (x86), which means to edit it you’ll have to run your text editor as an administrator. Then, open vimrc for editing with the command :edit $VIM\_vimrc. Add set nobackup to a new line at the end of the file.

At this point, the backup file has been fixed but the undo file is still cluttering our directory. We can tell vim to place the undo file elsewhere by telling vim to put undo files elsewhere. Open vim and enter :echo $HOMEPATH, which will output a directory. Inside of that directory, there should be a directory called vimfiles create a directory called .undo. Finally, add the line set undodir=$HOMEPATH\vimfiles\.undo// to the end of your vimrc file.

After all this, you should no longer see any files created in the directory of a file you’re editing with vim for Windows. If any of this doesn’t work, feel free to let me know.

Getting Help

If you want information on how to use a command in vim, enter the command :help <command>. Although help is helpful, I didn’t use it much when I was new to vim because it pops open a new help window which I didn’t know how to control; to switch from one window to the other, hit Ctrl-w then w. To exit a window, use :q. To resize the current window by n number of lines, use :re[size] [+/-]n.

This post is licensed under CC BY 4.0 by the author.