Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up gVim on windows

I am trying to get gVim working on a windows 7 machine and am having the following problems:

  • Whenever I try to change the _vimrc file, I get a message saying that I don't have permission to save in this location. This is on my home pc btw.

  • I can't seem to change the directory where the files I edit are being saved. They are all being saved to my desktop at the moment. I tried :set dir=path to where I want to save... with no success.

I wanted to run through vimtutor; however, whenever I type vimtutor into cmd, vim flashes open for a second then closes.

How do I alter the _vimrc file and how do I set the destination for edited files?

like image 872
bqui56 Avatar asked May 16 '12 05:05

bqui56


People also ask

Can we use Vim editor in Windows?

Vim is a powerful code editor. So powerful that both Linux and Mac have it installed by default. But if you are using Windows as your operating system, you will need to install Vim separately. Fortunately, Microsoft makes it very easy to install Vim and get it running on your PC.

Is Vim for Windows Good?

Vim is a flexible, efficient, and open-source terminal-based text editor. Vim stands for “Vi Improved”, which means it's a revamped version of the Vi text editor. Vim is regarded as one of the best text editors for security professionals and Linux users.

Is Gvim better than Vim?

Functionally there is no difference between VIM and GVIM. They both work the same and have same keyboard sequences. VIM does not need a Graphical User Interface (GUI) and uses terminal shell environment to provide text editing features.


2 Answers

I find many people do it differently. Here's how I organize my configurations on windows.

  • First note that I don't believe in mixing my vim configurations with the stock vim installation. So I don't write or modify files in %PROGRAMFILES% or %PROGRAMFILES(x86)%.
  • My vim configurations work on different platforms (OS X, linux, windows). And I keep them organized in a .vim folder and a .vimrc file.
  • Some of my windows machines have cygwin and others do not. On the ones without cygwin, I put my .vim folder and my _vimrc file in %USERPROFILE%. On the ones with cygwin, I put my .vim folder and my _vimrc file in my cygwin user's home directory.
  • %HOME% is not defined on windows OOTB, so I define it. I find setx.exe is easy...
    • Example: setx HOME %USERPROFILE% or setx HOME d:\cygwin\home\myname
    • Alternatively, you can add environment variables via the control panel.
  • Note, you can copy/store the .vim folder and _vimrc file in %HOME%. But I like to keep them in a git repo elsewhere on my machine and link to them. On windows, I use mlink /d %HOME%\.vim location_of_vim_folder to link the .vim folder. And mlink /h %HOME%\_vimrc location_of_dot_vimrc_file to link the .vimrc to _vimrc file.
  • Note, you should have write permissions to your %HOME% folder defined above... so this should solve your problem with permissions. (You need to be an administrator to write to %PROGRAMFILES% or %PROGRAMFILES(x86)%
  • In my vimrc, I have a bit of boiler plate stuff for windows:

    "g:my_vim_dir is used elsewhere in my vim configurations
    let g:my_vim_dir=expand("$HOME/.vim")
    
    "$HOME/.vim and $HOME/.vim/after are in the &rtp on unix
    "But on windows, they need to be added.
    if has("win16") || has("win32") || has("win64")
      "add g:my_vim_dir to the front of the runtimepath
       execute "set rtp^=".g:my_vim_dir
      "add g:my_vim_dir\after to the end of the runtimepath
      execute "set rtp+=".g:my_vim_dir."\\after"
      "Note, pathogen#infect() looks for the 'bundle' folder in each path
      "of the &rtp, where the last dir in the '&rtp path' is not 'after'. The
      "<path>\bundle\*\after folders will be added if and only if
      "the corresponding <path>\after folder is in the &rtp before
      "pathogen#infect() is called.  So it is very important to add the above
      "'after' folder.
      "(This applies to vim plugins such as snipmate, tabularize, etc.. that
      " are loaded by pathogen (and perhaps vundle too.))
    
      " Not necessary, but I like to cleanup &rtp to use \ instead of /
      " when on windows machines
      let &rtp=substitute(&rtp,"[/]","\\","g")
    
      "On windows, if called from cygwin or msys, the shell needs to be changed 
      "to cmd.exe to work with certain plugins that expect cmd.exe on windows versions   
      "of vim.
      if &shell=~#'bash$'
        set shell=$COMSPEC " sets shell to correct path for cmd.exe
      endif
    endif
    
    "Then I load pathogen... (Or if you prefer, you could load vundle bundles here if you wish )
    
like image 88
darcyparker Avatar answered Nov 13 '22 07:11

darcyparker


I can't seem to change the directory where the files I edit are being saved. They are all being saved to my desktop at the moment. I tried :set dir=path to where I want to save... with no success.

dir is the location for swap files, which are special backing files used by Vim at runtime.

What you want is cd or lcd which changes the current directory. Type :help cd inside of Vim for more info.

How do I alter the _vimrc file and how do I set the destination for edited files?

I have _vimrc in my Vim folder ($VIM), so when I want to put Vim on a new Windows machine I just copy my entire folder.

like image 43
Mud Avatar answered Nov 13 '22 06:11

Mud