I have a ~/.vimrc file that vim doesn't seem to be reading.
There is a file at /etc/vimrc, and it looks like it is using that one.
My understanding is that the one in the home directory should override this one, shouldn't it?
Update
cat vim_strace | grep .vimrc
stat64("/etc/vimrc", {st_mode=S_IFREG|0644, st_size=1438, ...}) = 0
open("/etc/vimrc", O_RDONLY|O_LARGEFILE) = 3
stat64("/etc/vimrc", {st_mode=S_IFREG|0644, st_size=1438, ...}) = 0
stat64("/root/.vimrc", {st_mode=S_IFREG|0644, st_size=35, ...}) = 0
open("/root/.vimrc", O_RDONLY|O_LARGEFILE) = 3
stat64("/root/.vimrc", {st_mode=S_IFREG|0644, st_size=35, ...}) = 0
Once you've loaded vim, :scriptnames will tell you exactly what Vim read.
For me, it starts like this:
1: /Applications/MacVim.app/Contents/Resources/vim/vimrc
2: ~/.vimrc
3: /Applications/MacVim.app/Contents/Resources/vim/runtime/syntax/syntax.vim
4: /Applications/MacVim.app/Contents/Resources/vim/runtime/syntax/synload.vim
5: /Applications/MacVim.app/Contents/Resources/vim/runtime/syntax/syncolor.vim
IF you want to check where a particular setting is being set, use "verbose set". For example, :verbose set background tells me:
background=light
Last set from ~/.vimrc
so I know that my setting in ~/.vimrc is being read, and that none of the later files is clobbering it.
if you're on linux and want to know if vim is accessing your ~/.vimrc on startup you can launch it with strace:
strace -o vim_strace vim
then quit vim.
Open the vim_strace file and search for "vimrc" in the file. you should find a line like that
stat64("/home/youruser/.vimrc", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
which mean that at least vim sees the file.
If anyone happen upon this issue while using neovim you should know (before you start pulling off your hair) that the .vimrc file is loaded from ~/.config/nvim/init.vim.
mkdir -p ~/.config/nvim; ln -s ~/.vimrc ~/.config/nvim/init.vim
I had this problem and just added the following to the file ~/.bash_profile:
alias vim="vim -S ~/.vimrc"
In case anyone else runs across this issue, and like me realizes .vimrc wasn't read because of sudo, try using sudo -E. It retains your environment for the command, and $HOME will point to your own home dir. Note this may not work in environments where /home is mounted with rootsquash.
Just to add on hellvinz's instruction.
After you have made vim_strace file.
cat vim_strace | grep .vimrc
makes life bit easy :)
Stumbled on this post and non of the suggestions worked for me. Some useful things not mentioned here:
vim --version should give you some useful info including the startup files. (Mine listed "virc" in several places (not vimrc)
If your vim isn't really vim then perhaps it is looking for ~/.exrc instead of .vimrc (Mine looks for some system vircs, then some users vircs and then $HOME/.exrc)
If your file (whichever one it is) has DOS line endings it may cause errors
... so even though I've got a real vim, it's looking for "virc"
On OSX 10.8.0 the location of the vimrc file is: /usr/share/vim/vimrc
I just add my changes to the bottom of the file.
Of course this has the effect of making the changes for all users. For the life of me I can't seem to figure out how to get it to read ~/.vimrc. This was never an issue for me on 10.6.x
Anyway this is a quick fix even it is a bit dirty.
Cheers
use file /etc/vim/vimrc.local in Ubuntu
Check if $VIMINIT has been set. It may prevent reading your ~/.vimrc. See :help VIMINIT:
c. Four places are searched for initializations. The first that exists
is used, the others are ignored. [...]
- The environment variable VIMINIT [...]
For me unsetting VIMINIT did the trick, my ~/.vimrc is now read.
After checking scriptnames and verbose as suggested above, I noticed that my setting was indeed being loaded, but being overridden by another plugin, thus giving the impression that it was not reading/loading the .vimrc.
If this happens to you and you want to override a specific setting from a plugin, without completely eliminating all the other good things that come from that plugin, you can create a config file to load after the plugin is loaded, by creating a file in ~/.vim/after/<path>/<plugin_name>. For reference, see this other question.
/etc/vim/vimrc is now overwritten by defaults.vim unless there is a ~/.vimrc, apparently.
https://github.com/vim/vim/issues/2042
I had the same problem with vim 8.1.3741 on Kubuntu 20.04
It seems the problem was that the ~$/.vimrc file was starting with a long comment starting with " and went over 2 lines (autobreak) The vim_strace showed input 133 and wrote the comment out but not the command under it. Removing the comment worked. Thanks for info.
For me, the mistake was I had the configuration set at ~/.vim/.vimrc.
After reading some documentation, I found that right path is ~/.vim/vimrc.
Changing the file did the trick.
TL;DR check that you don't have any inline comments in your .vimrc
After all of the helpful answers under this question I was still stuck. My ~/vimrc
set mouse-=a
set tabstop=4 " Indents will have a width of 4
set shiftwidth=4
set softtabstop=4 " Sets the number of columns for a TAB
set expandtab " Expand TABs to spaces
syntax on
set paste
" set compatible
set t_ti= t_te= "stop ^z clearing the screen
" remember line
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
" unless gitcommit
autocmd FileType gitcommit call setpos('.', [0, 1, 1, 0])
was located by vim and strace showed that it was read. Turns out that vim.basic on my system seems to ignore the entire line if it contains a comment. (So inline comments disable settings on the same line.)
I moved the "Expand TABs to spaces" comment to the previous line and instantly expandtab showed up the next time I ran vim -c :set
Related
I am using Vim 8.1 on a Ubuntu system. Here are the three cases I have found.
Case 1
$ ls -l ~/.vimrc
ls: cannot access '/home/lone/.vimrc': No such file or directory
$ vim -u NONE +':filetype'
filetype detection:OFF plugin:OFF indent:OFF
Case 2
$ ls -l ~/.vimrc
ls: cannot access '/home/lone/.vimrc': No such file or directory
$ vim +':filetype'
filetype detection:ON plugin:ON indent:ON
Case 3
$ touch ~/.vimrc
$ ls -l ~/.vimrc
-rw-r--r-- 1 lone lone 0 Nov 2 18:41 /home/lone/.vimrc
$ vim +':filetype'
filetype detection:OFF plugin:OFF indent:OFF
Question
Why is it that the filetype options are ON when ~/.vimrc is present but OFF when ~/.vimrc is present?
Where in the Vim :help documentation can I find more about this behavior?
-u NONE disables all vimrc's (including the defaults, more on that below)
With no vimrc, the defaults come in to play (assuming you have vim >7.4.2111 or >8)
With a vimrc, the defaults are not sourced.
From :help defaults.vim:
Defaults without a .vimrc file ~
*defaults.vim*
If Vim is started normally and no user vimrc file is found, the
$VIMRUNTIME/defaults.vim script is loaded. This will set 'compatible' off,
switch on syntax highlighting and a few more things. See the script for
details. NOTE: this is done since Vim 8.0, not in Vim 7.4. (it was added in
patch 7.4.2111 to be exact).
This should work well for new Vim users. If you create your own .vimrc, it is
recommended to add these lines somewhere near the top: >
unlet! skip_defaults_vim
source $VIMRUNTIME/defaults.vim
Then Vim works like before you had a .vimrc. Copying $VIMRUNTIME/vimrc_example
is way to do this. Alternatively, you can copy defaults.vim to your .vimrc
and modify it (but then you won't get updates when it changes).
If you don't like some of the defaults, you can still source defaults.vim and
revert individual settings. See the defaults.vim file for hints on how to
revert each item.
*skip_defaults_vim*
If you use a system-wide vimrc and don't want defaults.vim to change settings,
set the "skip_defaults_vim" variable. If this was set and you want to load
defaults.vim from your .vimrc, first unlet skip_defaults_vim, as in the
example above.
vim -u NONE starts vim without any config file and sets all options to default values.
vim without ~/.vimrc reads configuration values from a system config file. Try /etc/vim/vimrc or /usr/share/vim/vimrc.
See http://vimdoc.sourceforge.net/htmldoc/starting.html#initialization
I have strange problem with my /etc/vim/vimrc file.
I was trying to get rid of VISUAL mode in VIM, so I have tried to add the set mouse-=a command in my vimrc file.
However my vim does not take those changes into account.
When I do :set mouse-=a in openend vim, it does what I want (selecting text with mouse without entering VISUAL mode), but the command does not work in the vimrc file.
I have also enabled the "jump to the last position when reopening a file" in vimrc and it is working, that makes me even more confused.
I have been trying every possible command:
set mouse=a
set mouse=r
set mouse-=a
:set mouse-=a
None of them is working when added to /etc/vim/vimrc.
My system is:
rRr-kali:~# uname -a
Linux rRr-kali 4.8.0-kali2-amd64 #1 SMP Debian 4.8.15-1kali1 (2016-12-23) x86_64 GNU/Linux
rRr-kali:~#
If you are using Debian 9 (Strecth), edit the file /usr/share/vim/vim80/defaults.vim and change the line 70 to put
set mouse-=a
Best Regards
Thibault
I know, that this question is a bit old, but I just want to clarify, why both answers above are correct and why it's working that way.
On Debian systems the way the config files for vim are loaded is like this:
Load settings in /etc/vim/vimrc
If exists, load settings from /etc/vim/vimrc.local
If ~/.vimrc does not exist and there is no "let g:skip_defaults_vim = 1" in /etc/vim/vimrc or /etc/vim/vimrc.local, load settings from /usr/share/vim/vim80/defaults.vim otherwise load settings from ~/.vimrc (if it exists).
Details for that can be found in the config files itself, as well as in a discussion on bugs.debian.org
So to solve your issue you have two ways to go:
Insert "let g:skip_defaults_vim = 1" at the beginning of /etc/vim/vimrc.local.
Create an empty ~/.vimrc by issuing touch ~/.vimrc.
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=864074
Moving mouse-=a to the end of ~/.vimrc resolved the issue for me.
At least at RaspberryOS (Debian) the "problem" is that /usr/share/vim/vim80/defaults.vim will be executed after /etc/vim/vimrc (including vimrc.local) or ~/.vimrc
Thus I changed line defaults.vim alike this:
69 if has('mouse')
70 if empty("+mouse")
71 set mouse=a
72 endif
73 endif
now I'm able to set mouse-=a in system wide or personal vimrc
Is it possible to tell vim to save its viminfo file somewhere else?
Such as in the .vim folder
Try adding set viminfo+=n~/.vim/viminfo to your ~/.vimrc file. From :help 'viminfo':
n Name of the viminfo file. The name must immediately follow
the 'n'. Must be the last one! If the "-i" argument was
given when starting Vim, that file name overrides the one
given here with 'viminfo'. Environment variables are expanded
when opening the file, not when setting the option.
set viminfo='1000,nc:\\users\\abcdef\\_viminfo
This works for me in Windows 7.
I had a similar problem but had no write permission to my home folder (thus could not create the ~/.vimrc).
I solved it by modifying (through the Administrator) the _vimrc in C:\Program Files\VIM to include the line:
let $HOME = $USERPROFILE
I placed it at the beginning of the file and it worked well. Just in case someone comes across this question and this answer didn't work.
I know its quite a while now, but I am just mentioning this for future readers.
I was facing the same issue while trying to change the location for viminfo file in vimrc. At last setting the value of viminfofile option worked for me.
Added the following to my vimrc:
set viminfofile=D:\vim\viminfo
It works for me on windows with vim 8.2
TL;DR
This seems to be a bug in vim where set nocompatible is not idempotent and doesn't follow the principle of least astonishment.
As a workaround, either:
Ensure that you set nocompatible (or the equivalent set nocp) only once, and at the top of your vimrc.
Don't set it again if it's already set:
if &compatible | set nocompatible | endif " Avoid side effects if `nocp` already set
Explanation and bug illustration
From :help compatible (empahsis mine):
This is a special kind of option, because when it's set or reset,
other options are also changed as a side effect. CAREFUL: Setting or
resetting this option can have a lot of unexpected effects: Mappings
are interpreted in another way, undo behaves differently, etc. If you
set this option in your vimrc file, you should probably put it at the
very start.
Note that &viminfo is not listed in the side-effects, however the following lines clearly show the side effect upon &viminfo:
set nocompatible
set viminfo+=nWatch-my-viminfo-file-location-be-ignored
echom &viminfo
set nocompatible " do side effects even though nocomptible is already set
echom 'After 2nd "set nocompatible":'
echom &viminfo
Output:
'100,<50,s10,h,nWatch-my-viminfo-file-location-be-ignored
After 2nd "set nocompatible":
'100,<50,s10,h
vim --version | head -1
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Aug 05 2016 16:48:20)
Resolution
I have raised two GitHub issues regarding this:
Undocumented "set nocompatible" side effect upon &viminfo
set nocompatible not idempotent - setting produces side effects when already set
See also Vi StackExchange's question: Can't move viminfo file - &viminfo reverts upon loading vim which I raised before seeing this one.
The ordering of settings in the .vimrc affects the use of :set viminfo. The setting of viminfo should be after the setting of nocompatible. After reordering my .vimrc, the above solution to have the viminfo file be located in the .vim directory worked for me.
In gvim8.2 on Windows10, following option works to change path of viminfo :
set viminfofile=$VIM/.viminfo
Write this in .vimrc .
It could to change viminfo file path to under the $VIM.
The latest upgrade of Ubuntu made my vim colorscheme unusable. I know how to set it manually (:colo evening, for example), but I want to set the default for all vim sessions. I see reference in other places to .vimrc, but the right location and syntax have eluded me thus far.
Put a colorscheme directive in your .vimrc file, for example:
colorscheme morning
See here: http://vim.wikia.com/wiki/Change_the_color_scheme
Your .vimrc file goes in your $HOME directory. In *nix, cd ~; vim .vimrc. The commands in the .vimrc are the same as you type in ex-mode in vim, only without the leading colon, so colo evening would suffice. Comments in the .vimrc are indicated with a leading double-quote.
To see an example vimrc, open $VIMRUNTIME/vimrc_example.vim from within vim
:e $VIMRUNTIME/vimrc_example.vim
It's as simple as adding a line to your ~/.vimrc:
colorscheme color_scheme_name
You can try too to put this into your ~/.vimrc file:
colorscheme Solarized
What was asked for was to set:
the 'default', not some other color profile, and
'for all vim sessions', not simply for the current user.
The default colorscheme, "for all vim sessions", is not set simply by adding a line to your ~/.vimrc, as all of the other answers here say, nor is the default set without the word 'default' being there.
So all of the other answers here, so far, get both of these wrong. (lol, how did that happen?)
The correct answer is:
Add a line to your system vim setup file in /etc/vim/ that says
colorscheme default
or using the abbreviation
colo default
but not capitalized as
colo Default
(I suggest using the full, un-abbreviated term 'colorscheme', so that when you look at this years later you'll be able to more easily figure out what that darn thing does. I would also put a comment above it like "Use default colors for vim".)
To append that correctly, first look at your /etc/vim/vimrc file.
At the bottom of mine, I see these lines which include /etc/vim/vimrc.local:
" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
source /etc/vim/vimrc.local
endif
So you can append this line to either of these two files.
I think the best solution is to append your line to /etc/vim/vimrc.local like this:
colorscheme default
You can easily do that in bash with this line:
$ echo -e "\"Use default colors for vim:\ncolorscheme default" \
| sudo tee -a /etc/vim/vimrc.local
#
# NOTE: This doesn't work:
#
# $ sudo echo 'colorscheme default' >> /etc/vim/vimrc.local
#
# It's the same general idea, and simpler, but because sudo doesn't
# know how to handle pipes, it fails with a `Permission denied` error.
Also check that you have permission to globally read this file:
sudo chmod 644 /etc/vim/vimrc.local
With $ tail /etc/vim/vimrc.local you should now see these lines:
"Use default colors for vim:
colorscheme default
You can just use the one-liner
echo colorscheme koehler >> ~/.vimrc
and replace koehler with any other available colorscheme. Imho, all of them are better than default.
Once you’ve decided to change vim color scheme that you like, you’ll need to configure vim configuration file ~/.vimrc.
For e.g. to use the elflord color scheme just add these lines to your ~/.vimrc file:
colo elflord
For other names of color schemes you can look in /usr/share/vim/vimNN/colors
where NN - version of VIM.
Ubuntu 17.10 default doesn't have the ~/.vimrc file, we need create it and put the setting colorscheme color_scheme_name in it.
By the way, colorscheme desert is good scheme to choose.
Copy downloaded color schemes to ~/.vim/colors/Your_Color_Scheme.
Then write
colo Your_Color_Scheme
or
colorscheme Your_Color_Scheme
into your ~/.vimrc.
See this link for holokai
OS: Redhat enterprise edition
colo schema_name works fine if you are facing problems with colorscheme.
I code in Vim, not an IDE.
My source code is often nested 2-3 directories deep.
~/foo$ find
xyz
bar/abc
bar/def
~/foo$ vim
// inside of vim
:e bar/abc
... some work ...
:e <-- is there a way I can have this :e start in ~/foo/bar instead of ~/foo ?
Basically, I want :e to start the directory in "pathname of last edited file"
Thanks!
There's a lot of reasons not to like autochdir as it messes up some plugins and if you end up doing :e ../../../foo.txt you are not gaining anything. Just as an idea try this cmap I knocked up
:cnoremap red edit <c-r>=expand("%:h")<cr>/
then you can type :red and get
:e /the/path/to/your/current/files/dir/
(edit: perhaps use z instead of red as there are commands that start with red)
To expand the topic, also check out the FuzzyFinder plugin and some custom mappings to rapidly jump to common files you are always editing. Eg
10 or so of your regular files should be no more than 2 keystrokes away. It helps if they are systematically named
Here's an idea I use for django.
http://code.djangoproject.com/wiki/UsingVimWithDjango#Mappings
Try the autochdir option. It will automatically change the current working directory to whatever file was most recently opened or selected. In .vimrc:
set autochdir
For more info, :help autochdir
To always change the working directory to the current file's directory I have this in my .vimrc:
if has("autocmd")
autocmd BufEnter * :lcd %:p:h
endif " has("autocmd")
Sorry, but vim's :edit command takes a path which is interpreted relative to the present working directory of the vim instance.
You do have a :cd command which you could use to :cd bar then work for a while, then :cd ...
Hope that help some.
Some time ago I asked questions related to this on the vim mailing list: http://www.mail-archive.com/vim_use#googlegroups.com/msg03266.html Maybe you will find useful tips in that thread.
I tested a lot of plugins, but since CLI based GUIs are not my taste, I simply ended up using standard vim with a few configuration settings.
As honk pointed out, this line sets the working directory to the same as the file your working on:
autocmd BufEnter * lcd %:p:h
My other tip is to use the wildmenu. It makes it easier to get an overview of the files in your current directory when you go :e and then TAB. I'm a python programmer so the last line shows how to hide auto generated files that the python interpreter spits out, but you could use it to hide java .class files or c .obj files or whatever.
set wildmode=list:longest
set wildignore=*.pyc,*pyo
:cd changes directory
:pwd prints the current one.
why not just :E? Explore directory of current file.
:help :E
This isn't exactly what you wanted, but check out NERDTree.
On vim/gVim I just have cd C:/blah/blah at the top of my vimrc. I imagine it works on all platforms.
I personally use vagrant for each project so one CD is enough, but I think you can get vim to use different config files too, -u flag I think.
Or map a key to each project you have so pressing Ctrl+F1 does cd path/to/project/1 and Ctrl+F2 does cd path/to/project/2 perhaps?
Note: I don't use any plugins