ubuntu下vim語法著色和縮排問題的解決
2011-03-07 09:26
轉載自 javatown
最終編輯 javatown
版本號:2008.07.30
關鍵字:linux ubuntu vim vi 語法著色 語法高亮 縮進 縮排
本文的主要目的是討論記錄ubuntu下vim語法著色和縮排的方法
1。前提
安裝vim
sudo apt-get install vim-full
之后,在/etc/vim下會發(fā)現vimrc這個文件這個是公共配置文件,修改它一般會對所有的ubuntu用戶產生效果。
2。語法著色
要讓語法高亮顯示,可以用如下辦法:
方法一:
去掉/etc/vim下vimrc中syntax on一句前面的注釋符號來開啟
方法二:
如果方法一失效可以編輯/etc下的profile文件,添加
export TERM=xterm-color
方法三:
拷貝語法著色示例文件
cp /usr/share/vim/vimcurrent/vimrc_example.vim ~/.vimrc
方法四:
在vim中輸入:syntax on來開啟語法著色
方法五:
直接編輯~/.vimrc文件,如果沒有就自己建立一個
然后把下面內容加入
set autoindent
set cindent
set modeline
set ruler
set showcmd
set showfulltag
set showmode
set smartcase
set smartindent
set imcmdline
set previewwindow
set hlsearch
syntax on
一些配色方案,來自互聯網,直接添加在vimrc文件末尾即可:
colorscheme elflord
"colorscheme darkblue
"colorscheme evening
"colorscheme murphy
"colorscheme torte
"colorscheme desert
3。縮進
以下內容來自互聯網
1)設置(軟)制表符寬度為4:
set tabstop=4
set softtabstop=4
2)設置縮進的空格數為4
set shiftwidth=4
3)設置自動縮進:即每行的縮進值與上一行相等;使用 noautoindent 取消設置:
set autoindent
4)設置使用 C/C++ 語言的自動縮進方式:
set cindent
5)設置C/C++語言的具體縮進方式:
set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s
6)如果想在左側顯示文本的行號,可以用以下語句:
set nu
7)最后,如果沒有下列語句,就加上吧:
if &term=="xterm"
set t_Co=8
set t_Sb=^[[4%dm
set t_Sf=^[[3%dm
endif