新版教程迁移至:https://www.10sxj.com/?id=3对CentOS也适用
1.在虚拟机安装Ubuntu18.04;
2.安装vim命令行中输入: sudo apt-get install vim
3.查看安装是否成功输入:vim -v
2.配置vim
(1.)在主目录下新建.vimrc,并添加一下内容
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 显示相关
" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"set shortmess=atI " 启动的时候不显示那个援助乌干达儿童的提示
"winpos 5 5 " 设定窗口位置
"set lines=40 columns=155 " 设定窗口大小
"set nu " 显示行号
set go= " 不要图形按钮
"color asmanian2 " 设置背景主题
"set guifont=Courier_New:h10:cANSI " 设置字体
"syntax on " 语法高亮
autocmd InsertLeave * se nocul " 用浅色高亮当前行
autocmd InsertEnter * se cul " 用浅色高亮当前行
"set ruler " 显示标尺
set showcmd " 输入的命令显示出来,看的清楚些
"set cmdheight=1 " 命令行(在状态行下)的高度,设置为1
"set whichwrap+=<,>,h,l " 允许backspace和光标键跨越行边界(不建议)
"set scrolloff=3 " 光标移动到buffer的顶部和底部时保持3行距离
set novisualbell " 不要闪烁(不明白)
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")} "状态行显示的内容
set laststatus=1 " 启动显示状态行(1),总是显示状态行(2)
" set foldenable " 允许折叠
set foldmethod=manual " 手动折叠
"set background=dark "背景使用黑色
set nocompatible "去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限
" 显示中文帮助
if version >= 603
set helplang=cn
set encoding=utf-8
endif
" 设置配色方案
"colorscheme murphy
"字体
"if (has("gui_running"))
" set guifont=Bitstream\ Vera\ Sans\ Mono\ 10
"endif "
set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936
set fileencoding=utf-8
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g'\"" |
\ endif
" SHORTCUT SETTINGS: {{{1
" Set mapleader
let mapleader=","
" Space to command mode.
nnoremap :
vnoremap :
" Switching between buffers.
nnoremap h
nnoremap j
nnoremap k
nnoremap l
inoremap h
inoremap j
inoremap k
inoremap l
" "cd" to change to open directory.
let OpenDir=system("pwd")
nmap cd :exe 'cd ' . OpenDir:pwd
" PLUGIN SETTINGS: {{{1
" taglist.vim
let g:Tlist_Auto_Update=1
let g:Tlist_Process_File_Always=1
let g:Tlist_Exit_OnlyWindow=1
let g:Tlist_Show_One_File=1
let g:Tlist_WinWidth=25
let g:Tlist_Enable_Fold_Column=0
let g:Tlist_Auto_Highlight_Tag=1
" NERDTree.vim
let g:NERDTreeWinPos="right"
let g:NERDTreeWinSize=25
let g:NERDTreeShowLineNumbers=1
let g:NERDTreeQuitOnOpen=1
" cscope.vim
if has("cscope")
set csto=1
set cst
set nocsverb
if filereadable("cscope.out")
cs add cscope.out
endif
set csverb
endif
" OmniCppComplete.vim
let g:OmniCpp_DefaultNamespaces=["std"]
let g:OmniCpp_MayCompleteScope=1
let g:OmniCpp_SelectFirstItem=2
" VimGDB.vim
if has("gdb")
set asm=0
let g:vimgdb_debug_file=""
run macros/gdb_mappings.vim
endif
" LookupFile setting
let g:LookupFile_TagExpr='"./tags.filename"'
let g:LookupFile_MinPatLength=2
let g:LookupFile_PreserveLastPattern=0
let g:LookupFile_PreservePatternHistory=1
let g:LookupFile_AlwaysAcceptFirst=1
let g:LookupFile_AllowNewFiles=0
" Man.vim
source $VIMRUNTIME/ftplugin/man.vim
" snipMate
let g:snips_author="Du Jianfeng"
let g:snips_email="[email protected]"
let g:snips_copyright="SicMicro, Inc"
" plugin shortcuts
function! RunShell(Msg, Shell)
echo a:Msg . '...'
call system(a:Shell)
echon 'done'
endfunction
nmap :TlistToggle
nmap :NERDTreeToggle
nmap :MRU
nmap LookupFile
nmap :vimgrep /=expand("")/ **/*.c **/*.h:cw
nmap :call RunShell("Generate tags", "ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .")
nmap :call HLUDSync()
nmap :call RunShell("Generate filename tags", "~/.vim/shell/genfiletags.sh")
nmap :call RunShell("Generate cscope", "cscope -Rb"):cs add cscope.out
nmap sa :cs add cscope.out
nmap ss :cs find s =expand("")
nmap sg :cs find g =expand("")
nmap sc :cs find c =expand("")
nmap st :cs find t =expand("")
nmap se :cs find e =expand("")
nmap sf :cs find f =expand("")
nmap si :cs find i =expand("")
nmap sd :cs find d =expand("")
nmap zz o
nmap gs :GetScripts
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java exec ":call SetTitle()"
func SetTitle()
if &filetype == 'sh'
call setline(1,"\#########################################################################")
call append(line("."), "\# File Name: ".expand("%"))
call append(line(".")+1, "\# Author: 舒承扬")
call append(line(".")+2, "\# mail: [email protected]")
call append(line(".")+3, "\# Created Time:".strftime("%c"))
call append(line(".")+4,"\#########################################################################")
call append(line(".")+5, "\#!/bin/bash")
call append(line(".")+6, "")
else
call setline(1, "/*************************************************************************")
call append(line("."), " > File Name: ".expand("%"))
call append(line(".")+1, " > Author: 舒承扬")
call append(line(".")+2, " > Mail: [email protected] ")
call append(line(".")+3, " > Created Time: ".strftime("%c"))
call append(line(".")+4," ************************************************************************/")
call append(line(".")+5, "")
endif
if &filetype == 'cpp'
call append(line(".")+6, "#include ")
call append(line(".")+7, "")
call append(line(".")+8, "using namespace std;")
call append(line(".")+9, "")
call append(line(".")+10, "int main(void){")
call append(line(".")+11, "")
call append(line(".")+12, " return 0;")
call append(line(".")+13, "}")
endif
if &filetype == 'c'
call append(line(".")+6, "#include ")
call append(line(".")+7, "")
call append(line(".")+8, "int main(void){")
call append(line(".")+9, "")
call append(line(".")+10," return 0;")
call append(line(".")+11, "}")
endif
autocmd BufNewFile *normal G
endfunc
inoremap ( ()i>
(2.)执行sudo vi /etc/vim/vimrc,在文件尾添加如下内容
set ts=4
set expandtab
set autoindent
set nu
set nocompatible
set number
set autoindent
set smartindent
set showmatch
set ruler
set incsearch
set tabstop=4
set shiftwidth=4
set softtabstop=4
set cindent
set nobackup
set clipboard+=unnamed
"inoremap [ []i
"inoremap { {}i
"inoremap ( ()i
"inoremap ' ''i
"inoremap " ""i
(3.)重启终端或电脑
3.检测是否成功,新建一个c文件或c++文件
如有疑问加群:676977101(新群)