Ubuntu18.04之vim安装及配置
⼀、安装vim
命令⾏中输⼊:sudo apt-get install vim
(ps:它会显⽰让你输⼊密码,不过你输⼊的密码不会回显)
查看安装是否成功输⼊: vim  -v
⼆、配置vim
第⼀步:在终端创建.vimrc⽂件命令为:  $vi ~/.vimrc
(ps:表⽰⼿动设置⼀个配置⽂件 :vimrc  , 这⾥把.vimrc⽂件创建在当前⽤户的根⽬录下)
第⼆步:在.vimrc⽂件中添加配置内容:
set shortmess=atI  " 启动的时候不显⽰那个援助乌⼲达⼉童的提⽰
winpos 55" 设定窗⼝位置
set lines=40 columns=155" 设定窗⼝⼤⼩
set nu              " 显⽰⾏号
set go=            " 不要图形按钮
syntax on          " 语法⾼亮
autocmd InsertLeave * se nocul  " ⽤浅⾊⾼亮当前⾏
autocmd InsertEnter * se cul    " ⽤浅⾊⾼亮当前⾏
set showcmd        " 输⼊的命令显⽰出来,看的清楚些
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 foldmethod=manual  " ⼿动折叠
set background=dark "背景使⽤⿊⾊
set nocompatible  "去掉讨厌的有关vi⼀致性模式,避免以前版本的⼀些bug和局限
" 显⽰中⽂帮助
if version >= 603
set helplang=cn
set encoding=utf-8
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
let mapleader=","
nnoremap <space> :
vnoremap <space> :
nnoremap <C-h> <C-W>h
nnoremap <C-j> <C-W>j
nnoremap <C-k> <C-W>k
nnoremap <C-l> <C-W>l
inoremap <C-h> <Esc><C-W>h
inoremap <C-j> <Esc><C-W>j
inoremap <C-k> <Esc><C-W>k
inoremap <C-l> <Esc><C-W>l
let OpenDir=system("pwd")
nmap <silent> <leader>cd :exe 'cd ' . OpenDir<cr>:pwd<cr>
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
let g:NERDTreeWinPos="right"
let g:NERDTreeWinSize=25
let g:NERDTreeShowLineNumbers=1
let g:NERDTreeQuitOnOpen=1
if has("cscope")
set csto=1
set cst
set nocsverb
if filereadable("cscope.out")
cs add cscope.out
endif
set csverb
endif
let g:OmniCpp_DefaultNamespaces=["std"]
let g:OmniCpp_MayCompleteScope=1
let g:OmniCpp_SelectFirstItem=2
if has("gdb")
set asm=0
let g:vimgdb_debug_file=""
run macros/gdb_mappings.vim
endif
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
source $VIMRUNTIME/ftplugin/man.vim
let g:snips_author="Du Jianfeng"
let g:snips_email="cmdxiaoha@163"
let g:snips_copyright="SicMicro, Inc"
function! RunShell(Msg, Shell)
echo a:Msg . '...'
call system(a:Shell)
echon 'done'
endfunction
nmap  <F2> :TlistToggle<cr>
nmap  <F3> :NERDTreeToggle<cr>
nmap  <F4> :MRU<cr>
nmap  <F5> <Plug>LookupFile<cr>
nmap  <F6> :vimgrep /<C-R>=expand("<cword>")<cr>/ **/*.c **/*.h<cr><C-o>:cw<cr>
nmap  <F9> :call RunShell("Generate tags", "ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .")<cr>
nmap <F10> :call HLUDSync()<cr>
nmap <F11> :call RunShell("Generate filename tags", "~/.vim/shell/genfiletags.sh")<cr>
nmap <F12> :call RunShell("Generate cscope", "cscope -Rb")<cr>:cs add cscope.out<cr>
nmap <leader>sa :cs add cscope.out<cr>
nmap <leader>ss :cs find s <C-R>=expand("<cword>")<cr><cr>
nmap <leader>sg :cs find g <C-R>=expand("<cword>")<cr><cr>
nmap <leader>sc :cs find c <C-R>=expand("<cword>")<cr><cr>
nmap <leader>st :cs find t <C-R>=expand("<cword>")<cr><cr>
nmap <leader>se :cs find e <C-R>=expand("<cword>")<cr><cr>
nmap <leader>sf :cs find f <C-R>=expand("<cfile>")<cr><cr>
nmap <leader>si :cs find i <C-R>=expand("<cfile>")<cr><cr>
nmap <leader>sd :cs find d <C-R>=expand("<cword>")<cr><cr>
nmap <leader>zz <C-w>o
nmap <leader>gs :GetScripts<cr>
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: jianqiao")
call append(line(".")+2, "\# mail: 123456789@qq")
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: jianqiao")
call append(line(".")+2, "    > Mail: 123456789@qq ")
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 <iostream>")
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 <stdio.h>")
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 ( ()<Esc>i>
如何在vim中运行命令
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
三、重启终端创建、编写、编译、运⾏C、C++程序
(ps:以创建hello.cpp和hello.c为例)
1、在终端使⽤命令vihello.c(vi hello.cpp) 创建hello.c / hello.cpp⽂件,并进⼊vim界⾯;
2、键⼊i,进⼊输⼊模式
3、编写hello.c / hello.cpp程序
4、先按Esc键退出输⼊模式;然后按 : 键,进⼊命令模式;输⼊wq表⽰保存并退出。
5、编译hello.c / hello.cpp
5.1、对于C程序:在终端使⽤命令 $gcc hello.c
5.2、对于C++程序:⽤$g++ hello.cpp可编译,编译后均⽣成a.out的可执⾏⽂件
6、在终端使⽤命令 $ ./a.out  表⽰运⾏程序
7、在终端显⽰“helloworld!”即成功
⼩坑点:
修改ubuntu18.04界⾯⼤⼩:
1、使⽤CTRL+alt+t打开终端
2、使⽤命令xrandr  查看相应的屏幕分辨率的相关参数
3、使⽤命令 xrandr -s 相应分辨率(如1916x889)即可改为相应的显⽰
参考:
Processing math: 100%

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。

发表评论