Under what circumstances is $MYVIMRC not set? - windows

I am working with a gvim installation on windows (version 7.3). After starting up, I expected the variable $MYVIMRC to be set, yet it is not. Is there a reaseon why it is not set.
There is a vimrc file since many setting are different from the default settings.
I checked the for the value of MYVIMRC with
:echo ">" . $MYVIMRC . "<"
The gvim executable is located in c:\workarea\Vim\vim73, the *_vimrc* (that is being read on gvim's start) in c:\workare\Vim. After I have started gvim, I can edit the _vimrc file with a
:e $VIM/_vimrc
With :version I found that the system vimrc file is under $VIM/vimrc. This file doesn't exist.

If you are running :echo $MYVIMRC and $MYVIMRC is not defined I bet it is because there is not a ~/.vimrc file (or $HOME/_vimrc on windows).
From :help $MYVIMRC
Four places are searched for initializations. The first that exists is
used, the others are ignored. The $MYVIMRC environment variable is
set to the file that was first found
(Second place of that four places is the users vimrc.)
((Just check :help $MYVIMRC for more info))
If there are settings different from the default ones you can check other variables to find where that settings are changed:
:echo $MYVIMRC
:echo $MYGVIMRC
:echo $VIM
:echo $VIMRUNTIME
You can check:
:help startup
:help gui-fork
to see how this works.
You can use as well the verbose command to see where some settings are defined. For example if you know is mapped:
:verbose map <F5>
Will return something like:
* :python debugger.run()
Last set from ~/.vim/bundle/vdebug/plugin/vdebug.vim
(That is from my particular vim configuration)

You wrote,
There is a vimrc file since many setting are different from the default settings.
That could be because there is a system vimrc file. Look about half-way down the output of :version to see where vim looks for the system vimrc file. There are also some less common ways of changing settings. See :help startup.

Related

vim log4j syntax highlighter not working

I have this vim plugin
http://www.vim.org/scripts/script.php?script_id=4111
installed. I have included the following lines for the .vimrc:
autocmd BufRead,BufNewFile *.log set syntax=log4j
I am getting "autocmd unknown command"
when I am running
. .vimrc
from the bash
Please help.
The . command in Bash reads the argument as a Bash script; you're executing the Vim configuration as a Bash script. Of course, Bash doesn't know the autocmd command, and therefore complains.
Vim will automatically read in your ~/.vimrc on startup (cp. :help initialization). Just open a new Vim instance, and your new configuration will apply. You can ensure that the .vimrc has been read via :scriptnames (the file path should be listed at the start), or list your defined autocmd via :autocmd BufRead *.log
If you :edit somefile.log, you can verify that the syntax has been set via :setlocal syntax?
You don't need to run that command, once you will open any "*.log" file using "vim" the plugin will be used. if installed correctly.

Iterm2 case insensitive autocomplete

How can I add case insensitive autocomplete to Iterm2 terminal? I have tried:
set completion-ignore-case on
But this does not seem to be the solution.
Set ignore case on in inputrc file. The following command will create the file with the command if not exist already
echo "set completion-ignore-case On" >> ~/.inputrc
Then run
source ~/.inputrc
to load it on current instance of terminal.
I was entering in the set completion-ignore-case on as a command in the command line. I instead needed to navigate to my root directory, create a file named .inputrc and input the set completion-ignore-case on text in that file.

Why doesn't .vimrc get executed?

When I try to use . .vimrc it gives and error:
bash: runtime! command not found
bash: syntax: command not found
bash: filetype: command not found
bash: filetype: command not found
It just randomly stopped working for no reason, all other dotfiles seem to work fine. The .vimrc contains this:
runtime! archlinux.vim
set number
set noswapfile
set nobackup
syntax on
set autoindent
set smartindent
set smarttab
filetype plugin on
filetype indent on
set incsearch
set hlsearch
It also gave an error inside a comment when it was there.
The . (or source) command is a bash command which reads a file (which should be a valid bash script) in the context of the current shell instance.
The .vimrc file is not a bash script, it's something that's read and processed by vim rather than bash.
It's no different to trying to compile C code with a Pascal compiler. The file content is not suitable for what you're trying to do with it. The .vimrc file should be automatically picked up next time you run a vim instance.
~/.vimrc is the runtime configuration file for vim i.e. the file will be read by vim when it starts and all the statements are vim specific.
As you are trying to source the file in bash, you are getting the errors as bash has no idea of the vim specific statements like runtime, syntax etc.
use vimorvi instead of source command to activate .vimrc.Because .vimrc is not *.sh like .bashrc and etc.

How can I debug issues in VimL?

I'd like to know more about debugging in vim. What features does vim have that can help me to diagnose a problem I might have?
I'd basically like to know:
How can I diagnose a problem with my .vimrc and other configuration files?
What are some strategies to debugging a script in VimL?
How can I diagnose a problem with .vimrc and other configuration files?
If you're having some unexpected behavior in vim and you're not sure where the
problem is originating, there are a few approaches to honing in on the source
of the issue. One of the best first steps is to find out if your problem is
normal vim behavior, caused by a plugin or caused by your .vimrc.
If your vim instance is setting a particular 'option' and you're not sure
where it is being set. You can use the :verbose command to find out. For
instance
:verbose set nocompatible?
nocompatible
Last set from ~/.vimrc
To run an instance of vim without any plugins or configuration files run
vim -N -u NONE
I set this as to alias called cleanvim in my .bashrc file. The -u NONE is
what's doing the magic here. The -N simply puts vim into nocompatible mode,
which generally is desired. You can also use the option NORC to only exclude
your vimrc. Note that if you use something like pathogen or vundle to
instantiate your plugins from within your vimrc, then your plugins will also
not load properly.
If you are using a plugin manager like pathogen or vundle then excluding your
plugins is simple; just comment out the line in your .vimrc that calls
pathogen or vundle. However if you have other plugins loaded from your .vim
directory you can exclude them with the --noplugin flag.
If your problem is being caused by a plugin, try adding back plugins one by one
to determine which one is causing the issue. From there you can either report
the bug to the plugin's maintainer or try to diagnose the problem yourself
using the tips from the rest of this answer.
If your problem is caused by your .vimrc there are some ways to hone in on
the problem further. Once simple method is to add the finish command at some
point in your .vimrc. Once this command is encountered the script will stop
being sourced and no commands after it will be executed. In this way you can
exclude large portions of your .vimrc and try to find out the general region
where the problem is coming from.
What are some strategies to debugging a script in VimL?
Vim has a help section on this topic at :h debug-scripts. This describes
vim's debug mode in detail, which will allow you to set breakpoints and step
through a sourced file or user function. You can add a breakpoint on a specific
function or a specific line in a file. For instance...
" set a breakpoint on the function MyCoolFunc
:breakadd func MyCoolFunc
" set a breakpoint on line 43 of your .vimrc
:breakadd file 43 .vimrc
" set a breakpoint at this location
:breakadd here
After you set a breakpoint you can source the file again to begin debug mode at
that line. If you'd like to use debug mode on an entire file start vim with the
-D flag. You could also run debug mode on a particular command. For example,
say you're having trouble with a particular command :MyCommand. You can start
debugging mode on this command with :debug MyCommand.
Once debug mode has been started you can use the usual set of vim commands.
This is useful because you can now check the value of variables using the
echo command to try and diagnose an issue. You can also use the verbose
option to provide extra information about the following lines. See :h 'verbose'
for its options.
The scriptease is very helpful to debug vimL:
provide commands for easier insertion of Vim breakpoints
:Runtime allows easy reload of plugins, even unleting include guards
:Disarm {file}: attempt to disable a runtime file by removing its mappings, commands and autocmds
:Time {command}: profilling
:Verbose {command}: like :verbose, but capture the results to a file and load it in the preview window
For cases where you need to restart Vim several times (e.g.: incremental removal of plugins) the :RestartVim command of session plugin can be useful.
For vimL I find those 2 plugins awesome:
BreakPts
Set/View Vim breakpoints and browse functions visually
Decho
Better echo functionality suitable for debugging scripts
I also use this to quickly source the selected vimL lines:
fu! SourceRange() range
let tmpsofile = tempname()
call writefile(getline(a:firstline, a:lastline), l:tmpsofile)
execute "source " . l:tmpsofile
call delete(l:tmpsofile)
let n = a:lastline - a:firstline + 1
echo 'Sourced ' . n . ' line' . (n > 1 ? 's' : '')
endf
com! -range Source <line1>,<line2>call SourceRange()
nn gs m`:Source<cr>``
vn gs m`:Source<cr>``

How to detect if "&t_Co" is "defined" in my .vimrc?

When I :echo &t_Co in my Vim, it shows my terminal colors. If I :echo &t_Co in my gVim, nothing is showed (since I'm not in terminal).
I would like to use a condition in my vimrc to detect this situation (the &t_Co with no value in gVim, how do I test it? I know I can use has("gui_running") to see if I'm in gVim or not, but I would like to know how to test a variable like &t_Co that isn't showing nothing).
if !empty(&t_Co)
" t_Co is set to a non-empty value
endif
(exists('&t_Co') doesn't help because it does exist in GVim, it's just empty.)

Resources