MacOS下vim爬坑笔记

MacOS下的VIM爬坑笔记

安装

1
brew install vim

配置

MacOS下的vim配置文件 vimrc/usr/share/vim/vimrc 这个位置。

以下是我的配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
" Configuration file for vim
set modelines=0 " CVE-2007-2438

" Normally we use vim-extensions. If you want true vi-compatibility
" remove change the following statements
set nocompatible " Use Vim defaults instead of 100% vi compatibility
set backspace=2 " more powerful backspacing

" Don't write backup file if vim is being called by "crontab -e"
au BufWrite /private/tmp/crontab.* set nowritebackup nobackup
" Don't write backup file if vim is being called by "chpass"
au BufWrite /private/etc/pw.* set nowritebackup nobackup


" Custom Configure Start

" 自动检测语法高亮
syntax on
" Tab替换为4个空格
set ts=4
set expandtab
" 搜索结果高亮 (取消方法 :nohls)
set hlsearch

" Custom Configure End

插件

安装插件管理器

vim插件管理工具可以让插件安装变得简单快捷,vim的插件管理工具也有很多,这里选用 vim-pathogenhttps://github.com/tpope/vim-pathogen),安装很简单

1
mkdir -p ~/.vim/autoload ~/.vim/bundle

下载 vim-pathogen 到 ~/.vim/autoload

1
curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim

编辑 /usr/share/vim/vimrc ,加入如下几行内容:

1
2
3
execute pathogen#infect()
syntax on
filetype plugin indent on

重启vim 即可安装成功,之后如果想要安装其他插件,只需把插件放到 ~/.vim/bundle 目录下, 重启vim ,vim-pathogen就会帮你自动安装好插件。例如安装

markdown:

1
2
cd ~/.vim/bundle/
git clone https://github.com/plasticboy/vim-markdown.git

然后重启vim即可

添加 vim-go 插件

vim-go 是一款go代码高亮和语法检查的插件

如上所示安装方法,clone vim-go 到 ~/.vim/bundle 目录下即可

1
2
cd ~/.vim/bundle/
git clone https://github.com/fatih/vim-go.git

Via:https://blog.csdn.net/zhang197093/article/details/78559903?locationNum=5&fps=1

启动vim出现错误:

1
2
3
4
5
6
7
8
vim-go requires Vim 7.4.1689 or Neovim, but you're using an older version.
Please update your Vim for the best vim-go experience.
If you really want to continue you can set this to make the error go away:
let g:go_version_warning = 0
Note that some features may error out or behave incorrectly.
Please do not report bugs unless you're using Vim 7.4.1689 or newer.

Press ENTER or type command to continue

解决方案:

添加 let g:go_version_warning = 0 到 vimrc文件中。