Ubuntu中修改vim設定檔,更方便於c程式設計

來源:互聯網
上載者:User

1、使用cd /  轉到檔案系統中;


2、cd/etc/vim 切換到vim目錄內;


3、修改檔案許可權 :  sudo chmod  777 vimrc ,會提示你輸入密碼,輸入密碼即可;


4、vim vimrc   開啟vim檔案,內容基本如下:


" 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


5、插入設定檔,設定檔如下:


""""""""""""""""""""""""""""""""""""""
" 文法著色與高亮設定
""""""""""""""""""""""""""""""""""""""

"開啟文法高亮
syntax enable
syntax on

"配色
"colo ruki
"colors ruki
"由於目前沒有找到ruki外掛程式,暫時取消該功能,找到該外掛程式後,再啟用該功能

"設定高亮搜尋
:set hlsearch

""""""""""""""""""""""""""""""""""""""
" 檔案設定
""""""""""""""""""""""""""""""""""""""

set encoding=utf-8
set fileencoding=chinese
set fileencodings=ucs-bom,utf-8,chinese
set ambiwidth=double

"檢測檔案的類型
filetype on

"預設無備份
:set nobackup
:set nowritebackup

""""""""""""""""""""""""""""""""""""""
" 滑鼠設定
""""""""""""""""""""""""""""""""""""""

"滑鼠支援
if has('mouse')
:set mouse=a
endif

"使滑鼠用起來象微軟 Windows,似乎正好解決 連續多行縮排問題、退格問題
:behave mswin

""""""""""""""""""""""""""""""""""""""
" 編輯器設定
""""""""""""""""""""""""""""""""""""""

"顯示行號
set number

"Tab 寬度
:set ts=4

"自動縮排
:set sw=4

"C/C++ 風格的自動縮排
:set cin
"設定 C/C++ 風格自動縮排的選項
:set cino=:0g0t0(sus

"開啟普通檔案類型的自動縮排
:set ai

"在編輯過程中,在右下角顯示光線標位置的狀態行
:set ruler

"顯示匹配括弧
:set showmatch

"在insert模式下能用刪除鍵進行刪除
:set backspace=indent,eol,start

"程式碼摺疊功能, 命令 za
:set foldmethod=syntax
:set foldlevel=100  "啟動vim時不要自動摺疊代碼

"設定字型
:set guifont=courier/ 9

"當按右鍵視窗的時候, 彈出捷徑功能表
:set mousemodel=popup

"自動換行
if (has("gui_running")) "圖形介面下的設定

"指定不折行。如果一行太長,超過螢幕寬度,則向右邊延伸到螢幕外面
:set nowrap
"添加水平捲軸。如果你指定了不折行,那為視窗添加一個水平捲軸就非常有必要了
:set guioptions+=b

else "字元介面下的設定
   set wrap
endif

""""""""""""""""""""""""""""""""""""""
" 快速鍵設定
""""""""""""""""""""""""""""""""""""""
"<F1> 功能表列與工具列隱藏與顯示動態切換
set guioptions-=m
set guioptions-=T
map <silent> <F1> :if &guioptions =~# 'T' <Bar>
        /set guioptions-=T <Bar>
        /set guioptions-=m <bar>
    /else <Bar>
        /set guioptions+=T <Bar>
        /set guioptions+=m <Bar>
    /endif<CR>

"<F2>code_complete.vim外掛程式:函數自動完成
if !exists("g:completekey")
    let g:completekey = "<F2>"   "hotkey
endif

"<F3><F4>大小寫轉換
map <F3> gu
map <F4> gU

"目前的目錄產生tags文法檔案,用於自動完成,函數提示:code_complete.vim OmniCppComplete.vim ...
"map <F5> :!ctags -R --c-kinds=+p --fields=+S . <CR>
map <F5> :!ctags -R --c-kinds=+p --c++-kinds=+p --fields=+iaS --extra=+q . <CR>

"函數和變數列表
map <F6> :TlistToggle<CR>

"檔案瀏覽器
map <F7> :WMToggle<CR>
let g:winManagerWindowLayout = "FileExplorer"

"檔案樹狀列表
map <F8> :NERDTree<CR>

"映射複製、粘貼、剪貼ctrl+c ctrl+v ctrl+x
:map <C-V> "+pa<Esc>
:map! <C-V> <Esc>"+pa
:map <C-C> "+y
:map <C-X> "+x

" 映射全選 ctrl+a
:map <C-A> ggVG
:map! <C-A> <Esc>ggVG

" 多行縮排
:map <Tab> >
:map <S-Tab> <

""""""""""""""""""""""""""""""""""""""
" 外掛程式設定
""""""""""""""""""""""""""""""""""""""

"開啟OmniCppComplete.vim
set nocp
filetype plugin on

"2Html外掛程式,啟用XHtml css
:let html_number_lines=1
:let html_use_css=1
:let use_xhtml=1

"fencview.vim 外掛程式設定
let g:fencview_autodetect = 1  "開啟檔案時自動識別編碼
let g:fencview_checklines = 10 "檢查前後10行來判斷編碼

"autocomplpop.vim & supertab.vim 外掛程式設定
let g:AutoComplPop_IgnoreCaseOption=1
set ignorecase

""""""""""""""""""""""""""""""""""""""
" 其他設定
""""""""""""""""""""""""""""""""""""""

"去掉討厭的有關vi一致性模式,避免以前版本的一些bug和局限
:set nocompatible


其插入位置在倒數第5行,為了和以前內容區別,插入內容前後多打些空格


6、插入後的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)


""""""""""""""""""""""""""""""""""""""


" 文法著色與高亮設定
""""""""""""""""""""""""""""""""""""""

"開啟文法高亮
syntax enable
syntax on

"配色
"colo ruki
"colors ruki
"由於目前沒有找到ruki外掛程式,暫時取消該功能,找到該外掛程式後,再啟用該功能

"設定高亮搜尋
:set hlsearch

""""""""""""""""""""""""""""""""""""""
" 檔案設定
""""""""""""""""""""""""""""""""""""""

set encoding=utf-8
set fileencoding=chinese
set fileencodings=ucs-bom,utf-8,chinese
set ambiwidth=double

"檢測檔案的類型
filetype on

"預設無備份
:set nobackup
:set nowritebackup

""""""""""""""""""""""""""""""""""""""
" 滑鼠設定
""""""""""""""""""""""""""""""""""""""

"滑鼠支援
if has('mouse')
:set mouse=a
endif

"使滑鼠用起來象微軟 Windows,似乎正好解決 連續多行縮排問題、退格問題
:behave mswin

""""""""""""""""""""""""""""""""""""""
" 編輯器設定
""""""""""""""""""""""""""""""""""""""

"顯示行號
set number

"Tab 寬度
:set ts=4

"自動縮排
:set sw=4

"C/C++ 風格的自動縮排
:set cin
"設定 C/C++ 風格自動縮排的選項
:set cino=:0g0t0(sus

"開啟普通檔案類型的自動縮排
:set ai

"在編輯過程中,在右下角顯示光線標位置的狀態行
:set ruler

"顯示匹配括弧
:set showmatch

"在insert模式下能用刪除鍵進行刪除
:set backspace=indent,eol,start

"程式碼摺疊功能, 命令 za
:set foldmethod=syntax
:set foldlevel=100  "啟動vim時不要自動摺疊代碼

"設定字型
:set guifont=courier/ 9

"當按右鍵視窗的時候, 彈出捷徑功能表
:set mousemodel=popup

"自動換行
if (has("gui_running")) "圖形介面下的設定

"指定不折行。如果一行太長,超過螢幕寬度,則向右邊延伸到螢幕外面
:set nowrap
"添加水平捲軸。如果你指定了不折行,那為視窗添加一個水平捲軸就非常有必要了
:set guioptions+=b

else "字元介面下的設定
   set wrap
endif

""""""""""""""""""""""""""""""""""""""
" 快速鍵設定
""""""""""""""""""""""""""""""""""""""
"<F1> 功能表列與工具列隱藏與顯示動態切換
set guioptions-=m
set guioptions-=T
map <silent> <F1> :if &guioptions =~# 'T' <Bar>
        /set guioptions-=T <Bar>
        /set guioptions-=m <bar>
    /else <Bar>
        /set guioptions+=T <Bar>
        /set guioptions+=m <Bar>
    /endif<CR>

"<F2>code_complete.vim外掛程式:函數自動完成
if !exists("g:completekey")
    let g:completekey = "<F2>"   "hotkey
endif

"<F3><F4>大小寫轉換
map <F3> gu
map <F4> gU

"目前的目錄產生tags文法檔案,用於自動完成,函數提示:code_complete.vim OmniCppComplete.vim ...
"map <F5> :!ctags -R --c-kinds=+p --fields=+S . <CR>
map <F5> :!ctags -R --c-kinds=+p --c++-kinds=+p --fields=+iaS --extra=+q . <CR>

"函數和變數列表
map <F6> :TlistToggle<CR>

"檔案瀏覽器
map <F7> :WMToggle<CR>
let g:winManagerWindowLayout = "FileExplorer"

"檔案樹狀列表
map <F8> :NERDTree<CR>

"映射複製、粘貼、剪貼ctrl+c ctrl+v ctrl+x
:map <C-V> "+pa<Esc>
:map! <C-V> <Esc>"+pa
:map <C-C> "+y
:map <C-X> "+x

" 映射全選 ctrl+a
:map <C-A> ggVG
:map! <C-A> <Esc>ggVG

" 多行縮排
:map <Tab> >
:map <S-Tab> <

""""""""""""""""""""""""""""""""""""""
" 外掛程式設定
""""""""""""""""""""""""""""""""""""""

"開啟OmniCppComplete.vim
set nocp
filetype plugin on

"2Html外掛程式,啟用XHtml css
:let html_number_lines=1
:let html_use_css=1
:let use_xhtml=1

"fencview.vim 外掛程式設定
let g:fencview_autodetect = 1  "開啟檔案時自動識別編碼
let g:fencview_checklines = 10 "檢查前後10行來判斷編碼

"autocomplpop.vim & supertab.vim 外掛程式設定
let g:AutoComplPop_IgnoreCaseOption=1
set ignorecase

""""""""""""""""""""""""""""""""""""""
" 其他設定
""""""""""""""""""""""""""""""""""""""

"去掉討厭的有關vi一致性模式,避免以前版本的一些bug和局限

:set nocompatible

" Source a global configuration file if available

if filereadable("/etc/vim/vimrc.local")
  source /etc/vim/vimrc.local
endif

7、儲存。儲存方法:按ESC鍵後,輸入:wq,斷行符號,即可。



8、至此,設定檔修改成功。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.