When I put set scroll=10 in my .vimrc it does not work, but it does work when I enter the command in command mode.
I have many other commands in my .vimrc, what reason could there be for this set to not be getting through? It is the last line in my .vimrc.
:verbose set scroll?
should tell you which plugin script has last modified that option. If you don't find the culprit this way, you could workaround by setting it at the last possible moment by putting this in your ~/.vimrc
:autocmd VimEnter * set scroll=10
Related
when I run
vim good.html
and
:verbose set et?
expandtab
Last set from ~/.vimrc
but when I run
vim good.py
and
:verbose set et?
expandtab
Last set from /usr/share/vim/vim74/ftplugin/python.vim
I want apply ~/.vimrc file in .py, not python.vim
Yesterday I all is fine but today suddenly path was changed
please someone teach me how can I change the path
Put this into your .vimrc:
autocmd VimEnter *.py set expandtab
or if you want to have the configuration of .vimrc to be executed after all plugins being loaded - in case they have changed some settings -, you can add this line:
autocmd VimEnter * source ~/.vimrc
Note: It could have a side-effect depending on the content of your .vimrc because the latter actually will be executed twice (at the begining and at the end of vim startup) so you need to consider that.
Concerning Plugins now, if they are logged in some specific folders like .vim or vim installation path they will be loaded automatically unless you removed them or run some specific commands to be ignored.
Vim has also the ability to detect the type of file which is being edited, and this occurs when the option filetype is activated and probably this is what happened to you.
So typing :filetype will confirm that. Maybe you can desactivate it for some specific files if you wish. It is up to you !
:help VimEnter
VimEnter
VimEnter After doing all the startup stuff, including
loading .vimrc files, executing the "-c cmd"
arguments, creating all windows and loading
the buffers in them.
I want to enable cursorline only for gvim but disable it for vim in TUI, I tried this in .vimrc
if has("gui_running")
set cul
else
set nocul
endif
but it doesn't seem to work.
The .vimrc gets read by gvim and vim while the .gvimrc gets only read by gvim. As the docs say:
The gvimrc file is where GUI-specific startup commands should be placed. It
is always sourced after the |vimrc| file. If you have one then the $MYGVIMRC
environment variable has its name.
While your command should do the trick, I'd place the set cul command in my .gvimrc.
This will also help your .vimrc being cleaner and you don't need gui_running checks anymore.
The title pretty much says it all. When I :source $MYVIMRC or :source ~/.vimrc, the last search re-appears. I can easily turn this off again with :noh, but it re-appears every time I :source.
This persists
With a fresh .vimrc
After deleting current MacVim install and downloading a fresh copy
In iTerm using vim
I have checked in every file listed with :version, and other than my .vimrc, the only other file listed that isn't empty is $VIM/vimrc - which has only:
set nocompatible
set backspace+=indent,eol,start
set langmenu=none
I also tried the nuclear method: disable all plugins and pretend it's a fresh install:
mv .vim .vim-old
mv .vimrc .vimrc-old
touch .vimrc
echo "set hlsearch" > .vimrc
The issue still occurs.
I'm pretty stumped as I don't recall this being the normal behavior; any help would be much appreciated.
Credit to #AndyRay - I was misusing noh to get rid of the last search's highlighting, when instead I should be overriding the search term with :let #/ = "".
See: Vim clear last search highlighting
Going off what Josh was getting at. Add the following to your ~./vimrc:
" higlight search but not when sourcing .vimrc
set hls
let #/ = ""
I've got set formatoptions=cqn in my vimrc, but for some reason it doesn't stick. It seems like Vim is reverting to the default (fo=tcq) at some point… But I can't figure out why. Running -V100/tmp/log just gives me:
formatoptions=tcq
Last set from ~/.vimrc
With no useful context.
So, is there any way to make formatoptions stick? Or do I just need to create an autocmd to reset it each time a new file is loaded?
Edit
Using :verbose set formatoptions shows this:
formatoptions=tcq
Last set from ~/.vimrc
However, the only reference to fo or formatoptions in my ~/.vimrc is set formatoptions+=cqn.
This behavior is because of C file plugin in VIM. Since file plugin is loaded after loading .vimrc, the settings in .vimrc are overwritten.
The solution given by David Wolever seems to be the best option.
Add the following line in .vimrc:
autocmd BufNewFile,BufRead * setlocal formatoptions+=cqn
...instead of the normal set formatoptions command.
I ran across this problem too. I had project-specific configurations something like
autocmd BufRead,BufNewFile project/*.c setlocal formatoptions-=cro
However, set fo? showed formatoptions=croql. Turns out, I needed BufWinEnter instead of BufRead:
After a buffer is displayed in a window. This
can be when the buffer is loaded (after
processing the modelines) or when a hidden
buffer is displayed in a window (and is no
longer hidden).
Does not happen for :split without
arguments, since you keep editing the same
buffer, or ":split" with a file that's already
open in a window, because it re-uses an
existing buffer. But it does happen for a
":split" with the name of the current buffer,
since it reloads that buffer.
So this works
autocmd BufWinEnter,BufNewFile project/*.c setlocal formatoptions-=cro
According to the vim documentation on formatoptions:
NOTE: This option is set to the Vi
default value when 'compatible' is
set and to the Vim default value when
'compatible' is reset.
So if the value of compatible is changing along the way, that could be causing the issue you're seeing.
I does sound like some file either sourced from your .vimrc or plugins are changing that value.
Something to try to pinpoint it is
start vim without sourcing anything, use
vim -u NONE
Using NORC skipps .vimrc but loads plugins
Check :help --noplugin to read about various startup-options that controls the sourcing.
--noplugin Skip loading plugins. Resets the 'loadplugins' option.
{not in Vi}
Note that the |-u| argument may also disable loading plugins:
argument load vimrc files load plugins ~
(nothing) yes yes
-u NONE no no
-u NORC no yes
--noplugin yes no
Perhaps this might be useful as well (from help: :set):
When 'verbose' is non-zero, displaying an option value will also tell where it
was last set. Example: >
:verbose set shiftwidth cindent?
< shiftwidth=4 ~
Last set from modeline ~
cindent ~
Last set from /usr/local/share/vim/vim60/ftplugin/c.vim ~
perhaps... :-)
Edit
Are you using compatible? From help: formatoptions
NOTE: This option is set to the Vi default value when 'compatible' is
set and to the Vim default value when 'compatible' is reset.
Found in /usr/share/vim/vim74/ftplugin/vim.vim:
" Set 'formatoptions' to break comment lines but not other lines,<br>
" and insert the comment leader when hitting <CR> or using "o".<br>
setlocal fo-=t fo+=croql
Remove it. Then all things done.
I wrote
set tw=0
into my .vimrc file.
But when I verify options with
:set
it's still
textwidth=78
Why ?
You can use :
:verbose set tw?
Which should tell you where it was last setted, for example :
textwidth=80
Last set from ~/.vimrc
Why don't you just grep through your .vim directory for it?
If you have modelines enabled, vim will read the last few lines of the file for vim settings, so check that as well.