Vim 插键及配置-程序员宅基地

技术标签: python  git  开发工具  

6d9475f6ly1fxspjxxb2pj20hs0cimym.jpg

如果你觉得这个页面广告太多,欢迎移步博客阅读:Vim 插键及配置

编辑器之神 —— Vim

平日使用vim经常编辑文件,想想使用时的痛点,决定研究一下插件的使用。

Vim的扩展通常也被成为bundle或插件。

软件版本:

  • Mac OS X 10.14.1
  • vim 8.1

插件安装-Vundle

众多文章中都提到Vundle,那我就选用它好了!

有一个 Vim 的插键网站,专门有相关插键的配置介绍:VimAwesome

1.将Vundle下载到本地,后面下载的插件也将会下载到~/.vim/bundle路径下。

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

2.插件配置,将如下的内容粘贴到~/.vimrc的顶部(前提是,你本身.vimrc里一开始没有什么其他内容)。

set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'

" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
" Plugin 'tpope/vim-fugitive'
" plugin from http://vim-scripts.org/vim/scripts.html
" Plugin 'L9'
" Git plugin not hosted on GitHub
" Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
" Plugin 'file:///home/gmarik/path/to/plugin'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
" Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Install L9 and avoid a Naming conflict if you've already installed a
" different version somewhere else.
" Plugin 'ascenator/L9', {'name': 'newL9'}

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList       - lists configured plugins
" :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line

3.安装插件

将需要安装的插键放入.vimrc文件中即可,例如:

Plugin 'scrooloose/nerdtree' 
"Plugin 'scrooloose/nerdtree'  " 如果暂时不启用,就将该插件注释掉

打开vim,然后输入:

vim # 打开 vim
:PluginInstall
:PluginList # 查看已安装插键列表

4.升级与卸载插件

# 注释下面这段话
# Plugin 'Valloric/YouCompleteMe'

然后

:PluginUpdate # 这个命令本身可以一键升级所有插件
:PlugginClean

参考:

5.帮助文档

:h vundle

NERDTree

Plugin 'scrooloose/nerdtree'

"F2开启和关闭树"
map <F2> :NERDTreeToggle<CR>
let NERDTreeChDirMode=1
"显示书签"
let NERDTreeShowBookmarks=1
"设置忽略文件类型"
let NERDTreeIgnore=['\~$', '\.pyc$', '\.swp$']
"窗口大小"
let NERDTreeWinSize=25

python-mode

Plugin 'klen/python-mode' " https://vimawesome.com/plugin/python-mode

编写 Python 文件保存时,就会进行语法检查了:

let g:pymode_rope = 1
let g:pymode_rope_completion = 1
let g:pymode_rope_completion_bind = '<C-p>'  "为了自动补全有效,需要将 set paste 设置不启用
let g:pymode_rope_goto_definition_bind = '<C-c>g'
let g:pymode_python = 'python' " 默认检查 Python2
"Autofix PEP8 errors
nnoremap <leader>f :PymodeLintAuto<CR>

快捷键:

K 显示内置函数文档
<leader>r 运行 python 文件 # let mapleader=", " " 设置 leader 为空格,那么`,+r`就可以运行 python 文件了

参考:

vim-airline

一个状态栏美化工具,颜控必备。附带功能可以一目了然的区分各种编辑状态。

Plugin 'vim-airline/vim-airline' "https://github.com/vim-airlin    e/vim-airline
Plugin 'vim-airline/vim-airline-themes' "  https://github.com/v    im-airline/vim-airline-themes https://github.com/vim-airline/vi    m-airline/wiki/Screenshots

主题预览

To use solarized dark, set :AirlineTheme solarized and add the following to your .vimrc: let g:airline_solarized_bg='dark'

配置:

let g:airline_powerline_fonts = 1
let g:airline_theme='deus'
let g:Powerline_symbols='fancy'
let Powerline_symbols='fancy'
set t_Co=256 " 状态栏就有颜色了

Yggdroot/indentLine

安装:

Plugin 'Yggdroot/indentLine'

配置:

let g:indentLine_enabled = 1
let g:indentLine_color_term = 239
map <leader>m :IndentLinesToggle<CR> # 解决vim复制代码时,缩进线也被复制的问题 https://github.com/Yggdroot/indentLine/issues/261

为了这个插件能够有效果,也是折腾了半天。在 CentOS 平台是正常的,但是在 Mac 上的缩进线显示不正确,为何会这样呢?SOF-Why is apple vim compiled WITHOUT conceal feature?,原来 Mac 上自带的 Vim 版本虽然是8.0版本,但是没有concel这个 Feature ,而indentLine插件要显示对齐线依赖这个,坚线和星号在使用 conceal 功能

那么该怎么添加这个特性呢?搜了一圈,可以重新安装 Vim,可以参考这篇文章安装 Vim。

经过安装设置之后,可以通过vim --version|grep con或者:echo has("conceal")查看是否已经具有 conceal 特性:
006tNbRwly1fxrioguwosj30f902mdg7.jpg

rking/ag.vim

ag 的语法:

ag [FILE-TYPE] [OPTIONS] PATTERN [PATH]

ag 这个 vim 插键主要是基于这个项目 ggreer/the_silver_searcher

ag --list-file-types # 查看支持自定义哪些文件类型

安装了这个插键后,在 vim 的命令模式下,可以使用:Ag [options] {pattern} [{directory}]搜索了。

majutsushi/tagbar

安装 vim 插键之前,机器本身需要ctags

# ubuntu
sudo apt-get install ctags
# centos
sudo yum install ctags
# mac
brew install ctags

在这时使用 vim-tagbar 插件可以帮你快速了解当前文件中的类、方法等。

Plugin 'majutsushi/tagbar' " https://github.com/majutsushi/tagbar

配置:

nmap <F8> :TagbarToggle<CR>

关于 tagbar 的使用,看查看这篇文章 wklken-大纲式导航

YouCompleteMe

目前主要涉及的是 Python 开发,所以,YCM 目前没有配置,如下仅供参考。

Plugin 'Valloric/YouCompleteMe'
sudo apt-get install build-essential cmake
sudo apt-get install python-dev python3-dev
cd ~/.vim/bundle/YouCompleteMe
./install.py --all

cp ~/.vim/bundle/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py ~/.vim/
"YouCompleteMe配置相关
let g:ycm_server_python_interpreter='/usr/bin/python'
let g:ycm_global_ycm_extra_conf='~/.vim/.ycm_extra_conf.py'

主题

安装主题的方法比较简单,例如需要安装molokai主题,手动安装则按照如下步骤操作:

因为我在 VSCode 和 Iterm2 中都采用了 Dracula 的主题,因此,vim 主题我也同样偏爱它,可以采用插键的方式安装:

Plugin 'dracula/vim'
:PluginInstall
  • 然后在~/.vimrc文件中加入行colorscheme dracula即可。

主题相关的命令:

:colorscheme   "查看当前主题
:colorscheme space tab "列出所有主题
:colorscheme your-theme "切换主题

设置vim

为了让vim使用起来更加得心应手,先做一些简单的配置。

编辑VIM配置文件,可能一开始没有这个文件,不过没关系,直接vi ~/.vimrc保存这个文件即可。

今天学习到<leader> 这个概念,很强大,快捷键很方便!

  • nnoremap 将一个组合快捷键映射为另一个快捷键。

关于leader以及其他map知识,可以查看如下文章:

个人vim配置

参考多人的配置,打造属于自己的Vim配置,这个配置不涉及插件的设置,因为常常生产环境是网络不通的,要迅速配置能用:

let mapleader="," " 设置 leader
let g:mapleader = ','

" 分屏窗口移动, Smart way to move between windows
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l

" Go to home and end using capitalized directions
" H和L跳转到行首行末, 实在不想按0和$, 太远
noremap H ^
noremap L $

" 命令行模式增强,ctrl - a到行首, -e 到行尾
cnoremap <C-a> <Home>
cnoremap <C-e> <End>

" 去掉搜索高亮
noremap <silent><leader>/ :nohls<CR>

" 快速保存和退出
" Quickly close the current window
nnoremap <leader>q :q<CR>
" Quickly save the current file
nnoremap <leader>w :w<CR>


syntax on " 自动语法高亮
set cursorline " 突出显示当前行
set encoding=utf-8
set fileencoding=utf-8
set fileformat=unix "从Win上复制文件时,避免换行符错误
set hlsearch " 搜索时高亮显示被找到的文本
set ignorecase smartcase " 搜索时忽略大小写,但在有一个或以上大写字母时仍保持对大小写敏感
set incsearch " 输入搜索内容时就显示搜索结果
set laststatus=2 " 显示状态栏 (默认值为 1, 无法显示状态栏)
set magic " 设置魔术
set nocompatible " 关闭 vi 兼容模式
set number " 显示行号
set paste  " 解决拷贝的时遇到注释会自动注释后续所有行的问题
set ruler " 打开状态栏标尺
set shiftwidth=4 " 设定 << 和 >> 命令移动时的宽度为 4
set softtabstop=4 " 使得按退格键时可以一次删掉 4 个空格
set smartindent " 开启新行时使用智能自动缩进
set tabstop=4 " 设定 tab 长度为 4
set ambiwidth=double " 设置为双字宽显示,否则无法完整显示如:☆

vim配置文件中的注释,末尾用"隔开即可。保留注释,对于了解配置内容有利。

vim配置参考

FAQ

1. github访问速度慢,下载插件失败

2. tmux里面鼠标复制, 无法选中一行内容

mac上iterm2中,你会发现你想复制terminal上的东西的时候,死活复制不了,这时按住 Option (Alt)键就行了。
如果是在Windows平台上利用mobaxterm等工具,tmux也无法复制内容,按住shift键即可。

3. vim 中的内容,mobaxterm无法鼠标复制

注释掉这句话set mouse=a

参考

转载于:https://www.cnblogs.com/michael-xiang/p/10467220.html

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_34355881/article/details/94298114

智能推荐

while循环&CPU占用率高问题深入分析与解决方案_main函数使用while(1)循环cpu占用99-程序员宅基地

文章浏览阅读3.8k次,点赞9次,收藏28次。直接上一个工作中碰到的问题,另外一个系统开启多线程调用我这边的接口,然后我这边会开启多线程批量查询第三方接口并且返回给调用方。使用的是两三年前别人遗留下来的方法,放到线上后发现确实是可以正常取到结果,但是一旦调用,CPU占用就直接100%(部署环境是win server服务器)。因此查看了下相关的老代码并使用JProfiler查看发现是在某个while循环的时候有问题。具体项目代码就不贴了,类似于下面这段代码。​​​​​​while(flag) {//your code;}这里的flag._main函数使用while(1)循环cpu占用99

【无标题】jetbrains idea shift f6不生效_idea shift +f6快捷键不生效-程序员宅基地

文章浏览阅读347次。idea shift f6 快捷键无效_idea shift +f6快捷键不生效

node.js学习笔记之Node中的核心模块_node模块中有很多核心模块,以下不属于核心模块,使用时需下载的是-程序员宅基地

文章浏览阅读135次。Ecmacript 中没有DOM 和 BOM核心模块Node为JavaScript提供了很多服务器级别,这些API绝大多数都被包装到了一个具名和核心模块中了,例如文件操作的 fs 核心模块 ,http服务构建的http 模块 path 路径操作模块 os 操作系统信息模块// 用来获取机器信息的var os = require('os')// 用来操作路径的var path = require('path')// 获取当前机器的 CPU 信息console.log(os.cpus._node模块中有很多核心模块,以下不属于核心模块,使用时需下载的是

数学建模【SPSS 下载-安装、方差分析与回归分析的SPSS实现(软件概述、方差分析、回归分析)】_化工数学模型数据回归软件-程序员宅基地

文章浏览阅读10w+次,点赞435次,收藏3.4k次。SPSS 22 下载安装过程7.6 方差分析与回归分析的SPSS实现7.6.1 SPSS软件概述1 SPSS版本与安装2 SPSS界面3 SPSS特点4 SPSS数据7.6.2 SPSS与方差分析1 单因素方差分析2 双因素方差分析7.6.3 SPSS与回归分析SPSS回归分析过程牙膏价格问题的回归分析_化工数学模型数据回归软件

利用hutool实现邮件发送功能_hutool发送邮件-程序员宅基地

文章浏览阅读7.5k次。如何利用hutool工具包实现邮件发送功能呢?1、首先引入hutool依赖<dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>5.7.19</version></dependency>2、编写邮件发送工具类package com.pc.c..._hutool发送邮件

docker安装elasticsearch,elasticsearch-head,kibana,ik分词器_docker安装kibana连接elasticsearch并且elasticsearch有密码-程序员宅基地

文章浏览阅读867次,点赞2次,收藏2次。docker安装elasticsearch,elasticsearch-head,kibana,ik分词器安装方式基本有两种,一种是pull的方式,一种是Dockerfile的方式,由于pull的方式pull下来后还需配置许多东西且不便于复用,个人比较喜欢使用Dockerfile的方式所有docker支持的镜像基本都在https://hub.docker.com/docker的官网上能找到合..._docker安装kibana连接elasticsearch并且elasticsearch有密码

随便推点

Python 攻克移动开发失败!_beeware-程序员宅基地

文章浏览阅读1.3w次,点赞57次,收藏92次。整理 | 郑丽媛出品 | CSDN(ID:CSDNnews)近年来,随着机器学习的兴起,有一门编程语言逐渐变得火热——Python。得益于其针对机器学习提供了大量开源框架和第三方模块,内置..._beeware

Swift4.0_Timer 的基本使用_swift timer 暂停-程序员宅基地

文章浏览阅读7.9k次。//// ViewController.swift// Day_10_Timer//// Created by dongqiangfei on 2018/10/15.// Copyright 2018年 飞飞. All rights reserved.//import UIKitclass ViewController: UIViewController { ..._swift timer 暂停

元素三大等待-程序员宅基地

文章浏览阅读986次,点赞2次,收藏2次。1.硬性等待让当前线程暂停执行,应用场景:代码执行速度太快了,但是UI元素没有立马加载出来,造成两者不同步,这时候就可以让代码等待一下,再去执行找元素的动作线程休眠,强制等待 Thread.sleep(long mills)package com.example.demo;import org.junit.jupiter.api.Test;import org.openqa.selenium.By;import org.openqa.selenium.firefox.Firefox.._元素三大等待

Java软件工程师职位分析_java岗位分析-程序员宅基地

文章浏览阅读3k次,点赞4次,收藏14次。Java软件工程师职位分析_java岗位分析

Java:Unreachable code的解决方法_java unreachable code-程序员宅基地

文章浏览阅读2k次。Java:Unreachable code的解决方法_java unreachable code

标签data-*自定义属性值和根据data属性值查找对应标签_如何根据data-*属性获取对应的标签对象-程序员宅基地

文章浏览阅读1w次。1、html中设置标签data-*的值 标题 11111 222222、点击获取当前标签的data-url的值$('dd').on('click', function() { var urlVal = $(this).data('ur_如何根据data-*属性获取对应的标签对象

推荐文章

热门文章

相关标签