I am running windows with gVim version 7.3-46 (32bit)
I have set up Vim to automatically source my .vimrc after saving it with
if has("autocmd")
autocmd bufwritepost vimrc.win source $MYVIMRC "Source config file on save
endif
But when I issue the :w command my Powerline loses its color (it gets sourced indeed but breaks something). After reloading the file manually via :source $MYVIMRC the color returns. --> MYVIMRC
Duplicate of issue 213. When resourcing vimrc always use autocmd-nested.
Related
I have used vim for a while now, but after my friend introduced me to gvim, I'm trying to use it now. I have basic vimrc settings of :
set guifont=Monaco:h17
colorscheme zellner
set number
syntax on
I noticed that the settings were applied to my gvim. I want a different colorscheme for gvim and vim as I usually open the files I'll read quickly with vim or vi, and use gvim as my main code editor.
I heard people talk about the .gvimrc file, but I don't have it where my .bashrc, .zshrc, and .vimrc are.
How do I have separate colorschemes for gvim and vim?
Vim doesn't create either ~/.vimrc or ~/.gvimrc for you so you have to create them on your own.
You can either create the missing file in your shell, then edit in Vim:
$ touch ~/.gvimrc
$ vim ~/.gvimrc
<some editing>
:wq
or do everything from Vim:
:e ~/.gvimrc
<some editing>
:wq
Note: ~/.vimrc is still sourced whether you have a ~/.gvimrc or not so your gvimrc can be kept lightweight by only having GUI-specific options and overrides. In your case:
" ~/.vimrc
colorscheme zellner
set number
syntax on
" ~/.gvimrc
set guifont=Monaco:h17
colorscheme slate
You can do it in a single ~/.vimrc:
if has("gui_running")
colorscheme zellner
else
colorscheme blue
endif
See http://vimdoc.sourceforge.net/htmldoc/eval.html#has() and http://vimdoc.sourceforge.net/htmldoc/eval.html#feature-list
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.
I am trying to get vim to recognize a filetype.vim file consisting of the following:
if exists("did_load_filetypes")
finish
endif
augroup autodetect
au! BufRead,BufNewFile *.ish setfiletype perl
augroup END
This file is in the directory ~/programs/vim
My .vimrc file contains the following line:
set runtimepath=~/programs/vim,$VIMRUNTIME
I checked that this line is being executed by typing ":set runtimepath?" The result is "runtimepath=~/programs/vim,/usr/share/vim/vim74".
But when I open a file such as ish.ish, the vim filetype variable is set to 'on'. When I open x.pl, the vim filetype variable is set to 'perl'.
I can fix the problem by copying (or moving) filetype.vim to the ~/.vim directory (without changing runtimepath). Why doesn't vim recognize filetype.vim in ~/programs/vim?
The 'runtimepath' option is meant to tell Vim where to look for "standard" *.vim files such as colorschemes and plugins. Try :echo &rtp in a clean Vim session to see what it should look like and read :help 'runtimepath'. By setting this option to a meaningless value you effectively make Vim unable to find those files and thus work correctly.
To add a specific directory to 'runtimepath', use the following syntax:
set runtimepath+=/path/to/directory
But what's the reason you'd want to use a non-standard directory for standard scripts? What's wrong with ~/.vim?
The most obvious way to tell Vim about a new filetype is to add these lines to your ~/.vimrc:
augroup autodetect
autocmd!
autocmd BufRead,BufNewFile *.ish set filetype=perl
augroup END
The cleanest way is to put this line in ~/.vim/ftdetect/ish.vim:
autocmd BufRead,BufNewFile *.ish set filetype=perl
I have a symlink which points my .vimrc to the one from my repo.
Vim loads that just fine, but I can't get it to auto-source upon it being changed.
I have the typical:
if has("autocmd")
autocmd! BufWritePost .vimrc source $MYVIMRC
endif
Which works if the vimrc is not symlinked.
I have a similar setup where ~/.vimrc is just a symlink to a git repository. The following autocommand works for me:
autocmd! bufwritepost .vimrc source %
I don't like symlinks in general and Vim doesn't really like them either.
The layout I use is probably similar to yours:
~/.vimrc
~/.vim/vimrc
with a big difference: ~/.vimrc is a real file, not a symlink, and it contains only one line:
runtime vimrc
that executes my real ~/.vim/vimrc. Because it is a Vim command and it doesn't use a file path, that line can be the same on every system.
Because $MYVIMRC points to a real file, :so $MYVIMRC always works.
I solved that problem that way that all my configuration I am keeping in dotfiles folder
https://github.com/lis2/dotfiles
Then I have small and simple ruby script which I running when I am changing something in configuration
#!/usr/bin/env ruby
require "fileutils"
config_hash = { "tmux.conf" => ".tmux.conf", "vimrc" => ".vimrc", "vim" => ".vim", "gitconfig" => ".gitconfig", "gitignore" => ".gitignore"}
config_hash.each do |k,v|
FileUtils.rm_rf(File.dirname(__FILE__) + "/../#{v}")
FileUtils.ln_s(File.dirname(__FILE__) + "/#{k}", File.dirname(__FILE__) + "/../#{v}")
end
I recommend you to built same configuration. On all computers (private/work) I just clone my repo, run symlink.rb and my simple environment is ready for work.
cheers!
I have both .vimrc and .gvimrc symlinked to a git repo like you are describing. I'm running MacVim macOS.
I found a great answer to the question progressively-slower-reloading-time-of-vimrc.
I modified it a bit to reload both vimrc and gvimrc when any of them changes. I have been using it for months now without issues.
Here it is. You need just this and just in .vimrc. You don't have to add anything to .gvimrc.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Autoreload vimrc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
augroup configsGroup
autocmd!
" Make changes effective after saving .vimrc. Beware that autocommands are
" duplicated if .vimrc gets sourced again, unless they are wrapped in an
" augroup and the autocommands are cleared first using 'autocmd!'
autocmd! bufwritepost *\<vimrc\> call OnSavingConfigs()
autocmd! bufwritepost *\<gvimrc\> call OnSavingConfigs()
augroup END
" Avoid infinite loops
if !exists("*OnSavingConfigs")
function! OnSavingConfigs()
" Clear previous mappings, they don't go away automatically when
" sourcing vimrc.
mapclear
source $MYGVIMRC
source $MYVIMRC
redraw
echo "Reloaded " . $MYVIMRC . " and " . $MYGVIMRC . "."
endfunction
endif