Ubuntu 20.04 配置vim编辑器

您所在的位置:网站首页 ubuntu系统鼠标不能用 Ubuntu 20.04 配置vim编辑器

Ubuntu 20.04 配置vim编辑器

2023-06-14 03:03| 来源: 网络整理| 查看: 265

目录 vim的安装配置vim测试效果

vim的安装

命令:

sudo apt-get install vim-gtk -y

正常完成状态: 在这里插入图片描述

配置vim

vim的配置文件路径:/etc/vim/vimrc 我的配置文件如下,如果你需要,可以把红色部分改成你自己的一些信息,就是一个很好用的vim了。 具体操作:(这些命令都在终端执行,快捷键打开:ctl+alt+t)

// 把原本的文件备份 sudo cp /etc/vim/vimrc /etc/vim/vimrc.back //删除vimrc sudo rm /etc/vim/vimrc // 新建文件vimrc sudo vi /etc/vim/vimrc // 进入文件后按“a",表示插入,接下来把下面的内容复制到这个文件中,按”esc“,表示退出,再输入”wq“+”回车“就保存退出了。

下面是我的vimrc文件,功能基本完善,你可以直接完全复制到你的vimrc文件中。 如果你想定制你专属的vim编辑器,把文件内容中的Author字段改成你的昵称,Mail字段后面改成你的邮箱号,这样你就拥有你的专属vim编辑器了。 Author: username Mail: [email protected]

我的vimrc文件:

set sw=4 set ts=4 set et set smarttab set smartindent set lbr set fo+=mB set sm set selection=inclusive set wildmenu set mousemodel=popup set pastetoggle= au FileType php setlocal dict+=~/.vim/dict/php_funclist.dict au FileType css setlocal dict+=~/.vim/dict/css.dict au FileType c setlocal dict+=~/.vim/dict/c.dict au FileType cpp setlocal dict+=~/.vim/dict/cpp.dict au FileType scale setlocal dict+=~/.vim/dict/scale.dict au FileType javascript setlocal dict+=~/.vim/dict/javascript.dict au FileType html setlocal dict+=~/.vim/dict/javascript.dict au FileType html setlocal dict+=~/.vim/dict/css.dict " "syntastic相关 "execute pathogen#infect() let g:syntastic_python_checkers=['pylint'] let g:syntastic_php_checkers=['php', 'phpcs', 'phpmd'] "golang "Processing... % (ctrl+c to stop) let g:fencview_autodetect=0 set rtp+=$GOROOT/misc/vim """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 显示相关 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" syntax on set cul "高亮光标所在行 set cuc set shortmess=atI " 启动的时候不显示那个援助乌干达儿童的提示 set go= " 不要图形按钮 "color desert " 设置背景主题 color ron " 设置背景主题 "color torte " 设置背景主题 "set guifont=Courier_New:h10:cANSI " 设置字体 "autocmd InsertLeave * se nocul " 用浅色高亮当前行 autocmd InsertEnter * se cul " 用浅色高亮当前行 set ruler " 显示标尺 set showcmd " 输入的命令显示出来,看的清楚些 "set whichwrap+=,h,l " 允许backspace和光标键跨越行边界(不建议) set scrolloff=3 " 光标移动到buffer的顶部和底部时保持3行距离 set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")} "状态行显示的内容 set laststatus=2 " 启动显示状态行(1),总是显示状态行(2) "set foldenable " 允许折叠 ""set foldmethod=manual " 手动折叠 set nocompatible "去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限 " 显示中文帮助 if version >= 603 set helplang=cn set encoding=utf-8 endif " 自动缩进 set autoindent set cindent " Tab键的宽度 set tabstop=4 " 统一缩进为4 set softtabstop=4 set shiftwidth=4 " 使用空格代替制表符 set expandtab " 在行和段开始处使用制表符 set smarttab " 显示行号 set number " 历史记录数 set history=1000 "搜索逐字符高亮 set hlsearch set incsearch "语言设置 set langmenu=zh_CN.UTF-8 set helplang=cn " 总是显示状态行 set cmdheight=2 " 侦测文件类型 filetype on " 载入文件类型插件 filetype plugin on " 为特定文件类型载入相关缩进文件 filetype indent on " 保存全局变量 set viminfo+=! " 带有如下符号的单词不要被换行分割 set iskeyword+=_,$,@,%,#,- " 字符间插入的像素行数目 "markdown配置 au BufRead,BufNewFile *.{md,mdown,mkd,mkdn,markdown,mdwn} set filetype=mkd au BufRead,BufNewFile *.{go} set filetype=go au BufRead,BufNewFile *.{js} set filetype=javascript "rkdown to HTML nmap md :!~/.vim/markdown.pl % > %.html nmap fi :!firefox %.html & nmap \ \cc vmap \ \cc "将tab替换为空格 nmap tt :%s/\t/ /g """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """""新文件标题 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" "新建.c,.h,.sh,.java文件,自动插入文件头 autocmd BufNewFile *.cpp,*.[ch],*.sh,*.rb,*.java,*.py exec ":call SetTitle()" ""定义函数SetTitle,自动插入文件头 func SetTitle() "如果文件类型为.sh文件 if &filetype == 'sh' call setline(1,"\#!/bin/bash") call append(line("."), "") elseif &filetype == 'python' call setline(1,"#!/usr/bin/env python") call append(line("."),"# coding=utf-8") call append(line(".")+1, "") elseif &filetype == 'ruby' call setline(1,"#!/usr/bin/env ruby") call append(line("."),"# encoding: utf-8") call append(line(".")+1, "") " elseif &filetype == 'mkd' " call setline(1,"") else call setline(1, "/*************************************************************************") call append(line("."), " > File Name: ".expand("%")) call append(line(".")+1, " > Author: username") 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 expand("%:e") == 'cpp' call append(line(".")+6, "#include ") call append(line(".")+7, "using std::cin;") call append(line(".")+8, "using std::cout;") call append(line(".")+9, "using std::endl;") call append(line(".")+10, "using namespace std;") call append(line(".")+11, "") endif if &filetype == 'c' call append(line(".")+6, "#include ") call append(line(".")+7, "") endif if expand("%:e") == 'h' call append(line(".")+6, "#ifndef _".toupper(expand("%:r"))."_H") call append(line(".")+7, "#define _".toupper(expand("%:r"))."_H") call append(line(".")+8, "#endif") endif if &filetype == 'java' call append(line(".")+6,"public class ".expand("%:r")) call append(line(".")+7,"") endif "新建文件后,自动定位到文件末尾 endfunc autocmd BufNewFile * normal G command WQ wq command Wq wq """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" "键盘命令 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" :nmap :Tlist " shift tab pages map :tabp map :tabn map! zzi map! , map ggVG$"+y map :w map gg=G map w imap , imap imap " 选中状态下 Ctrl+c 复制 "map "*pa imap "*pa imap ^ imap $ vmap "+y "set mouse=v "set clipboard=unnamed "去注释 nnoremap :g/^\s*#/d "去空行 nnoremap :g/^\s*$/d "比较文件 nnoremap :vert diffsplit "nnoremap fu :CtrlPFunky "nnoremap :CtrlPFunky "列出当前目录文件 map :NERDTreeToggle imap :NERDTreeToggle "打开树状文件目录 map \be :autocmd BufRead,BufNewFile *.dot map :w:!dot -Tjpg -o % /dev/null 2>&1" elseif &filetype == 'perl' exec "!astyle --style=gnu --suffix=none %" elseif &filetype == 'py'||&filetype == 'python' exec "r !autopep8 -i --aggressive %" elseif &filetype == 'java' exec "!astyle --style=java --suffix=none %" elseif &filetype == 'jsp' exec "!astyle --style=gnu --suffix=none %" elseif &filetype == 'xml' exec "!astyle --style=gnu --suffix=none %" else exec "normal gg=G" return endif exec "e! %" endfunc "结束定义FormartSrc """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" ""实用设置 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" if has("autocmd") autocmd BufReadPost * \ if line("'\"") > 0 && line("'\"") }O ":inoremap } =ClosePair('}') "":inoremap [ []i "":inoremap ] =ClosePair(']') "":inoremap " ""i "":inoremap ' ''i ""function! ClosePair(char) "" if getline('.')[col('.') - 1] == a:char "" return "\" "" else "" return a:char "" endif ""endfunction filetype plugin indent on "打开文件类型检测, 加了这句才可以用智能补全 set completeopt=longest,menu """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " CTags的设定 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" let Tlist_Sort_Type = "name" " 按照名称排序 let Tlist_Use_Right_Window = 1 " 在右侧显示窗口 let Tlist_Compart_Format = 1 " 压缩方式 let Tlist_Exist_OnlyWindow = 1 " 如果只有一个buffer,kill窗口也kill掉buffer ""let Tlist_File_Fold_Auto_Close = 0 " 不要关闭其他文件的tags ""let Tlist_Enable_Fold_Column = 0 " 不要显示折叠树 "let Tlist_Show_One_File=1 "不同时显示多个文件的tag,只显示当前文件的 "设置tags set tags=tags; "set autochdir """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" "其他东东 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" "默认打开Taglist let Tlist_Auto_Open=0 """""""""""""""""""""""""""""" " Tag list (ctags) """""""""""""""""""""""""""""""" let Tlist_Ctags_Cmd = '/usr/local/bin/ctags' let Tlist_Show_One_File = 1 "不同时显示多个文件的tag,只显示当前文件的 let Tlist_File_Fold_Auto_Close = 1 let Tlist_Exit_OnlyWindow = 1 "如果taglist窗口是最后一个窗口,则退出vim let Tlist_Use_Right_Window = 1 "在右侧窗口中显示taglist窗口 " minibufexpl插件的一般设置 let g:miniBufExplMapWindowNavVim = 1 let g:miniBufExplMapWindowNavArrows = 1 let g:miniBufExplMapCTabSwitchBufs = 1 let g:miniBufExplModSelTarget = 1 nmap tl :Tlist "python补全 let g:pydiction_location = '~/.vim/after/complete-dict' let g:pydiction_menu_height = 20 let Tlist_Ctags_Cmd='/usr/local/bin/ctags' let g:miniBufExplMapWindowNavVim = 1 let g:miniBufExplMapWindowNavArrows = 1 let g:miniBufExplMapCTabSwitchBufs = 1 let g:miniBufExplModSelTarget = 1 set iskeyword+=. set termencoding=utf-8 set encoding=utf8 set fileencodings=utf8,ucs-bom,gbk,cp936,gb2312,gb18030 autocmd FileType python set omnifunc=pythoncomplete#Complete "set nocompatible " be iMproved "filetype off " required! set rtp+=~/.vim/bundle/vundle/ "call vundle#rc() " let Vundle manage Vundle " required! "Bundle 'gmarik/vundle' " My Bundles here: " " original repos on github " Bundle 'tpope/vim-fugitive' " Bundle 'rstacruz/sparkup', {'rtp': 'vim/'} " Bundle 'Yggdroot/indentLine' let g:indentLine_char = '┊' "ndle 'tpope/vim-rails.git' " vim-scripts repos " Bundle 'L9' " Bundle 'FuzzyFinder' " non github repos " Bundle 'https://github.com/wincent/command-t.git' " Bundle 'Auto-Pairs' " Bundle 'python-imports.vim' " Bundle 'CaptureClipboard' " Bundle 'ctrlp-modified.vim' " Bundle 'last_edit_marker.vim' " Bundle 'synmark.vim' "Bundle 'Python-mode-klen' " Bundle 'SQLComplete.vim' " Bundle 'Javascript-OmniCompletion-with-YUI-and-j' "Bundle 'JavaScript-Indent' "Bundle 'Better-Javascript-Indentation' "Bundle 'jslint.vim' "Bundle "pangloss/vim-javascript" "Bundle 'Vim-Script-Updater' "Bundle 'ctrlp.vim' "Bundle 'tacahiroy/ctrlp-funky' "Bundle 'jsbeautify' "Bundle 'The-NERD-Commenter' "django "Bundle 'django_templates.vim' "Bundle 'Django-Projects' "Bundle 'FredKSchott/CoVim' "Bundle 'djangojump' " ... let g:html_indent_inctags = "html,body,head,tbody" let g:html_indent_script1 = "inc" let g:html_indent_style1 = "inc" filetype plugin indent on " required! " "ctrlp设置 " set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*.pyc,*.png,*.jpg,*.gif " MacOSX/Linux set wildignore+=*\\tmp\\*,*.swp,*.zip,*.exe,*.pyc,*.png,*.jpg,*.gif " Windows let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$' let g:ctrlp_custom_ignore = '\v\.(exe|so|dll)$' let g:ctrlp_extensions = ['funky'] let NERDTreeIgnore=['\.pyc'] 测试

命令: 创建并打开一个cpp文件

vim test.cpp 效果

在这里插入图片描述



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3