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