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?
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 )
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.
Related
I have been developing a perl application under Windows 7 that has a subroutine which lists all source files in a given directory. To spare time in the next run source files that had been found are written to a cache (plain txt file). Then this cache is intended to be updated only if there were changes under the source folders. I assumed that I can check modification time of folders to check if files were removed or added and update cache file only if needed.
It seemed to work well until I edited some of the source files with vim which updated the modification date of the containing folder as well. First I thought it is because vim adds a swap file to the directory where the edited source resides. So I set directory in _vimrc file to point to an other location.
set directory=~/.vim/swap " directory to place swap files in
After setting it there were no added swap file in the source folder but the modification time of directory changed after saving the file.
I'm using gVim 8.0.586 for Windows but gVim nightly (8.0.1605), neovim (v0.2.2-1173-gc46d6f8da), cygwin vim (8.0 1-1376) gave me the same result even with a "clean" _vimrc that only sets directory.
Editing the same source file with Notepad++ or Atom changes only the modification time of the file and not the modification time of the directory containing it.
Does anybody have any clue what can cause this behavior of vim?
EDIT
I have also these two lines in may _vimrc:
set backup " make backup files
set backupdir=~/.vim/backup " where to put backup files
As Wumpus suggested i tried to switch off both backup and writebackup and it did work but i did not have any backupfile. :(
:set nobackup nowritebackup
writebackup is not set in _vimrc, so it is on by default.
It's probably the creation and deletion of the backup file.
vim creates a backup before writing the new version of the file, so you can get the old version back in case of a crash.
You can turn off backups with :set nobackup nowritebackup or change the location with :set backupdir=someplaceelse
The backupcopy option may also have some effect. It can try to rename the new file into place. Try yes and no for backupcopy and see if there is a difference. But note there are other side effects... see :help backupcopy. And the behavior may depend on whether your backupdir is on the same filesystem.
When using vi I almost always need to do
:set hlsearch
:set number
How can I make my system always load these as presets or something when I use vi.
In one machine I am root, in another not. So please include an answer for both. Thank you!
just create a .vimrc file with the following entries:
set hlsearch
set number
Put this file in the $HOME directory of the user you are using on the particular machine:
/root/on the machine where you are root.
/home/USERNAMEon the machine where your user is USERNAME
if .vimrc does not exist, create it.
You can create a file named .exrc in your home directory and write all the commands (without the preceding : ) there.
When you start the vi editor, the editor searches for the environment variable $EXINIT and uses the contents of the file it points to as configuration commands, if it exists. If EXINIT is not defined, vi looks for the .exrc file in your HOME directory, and uses its configuration commands. Finally, vi looks in your current directory for a file named .exrc and executes the commands in that file, if it exists. In this manner, you can have a different vi configuration for each directory or project that you're working on.
(http://alvinalexander.com/unix/edu/un010003/)
The corresponding file for vim is called .vimrc.
when I open gvim using Alt+F2 it takes as its default working directory my home folder.
How can I change the working folder after or while running gvim? can i pass that folder as a parameter when open gvim?
You could use a shortcut.
The simplest way, though, would be to
:edit $MYVIMRC
append a line
cd /home/user/my/work/dir
save (optionally execute :w|source % to immediately reload)
Inside vim
use
:pwd
:cd some/other/dir
To view/change current working directory.
Use e.g.
:cd %:h
to change to the directory containing the file loaded in the active window.
If you need/want to do this often, consider just setting 'autochdir'
:se autochdir
From the docs:
When on, Vim will change the current working directory
whenever you open a file, switch buffers, delete a
buffer or open/close a window. It will change to the
directory containing the file which was opened or
selected. This option is provided for backward
compatibility with the Vim released with Sun ONE
Studio 4 Enterprise Edition.
Note: When this option is on some plugins may not work.
You can pass an a folder to gvim (when you have NERDTree then it will be a file tree) You can cd before start to begin in directory you want or use :cd <path> command to change current working directory, which can be passed to -c flag when running Vim:
$ [g]vim -c 'cd <path>'
You can also check current dir using :pwd command.
You can change the working directory with the :cd command. You can also pass this in a command-line option like this:
vim -c "cd wherever"
If you like the working directory to always be the file you're currently editing you can use the set autochdir option. Put that in your ~/.vimrc or see :help autochdir.
I know I'm late, but I started using CDargs which is a bash tool to mark certain directories as bookmarks, then use cdb and press tab to list all the bookmarked directories.
There is a vim plugin that interacts with the settingsfile of this tool: vim-cdargs.
This combo works really nice for me to switch between projects.
Or after opening gvim to go quickly to some bookmarked folder, then use Ctrl-p plugin to quickly find the file I want to edit.
extra hint: I don't even want to type :Cdb so I abbreviated c to expand to :Cdb by adding this to my vimrc:
cnoreabbrev c Cdb
after which typing :c followed by a space, will expand into :Cdb.
EDIT: I now use vim-startify which provides a start page for vim that shows the most recent used files. And with the option let g:startify_change_to_vcs_root = 1 it will change the working directory to the outermost vcs root folder of the file you opened. Which is almost always what I want.
Furthemore, I created my own 'plugin' with some key mappings that will switch to the closest or furthest directory, in the path of the current buffer, containing a .git directory or file. In order to easily switch between searching for files in the current git submodule or in the overal supermodule.
Also I switched to fzf with fzf-vim instead of Ctrl-p, which works significantly faster and is more highly configurable.
I installed rvm and a couple of rubies since i'm working with projects based on different ones. Then created .rvmrc files in project directories and they work perfectly when i 'cd' to projects' folders in my terminal:
~$ cd workspace/prox/
~/workspace/prox$ rvm current
ruby-1.9.3-p194#prox
~/workspace/prox$ cd ../cto/
~/workspace/cto$ rvm current
ruby-1.8.7-p358#openservice
~/workspace/cto$
And now i'm trying to use vim + NERDTree as my new ide to improve performance but i encountered a problem with .rvmrc:
When i cd in NERDTree to a project's folder and get confirmation that CWD has changed i end up with default ruby#gemset. Hance .rvmrc hasn't got processed.
Does anyone know if it is possible to make .rvmrc files work with vim NERDTree?
I'm not a rubyist and, therefore have no practical experience with RVM.
But I seem to remember that it works by setting a bunch of environment variables which are supposed to be picked up by Vim at startup. Am I right?
IMO the problem, here, is that changing a directory in Vim and changing a directory in your shell is not related at all. AFAIK, Vim doesn't care about your .rvmrc and won't notify your shell of any :cd.
See this sequence of commands:
$ cd
$ pwd
/home/username
$ vim
:pwd
/home/username
:cd Dropbox
:pwd
/home/username/Dropox
:q
$ pwd
/home/username
While you have changed to another directory while working in Vim you are back to square one when you quit. Because your shell didn't notice all your travels and Vim didn't pickup any new environment variables you are somehow at the same place with the same environment.
But I might be completely off.
This plugin by Tim Pope should help.
I just installed Cygwin on my work machine and would like to use the .vimrc file I use on my Linux box at home.
Is that possible, or does it need to have Cygwin-specific settings?
Where would I put the .vimrc file?
I'm a little unsure of what directory I'm being dropped into at the bash prompt under Cygwin, but I think I'd create a subdirectory called .vim there, right?
I launched vi as vi -V and got this:
chdir(/cygdrive/c/Users/johntron)
chdir(/etc)
chdir(/cygdrive/c/Users/johntron)
could not source "/etc/virc"
chdir(/cygdrive/c/Users/johntron)
chdir(/cygdrive/c/Users/johntron)
chdir(/cygdrive/c/Users/johntron)
could not source "$HOME/.virc"
chdir(/cygdrive/c/Users/johntron)
chdir(/cygdrive/c/Users/johntron)
chdir(/cygdrive/c/Users/johntron)
could not source "$HOME/.exrc"
Realizing vi was looking for .virc and not .vimrc like all the other *nix systems I've ever used, I just ran this to fix the problem:
cp ~/.vimrc ~/.virc
... or if if you've configured symlinks:
ln -s ~/.vimrc ~/.virc
I'm pretty sure this was a problem, because Cygwin installs vi, and not vi improved; however, the loading screen if you launch vi with no parameters still says vi improved. Regardless, I installed vim via setup.exe and running vim (not vi) does indeed try to load ~/.vimrc as expected. You can simply add an alias vi=vim to your ~/.profile to use the improved version by default.
Cygwin (as of version 1.7.25) installs vi (not vim!) by default. If you also install vim you will have two commands: /usr/bin/vi and /usr/bin/vim.
Unlike in other *nix (e.g. debian) both commands slightly differ in their behaviour on starting vi/vim.
Both commands will load Vi Enhanced but they differ in the files they look for to initialize the editor:
/usr/bin/vi looks first for /etc/virc and then for $HOME/.virc
/usr/bin/vim looks first for /etc/vimrc and then for $HOME/.vimrc.
Both files (in /etc and in $HOME) will be sourced if found!
You can check it yourself entering vi -V and vim -V.
Use .vimrc if you call vim and .virc if you call vi. Or simply alias vi=vim for using .vimrc
1) Yes it is possible. It doesnt need any cygwin specific settings, though you can add some windows specific ones. Just make sure to install vi (vim gvim equivalent) properly.
2) the same place as on *nix -- user home directory
Beware one thing: there is a Cygwin port of vim, and a native win32 port of vim. Both have their advantages and their flaws when dialogue with cygwin or native-win32 applications is concerned.
A category on vim.wikia is dedicated to cygwin related tips.
Some parts of file system of Cygwin use your "host" file system as its own. Within cygwin, there is a user home directory (which actually resides under your "Documents and Settings/Username" folder), so you should place it there.
Just place your .vimrc somewhere you know how to access via cygwin and do a
directory/you/know$ cp .vimrc ~/
It will work--at least worked with default vim on my Cygwin installation several months ago.
I don't see any reason why your Linux ~/.vimrc
should not work in your cygwin install.
To go to your home directory in cygwin,
cd ~
or
cd $HOME
In Windows, you can use WinSCP to connect to your Linux box, open your Linux .vimrc in the WinSCP default editor, copy the contents. Then switch to the Cgywin terminal and type
getclip > ~/.vimrc
Start vi/vim to see if your new settings have taken effect:
vi
I had to rename / symlink my .vimrc file to .virc in a directory like /home/Leo/.virc or more generally $HOME/.virc.
I just created my own and worked out of box:
1) vim ~/.vimrc
Once inside the .vimrc (blank file) I like to copy the example from:
2) :r $VIMRUNTIME/vimrc_example.vim
3) :wq
Then check any file should have lots of color and stuff
4) vim .vimrc (or whatever file, e.g. ~/.bashrc)
simply navigate to your home directory which is
c:/Users/user_name/
create the file using
vi .vimrc
set your preferences here, and they would surely reflect
like
set nu "show line numbers
set ai "auto indentations
colors blue " or elflord or whatever you like.
save and try.
I had issue with Cygwin vi tabstop. It was always defaulting to 8. While launching it was giving error "Failed to source defaults.vim" Tried to follow various solutions but below worked for me.
Create .vim directory under current user home ($HOME) directory.
Create .virc file under .vim directory.
Add below line to .virc
set tabstop=4
Cygwin version details
CYGWIN_NT-10.0-22000 3.3.5-341.x86_64 x86_64 Cygwin