vim配置

vim配置

vim–一款让小白头疼,吐槽难用,但同时又是一款让大神爱不释手的开发神器,因为如果使用vim开发,你可以高效到不使用鼠标,这几乎是所有Windows下的IDE所不能实现的,相信当你的码代码的速度会因为点鼠标而变慢的时候,你就真正到达大神们的境界了。
虽然本人的水平并没有达到上面所说的水平,但是本人还是分享一些自己使用或者参考别人的vim的配置与插件,因为如果不使用vim开发,在Windows与linux间来回切换确实效率太低下了,而且Windows与linux间回车的定义也不一致,你自己在Windows下写的代码再拷贝回linux上库的话经常会有格式上的问题,git提交的代码因为格式问题会被公司的大佬们喷的,所以,不管从开发效率还是代码格式上来说,使用vim开发都是一种最优解。

功能快捷键

不显示行号:Ctrl/Command + n
显示行号:Ctrl/Command + b
新建一个tab :Ctrl/Command + d
在tab间切换:Ctrl/Command + e
关闭当前tab:Ctrl/Command + q
鼠标可以滑动,选择光标:Ctrl/Command + a
关闭鼠标可以滑动,选择光标:Ctrl/Command + z
打开NERDTree:F7
使用LeaderF搜索文件:space + f

我的 .vimrc配置

" An example for a vimrc file.
"
" Maintainer:	Bram Moolenaar <Bram@vim.org>
" Last change:	2011 Apr 15
"
" To use it, copy it to
"     for Unix and OS/2:  ~/.vimrc
"	      for Amiga:  s:.vimrc
"  for MS-DOS and Win32:  $VIM\_vimrc
"	    for OpenVMS:  sys$login:.vimrc



" ---------------------------------------------------

set nocompatible               " be iMproved
filetype off                   " required!

set rtp+=~/.vim/bundle/vundle/
call vundle#rc()

" let Vundle manage Vundle
" required!
Bundle 'gmarik/vundle'

" vim-go
Plugin 'fatih/vim-go'

set rtp+=~/.vim/bundle/vim-go/
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_structs = 1
let g:go_def_mapping_enabled = 0

" tagbar
Bundle 'majutsushi/tagbar'

nmap <F4> :TagbarToggle<CR>
let g:tagbar_right=1
let g:tagbar_width=40

" gocode
Plugin 'nsf/gocode', {'rtp': 'vim/'}

" supertab
let g:SuperTabDefaultCompletionType="context"

" theme
colorscheme  molokai
set t_Co=256
set background=dark

" for paste
nnoremap <F2> :set invpaste paste?<CR>
imap <F2> <C-O>:set invpaste paste?<CR>
set pastetoggle=<F2>

" nerdtree
Bundle 'scrooloose/nerdtree'

let g:NERDTreeDirArrows = 1
map <F7> :NERDTreeToggle<CR>
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif

" CtrlP
set runtimepath^=~/.vim/bundle/ctrlp.vim
let g:ctrlp_by_filename = 1
let g:ctrlp_working_path_mode = '0'
let g:ctrlp_match_window = 'bottom,order:ttb,min:1,max:10,results:20'
let g:ctrlp_extensions = ['buffertag', 'dir', 'undo', 'line', 'changes', 'mixed', 'bookmarkdir']
let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd = 'CtrlP'
set wildignore+="*/tmp/*,*.so,*.o,*.a,*.obj,*.swp,*.zip,*.pyc,*.pyo,*.class,.DS_Store"
let g:ctrlp_custom_ignore = {
			\ 'dir': '\v[\/]\.(git|hg|svn)$',
			\ 'file': '\v\.(exe|so|dll|o|mod.c)$',
			\ 'link': 'SOME_BAD_SYMBOLIC_LINKS',
			\ }

" vim-airline
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
let g:airline#extensions#tabline#enabled = 1
let g:airline_theme='molokai'
"nnoremap <C-Q> :bp<CR>
"nnoremap <C-W> :bn<CR>

" spell check
:map <C-K> :setlocal spell spelllang=en_us<CR>

" cscope
if has('cscope')
	set cscopetag
	set csto=0
	set cscopeverbose
	set nocsverb
	if filereadable("cscope.out")
		cs add cscope.out
	elseif $CSCOPE_DB != ""
		cs add $CSCOPE_DB
	endif
	set csverb


	nmap <C-f>s :cs find s <C-R>=expand("<cword>")<CR><CR>
	nmap <C-f>g :cs find g <C-R>=expand("<cword>")<CR><CR>
	nmap <C-f>c :cs find c <C-R>=expand("<cword>")<CR><CR>
	nmap <C-f>t :cs find t <C-R>=expand("<cword>")<CR><CR>
	nmap <C-f>e :cs find e <C-R>=expand("<cword>")<CR><CR>
	nmap <C-f>f :cs find f <C-R>=expand("<cword>")<CR><CR>
	nmap <C-f>i :cs find i ^<C-R>=expand("<cword>")<CR>$<CR>
	nmap <C-f>d :cs find d <C-R>=expand("<cword>")<CR><CR>
endif

""LeaderF
Plugin 'Yggdroot/LeaderF'

let mapleader = "\<space>"

""LeaderF config
noremap <leader>f :Leaderf file /Users/bytedance/code/<CR>
noremap <leader>j :LeaderfFunction<CR>
noremap <leader>t :LeaderfTag<CR>

Plugin 'vim-scripts/AutoComplPop'  " 自动补全功能

" for python indent
" autocmd BufNewFile,BufRead *.py set tabstop=4 softtabstop=4 shiftwidth=4 expandtab
" autocmd BufNewFile,BufRead *.h,*.hh,*.cc,*.c,*.cxx,Makefile set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab

" vim-autoformat
Plugin 'Chiel92/vim-autoformat'
let g:formatdef_custom = '"astyle --options=none --lineend=linux --mode=c --style=linux --indent=force-tab=8 --indent-preprocessor --indent-col1-comments --attach-namespaces --attach-classes --attach-inlines --attach-extern-c --min-conditional-indent=0 --max-instatement-indent=80 --pad-oper --pad-header --unpad-paren --align-pointer=name --align-reference=name --max-code-length=80 --break-after-logical"'
let g:formatters_cpp = ['custom']
let g:formatters_c = ['custom']
" au BufWrite *.cc,*.hh,*.c,*.h :Autoformat
noremap <F5> :Autoformat<CR>

function! UpdateCtags()
	let curdir=getcwd()
	while !filereadable("./tags")
		cd ..
		if getcwd() == "/"
			break
		endif
	endwhile
	if filewritable("./tags")
		!ctags -R --file-scope=yes --langmap=c:+.h --languages=c,c++ --links=yes --c-kinds=+p --c++-kinds=+p --fields=+iaS --extra=+q
	endif
	execute ":cd " . curdir
endfunction

nmap <F10> :call UpdateCtags()<CR>

filetype plugin indent on
syntax on

" for Chinese encoding
set fileencodings=utf-8,gbk

" hmcopyright
function! HMBANNER()
        0r ~/.vim/templates/copyright
"        language time en_US.UTF-8
        exe "%s/@TIMESTAMP@/" . strftime("%a %b %d %H:%M:%S %Y"). "/g"
endfunction
autocmd BufNewFile      *.c call HMBANNER()
autocmd BufNewFile      *.h call HMBANNER()

" ---------------------------------------------------

" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
	finish
endif


" allow backspacing over everything in insert mode
set backspace=indent,eol,start

set nobackup		" do not keep a backup file, use versions instead
set nowritebackup
set noswapfile
" set history=50		" keep 50 lines of command line history
set ruler		" show the cursor position all the time
set showcmd		" display incomplete commands
set incsearch		" do incremental searching

" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")

" Don't use Ex mode, use Q for formatting
map Q gq

" CTRL-U in insert mode deletes a lot.  Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>

" In many terminal emulators the mouse works just fine, thus enable it.
set mouse=v
:map <C-A> :set mouse=a<CR>
:map <C-Z> :set mouse=v<CR>

set nu
:map <C-N> :set nonu<CR>
:map <C-B> :set nu<CR>

:map <C-D> :tabnew<CR>
:map <C-E> :tabp<CR>
:map <C-Q> :tabc<CR>

" mark line and column of cursor

set cursorline
set cursorcolumn

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
endif
" Only do this part when compiled with support for autocommands.
if has("autocmd")

	" Enable file type detection.
	" Use the default filetype settings, so that mail gets 'tw' set to 72,
	" 'cindent' is on in C files, etc.
	" Also load indent files, to automatically do language-dependent indenting.
	filetype plugin indent on

	" Put these in an autocmd group, so that we can delete them easily.
	augroup vimrcEx
		au!

		" For all text files set 'textwidth' to 78 characters.
		autocmd FileType text setlocal textwidth=78

		" When editing a file, always jump to the last known cursor position.
		" Don't do it when the position is invalid or when inside an event handler
		" (happens when dropping a file on gvim).
		" Also don't do it when the mark is in the first line, that is the default
		" position when opening a file.
		autocmd BufReadPost *
					\ if line("'\"") > 1 && line("'\"") <= line("$") |
					\   exe "normal! g`\"" |
					\ endif

	augroup END

else

	set autoindent		" always set autoindenting on

endif " has("autocmd")

" highlight extra white space"
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
set listchars=tab:>-,trail:~,extends:>,precedes:<
set list


" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
	command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
				\ | wincmd p | diffthis
endif

安装方法

vim ~/.vimrc

将上面的内容拷贝到~/.vimrc 中,保存退出后,然后再创建.vim文件

mkdir ~/.vim 

安装vundle

git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

安装需要的插件,有两种方法安装插件。
(1) 运行 vim ,再运行 :PluginInstall

vim

在vim 中输入一下字符,耐心等待安装即可

:PlugInstall

(2) 通过命令行直接安装

vim +PluginInstall +qall

安装过程中可能会由于git设置的问题,导致下载失败,可以修改一下设置

git config --global http.postBuffer 1048576000

如果安装不成功,可以尝试手动git clone对应的插件到~/.vim/bundle

molokai 安装

cd ~/.vim
git clone git://github.com/tomasr/molokai.git
cp -r ~/.vim/molokai/colors ~/.vim/

部分vim插件对vim的版本有要求可以按照下面的操作升级vim,安装步骤参考的链接

vim升级安装方法

第一步,下载源码
到Vim官方Github仓库下载目前最新的Vim Release版本

wget https://codeload.github.com/vim/vim/tar.gz/v8.2.1258

第二步,解压

mv v8.2.1258  vim-v8.2.1258.tar.gz
tar -xvzf vim-v8.2.1258.tar.gz

第三步,编译安装

cd vim-8.2.1258/
./configure --prefix=$HOME/.local --enable-python3interp=yes && make && make install

这里注意一下我们需要用configure配置一下安装的路径,将Vim8安装到自己账户的目录下,避免干扰到系统上的其他用户
--enable-python3interp=yes 添加 python3 支持
在这里可能会遇到 no terminal library found 错误:

no terminal library found
checking for tgetent()… configure: error: NOT FOUND! You need to install a terminal library; for example ncurses. Or specify the name of the library with –with-tlib.

解决方法:

Ubuntu下解决方法:

sudo apt install libncurses5-dev

CentOS 下

yum install ncurses-devel.x86_64

完成后重新进行这一步,建议删除
第四步,链接
利用alias将vim指令定向到刚刚安装的vim8,同时修改.bashrc确保之后一直能生效

alias vim='~/.local/bin/vim'
echo "alias vim='~/.local/bin/vim'" >> ~/.bashrc

第五步,检查

vim --version

可能会出现一下错误

LeaderF requires Vim compiled with python and/or a compatible python version

需要编译vim的实收使用python不要使用python3

cd vim-8.2.1258/
./configure --prefix=$HOME/.local --enable-pythoninterp=yes && make && make install

这样就可以了

创建新文件模板设置

mkdir ~/.vim/templates
vim ~/.vim/templates/copyright

然后填入一下内容

/*
 * Copyright (C) 
 * Author: JiaHao
 * Create: @TIMESTAMP@
 */

@TIMESTAMP@用来自动替换创建文件时间,另外,可能机器上设置language time en_US.UTF-8会有问题,可以修改.vimrc文件,屏蔽掉这个地方

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用: Ubuntu的安装 1.1 镜像下载 1.2 镜像的安装 2 vim的使用 2.1 vim的几种模式 2.2 vim的启动 2.3 常用文档操作。 引用: 然后点击完成,打开虚拟机,并安装系统 选择语言为中文,继续 然后设置姓名密码,安装完成 2 vim的使用 2.1 vim的几种模式 正常模式插入模式:可以输入文本,在正常模式下,按i、a、o可以进入本模式 可视模式:正常模式下按v可以进入可视模式,在可视模式下,移动光标可以选择文本。按V进入可视行模式,总是整行整行的选中。ctrl v进入可视块模式。 2.2 vim的启动 vim -c cmd file:在打开文件前,先执行指定的命令 vim -r file: 恢复上次异常退出的文件 vim -R file: 以只读的方式打开文件,但可以强制保存 vim -M file: 以只读的方式打开文件,不可以强制保存 vim -y num file: 将编辑窗口的大小设为num行 vim file: 从文件的末尾开始 vim num file: 从第num行开始 vim /string file: 打开file,并将光标停留在第一个找到的string上 vim –remote file: 用已有的vim进程打开指定的文件。 如果你不想启用多个vim会话,这个很有用。但要注意, 如果你用vim,会寻找名叫VIM的服务器;如果你已经有一个gvim在运行了, 你可以用gvim –remote file在已有的gvim中打开文件 2.3 常用文档操作 :e file –关闭当前编辑的文件,并开启新的文件。 :w – 保存修改 :wq – 保存并退出 :x – 保存并退出。 引用: 打开VMware,创建新的虚拟机 选择自定义,并点击下一步 点击下一步 点击稍后安装操作系统,并下一步 客户机操作系统选择Linux,版本选择Ubuntu 64 位,下一步 选择想要安装的虚拟机位置,不建议在c盘。 问题: 请告诉我,18.04 vim配置 在Ubuntu 18.04上配置vim很简单。首先,确保你的系统上已经安装了vim。你可以使用以下命令来安装vim: ``` sudo apt-get update sudo apt-get install vim ``` 安装完成后,你可以通过编辑.vimrc文件来配置vim。该文件位于你的用户主目录下。你可以使用以下命令来打开并编辑该文件: ``` vim ~/.vimrc ``` 在.vimrc文件中,你可以添加各种配置选项,例如设置自动缩进、设置颜色主题、定义快捷键等。以下是一些常见的配置选项示例: ``` " 设置自动缩进 set autoindent " 设置显示行号 set number " 设置颜色主题 syntax on colorscheme desert " 定义快捷键 map <F5> :w<CR> " 设置Tab键为4个空格 set tabstop=4 set shiftwidth=4 set expandtab ``` 保存并关闭.vimrc文件后,你的vim配置就完成了。现在你可以重新启动vim,你的配置将生效。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值