Ubuntu18.04安裝及配置vim


Ubuntu18.04安裝及配置vim

 

本文鏈接:https://blog.csdn.net/qq_15725099/article/details/88536748

1.在虛擬機安裝Ubuntu18.04;

2.安裝vim命令行中輸入: sudo apt-get install vim

3.查看安裝是否成功輸入:vim -v

2.配置vim

(1.)在主目錄下新建.vimrc,並添加一下內容

  1 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  2 " 顯示相關  
  3 " """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  4  "set shortmess=atI   " 啟動的時候不顯示那個援助烏干達兒童的提示  
  5  "winpos 5 5          " 設定窗口位置  
  6  "set lines=40 columns=155    " 設定窗口大小  
  7  "set nu              " 顯示行號  
  8  set go=             " 不要圖形按鈕  
  9  "color asmanian2     " 設置背景主題  
 10  "set guifont=Courier_New:h10:cANSI   " 設置字體  
 11  "syntax on           " 語法高亮  
 12  autocmd InsertLeave * se nocul  " 用淺色高亮當前行  
 13  autocmd InsertEnter * se cul    " 用淺色高亮當前行  
 14  "set ruler           " 顯示標尺  
 15  set showcmd         " 輸入的命令顯示出來,看的清楚些  
 16  "set cmdheight=1     " 命令行(在狀態行下)的高度,設置為1  
 17  "set whichwrap+=<,>,h,l   " 允許backspace和光標鍵跨越行邊界(不建議)  
 18  "set scrolloff=3     " 光標移動到buffer的頂部和底部時保持3行距離  
 19  set novisualbell    " 不要閃爍(不明白)  
 20  set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}   "狀態行顯示的內容  
 21  set laststatus=1    " 啟動顯示狀態行(1),總是顯示狀態行(2)  
 22  " set foldenable      " 允許折疊  
 23  set foldmethod=manual   " 手動折疊  
 24  "set background=dark "背景使用黑色 
 25  set nocompatible  "去掉討厭的有關vi一致性模式,避免以前版本的一些bug和局限  
 26  " 顯示中文幫助
 27  if version >= 603
 28  set helplang=cn
 29  set encoding=utf-8
 30  endif
 31          " 設置配色方案
 32          "colorscheme murphy
 33          "字體 
 34          "if (has("gui_running")) 
 35          "   set guifont=Bitstream\ Vera\ Sans\ Mono\ 10 
 36          "endif "
 37 set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
 38 set termencoding=utf-8
 39 set encoding=utf-8
 40 set fileencodings=ucs-bom,utf-8,cp936
 41 set fileencoding=utf-8
 42 autocmd BufReadPost *
 43     \ if line("'\"") > 0 && line("'\"") <= line("$") |
 44     \     exe "normal g'\"" |
 45     \ endif
 46  
 47 " SHORTCUT SETTINGS: {{{1
 48 " Set mapleader
 49 let mapleader=","
 50 " Space to command mode.
 51 nnoremap <space> :
 52 vnoremap <space> :
 53 " Switching between buffers.
 54 nnoremap <C-h> <C-W>h
 55 nnoremap <C-j> <C-W>j
 56 nnoremap <C-k> <C-W>k
 57 nnoremap <C-l> <C-W>l
 58 inoremap <C-h> <Esc><C-W>h
 59 inoremap <C-j> <Esc><C-W>j
 60 inoremap <C-k> <Esc><C-W>k
 61 inoremap <C-l> <Esc><C-W>l
 62 " "cd" to change to open directory.
 63 let OpenDir=system("pwd")
 64 nmap <silent> <leader>cd :exe 'cd ' . OpenDir<cr>:pwd<cr>
 65 " PLUGIN SETTINGS: {{{1
 66 " taglist.vim
 67 let g:Tlist_Auto_Update=1
 68 let g:Tlist_Process_File_Always=1
 69 let g:Tlist_Exit_OnlyWindow=1
 70 let g:Tlist_Show_One_File=1
 71 let g:Tlist_WinWidth=25
 72 let g:Tlist_Enable_Fold_Column=0
 73 let g:Tlist_Auto_Highlight_Tag=1
 74 " NERDTree.vim
 75 let g:NERDTreeWinPos="right"
 76 let g:NERDTreeWinSize=25
 77 let g:NERDTreeShowLineNumbers=1
 78 let g:NERDTreeQuitOnOpen=1
 79 " cscope.vim
 80 if has("cscope")
 81     set csto=1
 82     set cst
 83     set nocsverb
 84     if filereadable("cscope.out")
 85         cs add cscope.out
 86     endif
 87     set csverb
 88 endif
 89 " OmniCppComplete.vim
 90 let g:OmniCpp_DefaultNamespaces=["std"]
 91 let g:OmniCpp_MayCompleteScope=1
 92 let g:OmniCpp_SelectFirstItem=2
 93 " VimGDB.vim
 94 if has("gdb")
 95     set asm=0
 96     let g:vimgdb_debug_file=""
 97     run macros/gdb_mappings.vim
 98 endif
 99 " LookupFile setting
100 let g:LookupFile_TagExpr='"./tags.filename"'
101 let g:LookupFile_MinPatLength=2
102 let g:LookupFile_PreserveLastPattern=0
103 let g:LookupFile_PreservePatternHistory=1
104 let g:LookupFile_AlwaysAcceptFirst=1
105 let g:LookupFile_AllowNewFiles=0
106 " Man.vim
107 source $VIMRUNTIME/ftplugin/man.vim
108 " snipMate
109 let g:snips_author="Du Jianfeng"
110 let g:snips_email="cmdxiaoha@163.com"
111 let g:snips_copyright="SicMicro, Inc"
112 " plugin shortcuts
113 function! RunShell(Msg, Shell)
114     echo a:Msg . '...'
115     call system(a:Shell)
116     echon 'done'
117 endfunction
118 nmap  <F2> :TlistToggle<cr>
119 nmap  <F3> :NERDTreeToggle<cr>
120 nmap  <F4> :MRU<cr>
121 nmap  <F5> <Plug>LookupFile<cr>
122 nmap  <F6> :vimgrep /<C-R>=expand("<cword>")<cr>/ **/*.c **/*.h<cr><C-o>:cw<cr>
123 nmap  <F9> :call RunShell("Generate tags", "ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .")<cr>
124 nmap <F10> :call HLUDSync()<cr>
125 nmap <F11> :call RunShell("Generate filename tags", "~/.vim/shell/genfiletags.sh")<cr>
126 nmap <F12> :call RunShell("Generate cscope", "cscope -Rb")<cr>:cs add cscope.out<cr>
127 nmap <leader>sa :cs add cscope.out<cr>
128 nmap <leader>ss :cs find s <C-R>=expand("<cword>")<cr><cr>
129 nmap <leader>sg :cs find g <C-R>=expand("<cword>")<cr><cr>
130 nmap <leader>sc :cs find c <C-R>=expand("<cword>")<cr><cr>
131 nmap <leader>st :cs find t <C-R>=expand("<cword>")<cr><cr>
132 nmap <leader>se :cs find e <C-R>=expand("<cword>")<cr><cr>
133 nmap <leader>sf :cs find f <C-R>=expand("<cfile>")<cr><cr>
134 nmap <leader>si :cs find i <C-R>=expand("<cfile>")<cr><cr>
135 nmap <leader>sd :cs find d <C-R>=expand("<cword>")<cr><cr>
136 nmap <leader>zz <C-w>o
137 nmap <leader>gs :GetScripts<cr>
138 autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java exec ":call SetTitle()"
139 func SetTitle()
140     if &filetype == 'sh'
141         call setline(1,"\#########################################################################")
142         call append(line("."), "\# File Name: ".expand("%"))
143         call append(line(".")+1, "\# Author: 舒承揚")
144         call append(line(".")+2, "\# mail: 1083790169@qq.com")
145         call append(line(".")+3, "\# Created Time:".strftime("%c"))
146         call append(line(".")+4,"\#########################################################################")
147         call append(line(".")+5, "\#!/bin/bash")
148         call append(line(".")+6, "") 
149     else
150         call setline(1, "/*************************************************************************")
151         call append(line("."), "    > File Name: ".expand("%"))
152         call append(line(".")+1, "    > Author: 舒承揚")
153         call append(line(".")+2, "    > Mail: 1083790169@qq.com ")
154         call append(line(".")+3, "    > Created Time: ".strftime("%c"))
155         call append(line(".")+4," ************************************************************************/")
156         call append(line(".")+5, "") 
157     endif
158     if &filetype == 'cpp'
159         call append(line(".")+6, "#include <iostream>")
160  
161         call append(line(".")+7, "")
162         call append(line(".")+8, "using namespace std;")
163         call append(line(".")+9, "")
164         call append(line(".")+10, "int main(void){")
165         call append(line(".")+11, "")
166         call append(line(".")+12, "    return 0;")
167         call append(line(".")+13, "}")
168     endif
169     if &filetype == 'c'
170         call append(line(".")+6, "#include <stdio.h>")
171         call append(line(".")+7, "")
172         call append(line(".")+8, "int main(void){")
173         call append(line(".")+9, "")
174         call append(line(".")+10,"  return 0;")
175         call append(line(".")+11, "}")
176     endif
177     autocmd BufNewFile *normal G
178 endfunc
179 inoremap ( ()<Esc>i>
View Code

(2.)執行sudo vi /etc/vim/vimrc,在文件尾添加如下內容

 1 set ts=4
 2 set expandtab
 3 set autoindent
 4 set nu
 5 set nocompatible 
 6 set number
 7 set autoindent
 8 set smartindent
 9 set showmatch
10 set ruler
11 set incsearch
12 set tabstop=4
13 set shiftwidth=4
14 set softtabstop=4
15 set cindent
16 set nobackup
17 set clipboard+=unnamed
18 "inoremap [ []<Esc>i
19 "inoremap { {}<Esc>i
20 "inoremap ( ()<Esc>i
21 "inoremap ' ''<Esc>i
22 "inoremap " ""<Esc>i
23 
24 ————————————————
25 版權聲明:本文為CSDN博主「自由的雨」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
26 原文鏈接:https://blog.csdn.net/qq_15725099/article/details/88536748
View Code

(3.)重啟終端或電腦

 




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM