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
Related
I have a $HOME/.vimrc file which I have configured for many options like below but not limited to.
set foldmethod=indent
set foldnestmax=10
set mouse=a
set number
These all work fine if I open a file with vim however if I open with vi or view the file none of the config work, which is fine but I get errors for some.
line 104:
E538: No mouse support: mouse=a
line 205:
E518: Unknown option: foldmethod=indent
Press ENTER or type command to continue
After searching quite a while I was able to remove some of these.
if has('mouse')
set mouse=a
endif
silent! set foldmethod=indent
However this is just suppressing them. And the linenumbers are still being displayed with vi or view which look pretty bad and many people login to the box will be suddenly mystified by the yellow line numbers.
How to make vi not take up these config.
I powerbroker to the linux box. Can I make .vimrc setting just for me.
vi and vim are the same executable.
I'd suggest you change the name of your vimrc:
$ mv ~/.vimrc ~/.myvimrc
and start Vim with:
$ vim -Nu ~/.myvimrc
You could add an alias to ~/.bashrc (or whatever works in that system) to ease your workflow:
alias myvim='/usr/bin/vim -Nu ~/.myvimrc'
As vi does not support all options of vim, What I do is to set alias for vi to vim in my rc file
alias vim='vim -p'
alias vi='vim -p'
The -p is not really required. but I kinda like tabbing enabled by default on vim. So every time, if you hit vi or vim, it behaves the same.
You can make this permanent, if you like, by adding the lines to ~/.bashrc, assuming you are using bash. You need to source ~/.bashrc to take immediate effect without logging off.
I can :set number from within a file I'm editing but how can I have them always be on by default?
Add set number to your .vimrc file in your home directory.
If the .vimrc file is not in your home directory create one with
vim .vimrc and add the commands you want at open.
Here's a site that explains the vimrc and how to use it.
To change the default setting to display line numbers in vi/vim:
vi ~/.vimrc
then add the following line to the file:
set number
Either we can source ~/.vimrc or save and quit by :wq, now future vi/vim sessions will have numbering :)
set nu
set ai
set tabstop=4
set ls=2
set autoindent
Add the above code in your .vimrc file. if .vimrc file is not present please create in your home directory (/home/name of user)
set nu -> This makes Vim display line numbers
set ai -> This makes Vim enable auto-indentation
set ls=2 -> This makes Vim show a status line
set tabstop=4 -> This makes Vim set tab of length 4 spaces (it is 8 by default)
The filename will also be displayed.
Terminal > su > password > vim /etc/vimrc
Click here and edit as in line number (13):
set nu
If you don't want to add/edit .vimrc, you can start with
vi "+set number" /path/to/file
I did not have a .vimrc file in my home directory. I created one, added this line:
set number
and that solved the problem.
in home directory you will find a file called ".vimrc" in that file add this code "set nu" and save and exit and open new vi file and you will find line numbers on that.
I'm using Debian 7 64-bit.
I didn't have a .vimrc file in my home folder. I created one and was able to set user defaults for vim.
However, for Debian 7, another way is to edit /etc/vim/vimrc
Here is a comment block in that file:
" All system-wide defaults are set in $VIMRUNTIME/debian.vim (usually just
" /usr/share/vim/vimcurrent/debian.vim) and sourced by the call to :runtime
" you can find below. If you wish to change any of those settings, you should
" do it in this file (/etc/vim/vimrc), since debian.vim will be overwritten
" everytime an upgrade of the vim packages is performed. It is recommended to
" make changes after sourcing debian.vim since it alters the value of the
" 'compatible' option.
Add any command you want to have by default to your ~/.vimrc file (named _vimrc on Windows systems)
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.
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
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.