vim的配置文件.vimrc常规配置

12 篇文章 0 订阅

           使用vim进行编辑时,默认情况下,编辑的界面上是没有显示行号、语法高亮、智能缩进等功能的。如果想让vim具有这些功能,需要手动设置一个配置文件【.vimrc,该文件会保持在用户的根目录下

先show下我的.vimrc文件:

set nu
set tabstop=4
set shiftwidth=4
syntax on 
"colorscheme wombat
colorscheme desert
set hlsearch
set incsearch
set smartindent
set autoindent
set cursorline
set showmatch  
set ruler
set textwidth=1000
set cindent
set nobackup

filetype on

nmap <F4> :NERDTreeToggle<cr>
nmap <F2> :TlistToggle<cr>
nmap <F12> :Calendar<cr>


nmap <C-k> <C-W>k
nmap <C-j> <C-W>j
nmap <C-h> <C-W>h
nmap <C-l> <C-W>l

let Tlist_Use_Right_Window=1
let Tlist_File_Fold_Auto_Close=0
let Tlist_Exist_OnlyWindow = 1 
let Tlist_Sort_Type = "name"
let Tlist_Compart_Format = 1
let g:winManagerWindowLayout='FileExplorer|TagList'

"let g:miniBufExplMapWindowNavVim = 1
"let g:miniBufExplMapWindowNavArrows = 1
"let g:miniBufExplMapCTabSwitchBufs = 1
"let g:miniBufExplModSelTarget = 1 

" C/C++
map <F5> :call CompileRunGcc5()<CR>
func! CompileRunGcc5()
	exec "!make clean"
	exec "w"
	exec "!make"
	endfunc

" C/C++
map <F7> :call CompileRunGcc7()<CR>
func! CompileRunGcc7()
	exec "w"
	exec "!make"
	endfunc

" Encoding settings
if has("multi_byte")
	" Set fileencoding priority
	if getfsize(expand("%")) > 0
		set fileencodings=ucs-bom,utf-8,cp936,big5,euc-jp,euc-kr,latin1
	else
		set fileencodings=cp936,big5,euc-jp,euc-kr,latin1
	endif

	" CJK environment detection and corresponding setting
	if v:lang =~ "^zh_CN"
		" Use cp936 to support GBK, euc-cn == gb2312
		set encoding=cp936
		set termencoding=cp936
		set fileencoding=cp936
	elseif v:lang =~ "^zh_TW"
		" cp950, big5 or euc-tw
		" Are they equal to each other?
		set encoding=big5
		set termencoding=big5
		set fileencoding=big5
	elseif v:lang =~ "^ko"
		" Copied from someone's dotfile, untested
		set encoding=euc-kr
		set termencoding=euc-kr
		set fileencoding=euc-kr
	elseif v:lang =~ "^ja_JP"
		" Copied from someone's dotfile, unteste
		set encoding=euc-jp
		set termencoding=euc-jp
		set fileencoding=euc-jp
	endif
	
	" Detect UTF-8 locale, and replace CJK setting if needed
	if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
		set encoding=utf-8
		set termencoding=utf-8
		set fileencoding=utf-8
	endif
endif

当然了,你的配置文件,不用照搬我的,请参阅下网上老外的example【 http://www.vi-improved.org/vimrc.php】:

1 " Modeline and Notes {
  2 "   vim: set foldmarker={,} foldlevel=0 spell:
  3 "
  4 "   This is my personal .vimrc, I don't recommend you copy it, just 
  5 "   use the "   pieces you want(and understand!).  When you copy a 
  6 "   .vimrc in its entirety, weird and unexpected things can happen.
  7 "
  8 "   If you find an obvious mistake hit me up at:
  9 "   http://robertmelton.com/contact (many forms of communication)
 10 " }
 11 
 12 " Basics {
 13     set nocompatible " explicitly get out of vi-compatible mode
 14     set noexrc " don't use local version of .(g)vimrc, .exrc
 15     set background=dark " we plan to use a dark background
 16     set cpoptions=aABceFsmq
 17     "             |||||||||
 18     "             ||||||||+-- When joining lines, leave the cursor 
 19     "             |||||||      between joined lines
 20     "             |||||||+-- When a new match is created (showmatch) 
 21     "             ||||||      pause for .5
 22     "             ||||||+-- Set buffer options when entering the 
 23     "             |||||      buffer
 24     "             |||||+-- :write command updates current file name
 25     "             ||||+-- Automatically add <CR> to the last line 
 26     "             |||      when using :@r
 27     "             |||+-- Searching continues at the end of the match 
 28     "             ||      at the cursor position
 29     "             ||+-- A backslash has no special meaning in mappings
 30     "             |+-- :write updates alternative file name
 31     "             +-- :read updates alternative file name
 32     syntax on " syntax highlighting on
 33 " }
 34 
 35 " General {
 36     filetype plugin indent on " load filetype plugins/indent settings
 37     set autochdir " always switch to the current file directory 
 38     set backspace=indent,eol,start " make backspace a more flexible
 39     set backup " make backup files
 40     set backupdir=~/.vim/backup " where to put backup files
 41     set clipboard+=unnamed " share windows clipboard
 42     set directory=~/.vim/tmp " directory to place swap files in
 43     set fileformats=unix,dos,mac " support all three, in this order
 44     set hidden " you can change buffers without saving
 45     " (XXX: #VIM/tpope warns the line below could break things)
 46     set iskeyword+=_,$,@,%,# " none of these are word dividers 
 47     set mouse=a " use mouse everywhere
 48     set noerrorbells " don't make noise
 49     set whichwrap=b,s,h,l,<,>,~,[,] " everything wraps
 50     "             | | | | | | | | |
 51     "             | | | | | | | | +-- "]" Insert and Replace
 52     "             | | | | | | | +-- "[" Insert and Replace
 53     "             | | | | | | +-- "~" Normal
 54     "             | | | | | +-- <Right> Normal and Visual
 55     "             | | | | +-- <Left> Normal and Visual
 56     "             | | | +-- "l" Normal and Visual (not recommended)
 57     "             | | +-- "h" Normal and Visual (not recommended)
 58     "             | +-- <Space> Normal and Visual
 59     "             +-- <BS> Normal and Visual
 60     set wildmenu " turn on command line completion wild style
 61     " ignore these list file extensions
 62     set wildignore=*.dll,*.o,*.obj,*.bak,*.exe,*.pyc,
 63                     \*.jpg,*.gif,*.png
 64     set wildmode=list:longest " turn on wild mode huge list
 65 " }
 66 
 67 " Vim UI {
 68     set cursorcolumn " highlight the current column
 69     set cursorline " highlight current line
 70     set incsearch " BUT do highlight as you type you 
 71                    " search phrase
 72     set laststatus=2 " always show the status line
 73     set lazyredraw " do not redraw while running macros
 74     set linespace=0 " don't insert any extra pixel lines 
 75                      " betweens rows
 76     set list " we do what to show tabs, to ensure we get them 
 77               " out of my files
 78     set listchars=tab:>-,trail:- " show tabs and trailing 
 79     set matchtime=5 " how many tenths of a second to blink 
 80                      " matching brackets for
 81     set nohlsearch " do not highlight searched for phrases
 82     set nostartofline " leave my cursor where it was
 83     set novisualbell " don't blink
 84     set number " turn on line numbers
 85     set numberwidth=5 " We are good up to 99999 lines
 86     set report=0 " tell us when anything is changed via :...
 87     set ruler " Always show current positions along the bottom
 88     set scrolloff=10 " Keep 10 lines (top/bottom) for scope
 89     set shortmess=aOstT " shortens messages to avoid 
 90                          " 'press a key' prompt
 91     set showcmd " show the command being typed
 92     set showmatch " show matching brackets
 93     set sidescrolloff=10 " Keep 5 lines at the size
 94     set statusline=%F%m%r%h%w[%L][%{&ff}]%y[%p%%][%04l,%04v]
 95     "              | | | | |  |   |      |  |     |    |
 96     "              | | | | |  |   |      |  |     |    + current 
 97     "              | | | | |  |   |      |  |     |       column
 98     "              | | | | |  |   |      |  |     +-- current line
 99     "              | | | | |  |   |      |  +-- current % into file
100     "              | | | | |  |   |      +-- current syntax in 
101     "              | | | | |  |   |          square brackets
102     "              | | | | |  |   +-- current fileformat
103     "              | | | | |  +-- number of lines
104     "              | | | | +-- preview flag in square brackets
105     "              | | | +-- help flag in square brackets
106     "              | | +-- readonly flag in square brackets
107     "              | +-- rodified flag in square brackets
108     "              +-- full path to file in the buffer
109 " }
110 
111 " Text Formatting/Layout {
112     set completeopt= " don't use a pop up menu for completions
113     set expandtab " no real tabs please!
114     set formatoptions=rq " Automatically insert comment leader on return, 
115                           " and let gq format comments
116     set ignorecase " case insensitive by default
117     set infercase " case inferred by default
118     set nowrap " do not wrap line
119     set shiftround " when at 3 spaces, and I hit > ... go to 4, not 5
120     set smartcase " if there are caps, go case-sensitive
121     set shiftwidth=4 " auto-indent amount when using cindent, 
122                       " >>, << and stuff like that
123     set softtabstop=4 " when hitting tab or backspace, how many spaces 
124                        "should a tab be (see expandtab)
125     set tabstop=8 " real tabs should be 8, and they will show with 
126                    " set list on
127 " }
128 
129 " Folding {
130     set foldenable " Turn on folding
131     set foldmarker={,} " Fold C style code (only use this as default 
132                         " if you use a high foldlevel)
133     set foldmethod=marker " Fold on the marker
134     set foldlevel=100 " Don't autofold anything (but I can still 
135                       " fold manually)
136     set foldopen=block,hor,mark,percent,quickfix,tag " what movements
137                                                       " open folds 
138     function SimpleFoldText() " {
139         return getline(v:foldstart).' '
140     endfunction " }
141     set foldtext=SimpleFoldText() " Custom fold text function 
142                                    " (cleaner than default)
143 " }
144 
145 " Plugin Settings {
146     let b:match_ignorecase = 1 " case is stupid
147     let perl_extended_vars=1 " highlight advanced perl vars 
148                               " inside strings
149 
150     " TagList Settings {
151         let Tlist_Auto_Open=0 " let the tag list open automagically
152         let Tlist_Compact_Format = 1 " show small menu
153         let Tlist_Ctags_Cmd = 'ctags' " location of ctags
154         let Tlist_Enable_Fold_Column = 0 " do show folding tree
155         let Tlist_Exist_OnlyWindow = 1 " if you are the last, kill 
156                                         " yourself
157         let Tlist_File_Fold_Auto_Close = 0 " fold closed other trees
158         let Tlist_Sort_Type = "name" " order by 
159         let Tlist_Use_Right_Window = 1 " split to the right side
160                                         " of the screen
161         let Tlist_WinWidth = 40 " 40 cols wide, so i can (almost always)
162                                  " read my functions
163         " Language Specifics {
164             " just functions and classes please
165             let tlist_aspjscript_settings = 'asp;f:function;c:class' 
166             " just functions and subs please
167             let tlist_aspvbs_settings = 'asp;f:function;s:sub' 
168             " don't show variables in freaking php
169             let tlist_php_settings = 'php;c:class;d:constant;f:function' 
170             " just functions and classes please
171             let tlist_vb_settings = 'asp;f:function;c:class' 
172         " }
173     " }
174 " }
175 
176 " Mappings {
177     " ROT13 - fun
178     map <F12> ggVGg?
179 
180     " space / shift-space scroll in normal mode
181     noremap <S-space> <C-b>
182     noremap <space> <C-f>
183 
184     " Make Arrow Keys Useful Again {
185         map <down> <ESC>:bn<RETURN>
186         map <left> <ESC>:NERDTreeToggle<RETURN>
187         map <right> <ESC>:Tlist<RETURN>
188         map <up> <ESC>:bp<RETURN>
189     " }
190 " }
191 
192 " Autocommands {
193     " Ruby {
194         " ruby standard 2 spaces, always
195         au BufRead,BufNewFile *.rb,*.rhtml set shiftwidth=2 
196         au BufRead,BufNewFile *.rb,*.rhtml set softtabstop=2 
197     " }
198     " Notes {
199         " I consider .notes files special, and handle them differently, I
200         " should probably put this in another file
201         au BufRead,BufNewFile *.notes set foldlevel=2
202         au BufRead,BufNewFile *.notes set foldmethod=indent
203         au BufRead,BufNewFile *.notes set foldtext=foldtext()
204         au BufRead,BufNewFile *.notes set listchars=tab:\ \ 
205         au BufRead,BufNewFile *.notes set noexpandtab
206         au BufRead,BufNewFile *.notes set shiftwidth=8
207         au BufRead,BufNewFile *.notes set softtabstop=8
208         au BufRead,BufNewFile *.notes set tabstop=8
209         au BufRead,BufNewFile *.notes set syntax=notes
210         au BufRead,BufNewFile *.notes set nocursorcolumn
211         au BufRead,BufNewFile *.notes set nocursorline
212         au BufRead,BufNewFile *.notes set guifont=Consolas:h12
213         au BufRead,BufNewFile *.notes set spell
214     " }
215     au BufNewFile,BufRead *.ahk setf ahk 
216 " }
217 
218 " GUI Settings {
219 if has("gui_running")
220     " Basics {
221         colorscheme metacosm " my color scheme (only works in GUI)
222         set columns=180 " perfect size for me
223         set guifont=Consolas:h10 " My favorite font
224         set guioptions=ce 
225         "              ||
226         "              |+-- use simple dialogs rather than pop-ups
227         "              +  use GUI tabs, not console style tabs
228         set lines=55 " perfect size for me
229         set mousehide " hide the mouse cursor when typing
230     " }
231 
232     " Font Switching Binds {
233         map <F8> <ESC>:set guifont=Consolas:h8<CR>
234         map <F9> <ESC>:set guifont=Consolas:h10<CR>
235         map <F10> <ESC>:set guifont=Consolas:h12<CR>
236         map <F11> <ESC>:set guifont=Consolas:h16<CR>
237         map <F12> <ESC>:set guifont=Consolas:h20<CR>
238     " }
239 endif
240 " }

其他参考网址:

http://www.vim.org/

http://vimcdoc.sourceforge.net/

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 要下载.vimrc文件,可以按照以下步骤操作: 1. 打开任意网页浏览器,进入搜索引擎网站,如Google或百度。 2. 在搜索框中输入“vim配置文件.vimrc下载”并点击搜索按钮。 3. 在搜索结果中,可以看到一些网站提供.vimrc文件的下载链接。点击其中一个可靠的链接。 4. 进入下载页面后,查看文件下载方式。通常,会提供一个“下载”按钮或者直接显示文件内容。 5. 如果有“下载”按钮,点击该按钮进行下载。如果文件内容直接显示在页面上,复制整个内容。 6. 找到想要保存.vimrc文件的位置,例如桌面或者指定文件夹。 7. 在浏览器上右击鼠标,并选择“保存链接为”或“保存页面为”。然后,选择保存到指定位置。 8. 在保存对话框中,指定保存文件的名称为“.vimrc”,确保文件名前面有一个点来确保其为隐藏文件。 9. 点击保存按钮,等待文件下载完成。 10. 成功保存文件后,即可在指定位置找到下载的.vimrc文件。 注意事项:在下载文件时,始终选择可信任的来源,以确保文件的安全性。另外,.vimrc文件通常是用于Vim编辑器的配置文件,如果使用其他编辑器,可能会需要相应的配置文件。 ### 回答2: 要下载vim配置文件.vimrc,你可以按照以下步骤进行操作: 1. 打开你的终端或命令行界面。 2. 使用curl命令下载.vimrc文件。在终端中输入以下命令并按下回车键: curl -o ~/.vimrc https://raw.githubusercontent.com/username/repo/master/.vimrc 这个命令会从GitHub的仓库中下载.vimrc文件并保存到你的主目录下。 替换"username/repo"部分为你所使用的GitHub用户名和仓库名称。 3. 下载完成后,你可以使用vim编辑器打开.vimrc文件来查看和修改配置。 在终端中输入以下命令打开.vimrc文件: vim ~/.vimrc 这将使用vim编辑器打开你的.vimrc文件,现在你可以根据自己的需求进行编辑和配置。 如果你对vim配置不熟悉,你可以搜索一些vim配置示例或教程,以帮助你进行必要的修改。 希望这个回答对你有所帮助! ### 回答3: vim配置文件.vimrc是用来定制Vim编辑器的设置和插件的配置文件。想要下载.vimrc文件,请按照以下步骤进行操作。 1. 打开你的命令行终端。 2. 在终端中输入以下命令,下载.vimrc文件: `wget https://raw.githubusercontent.com/username/repo/master/.vimrc` 这里的`https://raw.githubusercontent.com/username/repo/master/.vimrc`是.vimrc文件所在的URL。你需要将其替换为你想要下载的.vimrc文件的真实URL。 3. 下载完成后,.vimrc文件会保存在当前目录下。 4. 如果需要将.vimrc文件移动到其他目录,请使用以下命令: `mv .vimrc /desired/path` 这里的`/desired/path`是你想要移动到的目标路径。你需要将其替换为你想要保存.vimrc文件的目标路径。 通过上述步骤,你可以下载到你想要的.vimrc配置文件,并可以根据自己的需要进行自定义及编辑。记得根据实际情况修改命令中的URL和目标路径以适应你的需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值