Ubuntu下vim的设置

Linux下由于安装Vim后,Vim的默认设置不是很好用,应该我们可以按照自己的要求来对其进行配置文件的设置,以方便我们的使用。

首先,找到vim的配置文件,一般在/etc/vim下,这个是公共的vim配置文件,为了不破坏公共的配置文件,我们可以复制一份到我们自己用户的目录下,建立私有的配置文件。命令为:“.vimrc”
命令如下:cd /etc/vim
cp vimrc /home/administrator/.vimrc


然后,我们就可以对自己用户下的.vimrc进行设置了。


" All system-wide defaults are set in $VIMRUNTIME/debian.vim (usually just
" /usr/share/vim/vimcurrent/debian.vim) and sourced by the call to :runtime
" you can find below.  If you wish to change any of those settings, you should
" do it in this file (/etc/vim/vimrc), since debian.vim will be overwritten
" everytime an upgrade of the vim packages is performed.  It is recommended to
" make changes after sourcing debian.vim since it alters the value of the
" 'compatible' option.

" This line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in Debian.
runtime! debian.vim

" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'.  Setting 'compatible' changes numerous
" options, so any other options should be set AFTER setting 'compatible'.
"set compatible

" Vim5 and later versions support syntax highlighting. Uncommenting the
" following enables syntax highlighting by default.
if has("syntax")
  syntax on
endif

" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
"set background=dark

" Uncomment the following to have Vim jump to the last position when
" reopening a file
"if has("autocmd")
"  au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
"endif

" Uncomment the following to have Vim load indentation rules and plugins
" according to the detected filetype.
"if has("autocmd")
"  filetype plugin indent on
"endif

" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
"set showcmd		" Show (partial) command in status line.
"set showmatch		" Show matching brackets.
"set ignorecase		" Do case insensitive matching
"set smartcase		" Do smart case matching
"set incsearch		" Incremental search
"set autowrite		" Automatically save before commands like :next and :make
"set hidden             " Hide buffers when they are abandoned
"set mouse=a		" Enable mouse usage (all modes)

" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
  source /etc/vim/vimrc.local
endif

从上可以看出vim的默认设置非常的简单,因此,我们根据自己的需要来添加所需要的设置,以下是我需要用的配置信息,如果有其他的需要可以上网搜一下

1) 添加以下语句来使得语法高亮显示:
syntax on
2)设置Windows风格的C/C++自动缩进(添加以下set语句到vimrc中)
设置(软)制表符宽度为4:
set tabstop=4
set softtabstop=4


3)设置缩进的空格数为4
set shiftwidth=4

4)设置自动缩进:即每行的缩进值与上一行相等;使用 noautoindent 取消设置:
set autoindent

5)设置使用 C/C++ 语言的自动缩进方式:
set cindent

6)如果想在左侧显示文本的行号,可以用以下语句:
set nu

7)设置高亮搜索
set hlsearch

你可能感兴趣的:(开发工具,runtime,c/c++)