gvim背景配色

背景(feihua)

重新安装了gvim7.4后(发现gvim7.3有显示字符的bug便升级了),忽然想改一下windows下gvim的外观,在看了几个博客,却发现无法设置,于是到官网找到了解决方案,贴在此处。

最初试探的解决方法:

gvim无法自动保存当前手动的设置,比如字体、配色方案。但是修改一下gvim的配置文件,就可以载入我们所希望的设置。

修改vim安装目录下的_vimrc文件,把配色方案设置成黑色背景灰色文字的koehler方案,设置字体大小为14,这样看得不会太辛苦。把下面的代码复制到_vimrc文件的末尾就OK了。

colo koehler

set guifont=Courier_New:h14:cANSI

Open vimrc file - Vim Tips Wiki

Contents

[show]

What is vimrc?Edit

The vimrc file contains optional runtime configuration settings to initialize Vim when it starts. On Unix based systems, the file is named .vimrc, while on Windows systems it is named _vimrc:help vimrc

You can customize Vim by putting suitable commands in your vimrc. Here is a very simple example:

" Always wrap long lines:
set wrap

Lines that begin with " are comments and are not read by vim.

Search for file vimrc_example.vim in your Vim files for another example. :help vimrc-intro:help vimrc_example.vim

To customize Vim for editing a specific file, or a specific type of file, you can usemodelines, or auto commands, or filetype plugins. :help auto-setting :help filetype

Location of vimrcEdit

In Vim, your home directory is specified with $HOME. On Unix systems, this is your ~directory. On Windows systems, the best way to find the value of $HOME is from within Vim, as follows. These commands are useful to see what directories your Vim is using:

:version
:echo expand(‘~‘)
:echo $HOME
:echo $VIM
:echo $VIMRUNTIME

Note the ‘system vimrc file‘ and ‘user vimrc file‘ paths displayed by the :versioncommand. The system vimrc file can be created by an administrator to customize Vim for all users. In addition, each user can have his or her own user vimrc.

The output from :version includes the paths of the system and user vimrc and gvimrc files. For example:

   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"

If the gvimrc files exist, they are used to configure Vim when the GUI version (gvim) runs (after settings from vimrc are applied).

Settings for gvim can also be placed in the vimrc file using a has(‘gui_running‘) check:

if has(‘gui_running‘)
  set guioptions-=T  " no toolbar
  colorscheme elflord
endif

Although this can be useful to avoid the clutter of both a vimrc and gvimrc file, using the gvimrc file has distinct benefits over the "gui_running" check. The most notable being that a gvimrc file is sourced when using the :gui command to change a vim session into a gvim session. Anything that was in the vimrc inside a "gui_running" check will not be applied since the vimrc is only sourced when Vim initially starts.

Per-directory vimrcEdit

Vim can be configured so that, when starting, it reads commands from a vimrc file in the current directory, after reading the primary vimrc. This is configured by adding set exrcto the primary vimrc file. Setting ‘exrc‘ can be a security problem because it means Vim will execute commands from any vimrc file in the directory where Vim is started.:help ‘exrc‘ For that reason, set the ‘secure‘ option if you use this option, and you may also want to limit setting this option to when Vim is started from known "safe" directory trees:

if getcwd()~=#‘^\(/my/safe/dir1/\|/my/safe/dir2/\)‘
  set secure exrc
endif

Opening vimrcEdit

If Vim finds your vimrc file during startup, Vim will set the MYVIMRC environment variable to the full path of the vimrc file. Similarly, if your gvimrc file is found, the MYGVIMRCvariable is set. Therefore, you can easily edit these files from within Vim:

:e $MYVIMRC
:e $MYGVIMRC

Using file name completion, you could type :e $M then press Tab until you see the desired variable. If you only want to see the path, type :echo $M then press Tab to see the variable, and press Enter.

In gvim, the Edit menu includes "Startup Settings" which will use $MYVIMRC to edit your vimrc file. If $MYVIMRC does not exist, "Startup Settings" will create a new file using the "user vimrc file" path shown by the :version command.

Sourcing vimrcEdit

After you have saved changes to your vimrc file, you can see the results by exiting from Vim, then starting Vim again.

If you are making frequent changes, you might want to "source" (execute) the changed vimrc file without exiting:

:so $MYVIMRC
" Alternative that can be used if vimrc is the current file:
:so %

Warning You may need to plan your vimrc so re-sourcing does not cause problems. If you define commands, functions, or autocmds, you must make them remove or override the previous version when sourced, or you will get errors (for commands and functions) or duplicates (for autocmds). Here are some examples that will work correctly when re-sourced:

" Use bang (!) to redefine a command or function, if already defined.
command! Mycommand echo "Hello!"
function! Myfunc()
  echo "Hello!"
endfunction

" Put all autocmds in some augroup and use au! to clear the group.
augroup vimrc_autocmds
  au!
  autocmd BufRead * echo "File read!"
augroup END

Recovering from errorsEdit

Some errors in your vimrc may prevent Vim from starting successfully. A reliable way to handle that would be to rename your vimrc file, then edit the renamed file, then give it the correct name. Alternatively, you could start Vim with a command like this (or use "gvim" if that is how you run Vim):

vim -N -u NONE -U NONE

The -N starts in "not compatible" mode (that is, with extra Vim features). The NONEargument (must be uppercase) skips initializations and does not read any vimrc file (-u), and does not read any gvimrc file (-U).

You could now use the :version command to show the vimrc path, then enter a command to edit that file.

CommentsEdit

 TO DO 

  • What else is needed to explain what vimrc is, and how to use it, for a beginner?
  • Do something with the following text from the original tip (if keep it, need to fix text because it assumes you have used some standard setup for installation, and assumes $VIM and $HOME are some default, and of course is for Windows):

On Windows, when you start Vim normally, it *either* runs the file "C:\Documents and Settings\(user name)\_vimrc" (where "(user name)" is replaced by the actual user name); *or*, if that file doesn‘t exist (it usually doesn‘t, for most users), it runs the file "C:\Program Files\vim\_vimrc". Note that if you have more than one disk your home may be different; do an ":echo $HOME" to know where is your home. You should also see the _viminfo file in that directory.

  • Include information for Windows:

    • When $HOME is not defined, it is created by combining $HOMEDRIVE and$HOMEPATH (if defined).
    • The recommended method to define $HOMEDRIVE and $HOMEPATH is to set the "Home folder ... Local path" on the Profile tab of the User properties in Local Users and Groups (run lusrmgr.msc).
    • I‘d say that this (the item above) is the recommended method to set your home folder in Windows. The recommendes method to specify where your _vimrc is located (if it differs from your home folder) is to set the $HOME environment variable. (Spiiph 00:16, 29 July 2009 (UTC))
  • Link to the #vim-approved .vimrc? ;) (Spiiph 00:18, 29 July 2009 (UTC))


Proposal Omit suggestions like the following that attempt to auto-source vimrc. I suspect that anyone needing to read a tip to do this could get themselves in quite a bit of trouble. IMHO it‘s a lot more sensible to map a key to source a script so you can control when it is sourced. I haven‘t bothered to put such a mapping in the tip so far because the :so % info seems more helpful, and entirely adequate. --JohnBeckett 11:56, 23 August 2008 (UTC)

To source changes immediately, add to vimrc:

au BufLeave ~/.vimrc :source ~/.vimrc
Why not use a BufWritePost instead of BufLeave, so it will source whenever you save?


Getting started tip ... I hit this page because I could not remember the "mkvim" command. I found it elsewhere and thought I‘d throw it in here. If you open vim, change some settings and get things how you like you can use this command

:mkv [file]

to automatically make a vimrc file based on your current settings. The [file] part is optional; vim will use ~/.vimrc by default. If you already have a .vimrc and you attempt this you we will be warned that .vimrc already exists. You can use

mkv!

to overwrite the existing file if you like. However once you do this your original .vimrc file is gone so you may want to back up any existing .vimrc before you try this.

Using :mkvimrc to create .vimrc isn‘t a terribly good idea, since it saves mappings and abbreviations setup by plugins. It can be useful to copy currently set options to .vimrc however. (Spiiph 14:51, 27 July 2009 (UTC))
参考来源:http://vim.wikia.com/wiki/Open_vimrc_file
              http://blog.sina.com.cn/s/blog_4ddef8f80100wjs1.html
时间: 2024-11-03 03:42:20

gvim背景配色的相关文章

gVim设置配色方案和字体

在gVim的安装目录中找到_vimrc文件,编辑该文件,在文件的最后加上如下两行: 第一行是设置字体的,第二行是设置配色方案的. 这里千万注意=前后不要有空格,我试了一下后面的字体名称写出Courier_New:h14也可以 字体名称中有空格的要在空格前面加上\

[转]将Eclipse设置为黑色主题 方式一

将Eclipse设置为黑色主题 觉得黑色的主题&配色很高大上,于是花了点时间实践出下面一种方法. 修改代码编辑区配色 修改整个软件主题 先上成果图: 但是进度条依旧是白色的,不知道怎么弄了╮(╯▽╰)╭ Step 1 修改代码编辑区背景配色,有两种方法: 1.去官方网站(http://eclipsecolorthemes.org/)上下载自己想要的配色方案.但是这个方法一次只能添加一个配色方案.于是我采用了第二种方法. 2.打开Eclipse,help->Install new softwa

移动网站七步完美打造

本文摘自e良师益友网 现在手机上App很火爆,看到最近很流行的游戏很多人 就会去装一个.可是想想我们平常经常使用的应用也就3-5个,微博.微信.浏览器等,一般最多不会超过7个.普通人的大脑无法同时处理七件以上的信息单 位,人们在列出必须记牢的事项上多半只列到第七项:一周有7天,音乐有7个音符,电话号码通常是7位数,世界奇迹是7个.七仙女.白雪公主和7个小矮人 等. 一方面是用户偶发性的需求,一方面却是开发者面对移动互联网海量用户的渴求,如何平衡这两者之前的矛盾呢?专为移动设备优化的移动网站是可行

自定义博客园皮肤:暗色流体响应式布局

博客园的皮肤模板虽然有100多套,但我需要的作品却没几套,从布局上看,大多是固定布局,有的使用表格布局,有的将侧边栏在HTML页面的代码顺序放在主内容的前面.这些布局方式不利于页面缩放和不同屏幕尺寸与分辨率的设备浏览,尤其是在当今网页浏览设备屏幕尺寸与分辨率多样化的时代,流体与响应式布局才是最佳的选择.从配色上看,博客园有3款还不错的暗色皮肤,但不符合我布局的要求. 我想要自己的博客皮肤满足以下要求: 模版选择:不能使用表格布局,侧边栏在HTML页面的代码顺序放在主内容 的后面,页面结构和样式简

如何改变Myeclipse编辑区背景色

如何改变Myeclipse编辑区背景色 分类: 工具2010-12-24 11:45 5507人阅读 评论(4) 收藏 举报 myeclipsesystem 目录(?)[+] 编辑窗口右键单击-->Preferences-->General加号-->Editors加号-->点Text Editors字样-->右下窗口选Backgroud color,右边点掉System Default按钮,点Color右边的颜色框,选择颜色OK 背景颜色向你推荐:RGB 199 237 20

将Eclipse设置为黑色主题

将Eclipse设置为黑色主题 觉得黑色的主题&配色很高大上,于是花了点时间实践出下面一种方法. 修改代码编辑区配色 修改整个软件主题 先上成果图: 但是进度条依旧是白色的,不知道怎么弄了╮(╯▽╰)╭ Step 1 修改代码编辑区背景配色,有两种方法: 1.去官方网站(http://eclipsecolorthemes.org/)上下载自己想要的配色方案.但是这个方法一次只能添加一个配色方案.于是我采用了第二种方法. 2.打开Eclipse,help->Install new softwa

如何更换gvim配色方案

1.查看你的系统中自带的有哪些配色方案,在shell中执行命令: ls -l  /usr/share/vim/vim70/colors/ 可以看到列出的方案,我们以"desert"方案为例. 2.在你的家目录下创建.vimrc,内容如下: set tabstop=4 set softtabstop=4 set shiftwidth=4 set autoindent set cindent set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,

windows上搭建python+gvim开发环境

参照了 http://www.cnblogs.com/xd502djj/archive/2010/09/16/1827683.html ,发现有些问题,所以修改了一些. Vim as Python IDE on windows(转) 下载安装Python. 从Vim的网站下载vim,建议下Self-installing executable的版本. 编辑vim的配置文件_vimrc,windows的_vimrc用户文件可以在用户目录下创建. 设置中文支持 " 设置编码自动识别, 中文引号显示 &

Eclipse修改字体、颜色、编译器背景颜色等操作方法

1.eclipse 背景色设置:Window->Preferences->General->Editors->Text Editors->Backgroud colors取消System default 设置成:RGB(204,232,207). 2.字体大小设置:java 字体:菜单windows>Prefenrence>General Appearance>Colors and Fonts 在右边的菜单中选Java> Java Editor Tex