文章地址 https://github.com/itgoyo/500Days-Of-Github/issues
本人github:itgoyo,歡迎關(guān)注 (??? ????)
Vim
Vim的配置以spf-13為例子
項(xiàng)目地址: https://github.com/spf13/spf13-vim
Vim的安裝
- Linux, *nix, Mac OSX Installation
The easiest way to install spf13-vim is to use our automatic installer by simply copying and pasting the following line into a terminal. This will install spf13-vim and backup your existing vim configuration. If you are upgrading from a prior version (before 3.0) this is also the recommended installation.
Requires Git 1.7+ and Vim 7.3+
curl https://j.mp/spf13-vim3 -L > spf13-vim.sh && sh spf13-vim.sh
If you have a bash-compatible shell you can run the script directly:
sh <(curl https://j.mp/spf13-vim3 -L)
此過程會(huì)比較長,包括插件的下載還有安裝,這個(gè)過程將近1個(gè)多小時(shí)
- Installing on Windows
On Windows and *nix Git and Curl are required. Also, if you haven't done so already, you'll need to install Vim. The quickest option to install all three dependencies (Git, Curl, Vim and spf13-vim) is via Chocolatey NuGet. After installing Chocolatey, execute the following commands on the command prompt:
Install with cmd.exe(run as admin mode)
@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
C:\> choco install spf13-vim
一直Y,整個(gè)過程大概2h左右
Vim插件的介紹
-
Vundle(The best plugin manager)
Vundle is an excellent system built on the same principles as Pathogen, but with an integrated plugin management system that is Git and Github aware.
spf13-vim uses the Vundle plugin management system to have a well organized vim directory (Similar to mac's app folders). Vundle also ensures that the latest versions of your plugins are installed and makes it easy to keep them up to date.
-
NERDTree(file navigation)
NERDTree is a file explorer plugin that provides "project drawer" functionality to your vim editing. You can learn more about it with :help NERDTree or checkout my post on NERDTree.
Use Ctrl+e to toggle NERDTree
-
ctrlp(fast file finder)
Ctrlp replaces the Command-T plugin with a 100% viml plugin. It provides an intuitive and fast mechanism to load files from the file system (with regex and fuzzy find), from open buffers, and from recently used files.
Use Ctrl+p to toggle Ctrlp
-
neocomplcache(autocomplete++)
NeoComplCache is an amazing autocomplete plugin with additional support for snippets. It can complete simulatiously from the dictionary, buffer, omnicomplete and snippets. This is the one true plugin that brings Vim autocomplete on par with the best editors.
Use Ctrl+n to toggle neocomplcache
-
Tagbar(tag generation and navigation)
spf13-vim includes the Tagbar plugin. This plugin requires exuberant-ctags and will automatically generate tags for your open files. It also provides a panel to navigate easily via tags
Use ,tt to toggle neocomplcache
關(guān)于在Mac端ctags無效的解決方法
https://github.com/universal-ctags/ctags
https://github.com/universal-ctags/homebrew-universal-ctags
在Windows端,如果想切換到別的盤符進(jìn)行操作的話,使用
:NERDTree D:\\
進(jìn)行目錄的跳轉(zhuǎn)
Preview: To preview markdown format you need to install bluecloth gem
在使用previewMarkdown的時(shí)候出現(xiàn)了
Preview: To preview markdown format you need to install bluecloth gem
解決方法:
sudo gem install redcarpetsudo gem install bluecloth
Linux出現(xiàn)的問題
can't find header files for ruby at /usr/lib/ruby/include/ruby.h
解決方法:sudo apt-get install ruby-dev
提示找不到tag文件
用法:
1.生成標(biāo)簽文件(cmd到項(xiàng)目的目錄中執(zhí)行)
在當(dāng)前目錄下(運(yùn)行$提示符后面的命令):
$ctags -R .
-R表示recursive,遞歸,為當(dāng)前目錄及其子目錄中的c文件生成標(biāo)簽文件。最后一個(gè).表示在當(dāng)前目錄。
運(yùn)行完當(dāng)前目錄會(huì)多一個(gè)文件tags,就是c標(biāo)簽的索引文件。
2.跳轉(zhuǎn)
1)用vim打開一個(gè)已經(jīng)建過標(biāo)簽的c文件
2)ctrl+] 找到光標(biāo)所在位置的標(biāo)簽定義的地方
3)ctrl+t 回到跳轉(zhuǎn)之前的標(biāo)簽處
3.窗口顯示方法
命令Tagbar toggle打開相應(yīng)的方法窗口顯示
注意:此時(shí)運(yùn)行vim,必須在"tags"文件所在的目錄下運(yùn)行。否則,運(yùn)行它會(huì)找不到"tags"文件,而需要在vim中用":set tags="命令設(shè)定"tags"文件的路徑。對(duì)于一個(gè)稍微大點(diǎn)的項(xiàng)目,你可能在任何一個(gè)目錄下打開vim,然而在每個(gè)目錄下都生成一個(gè)tags文件并不 是個(gè)好主意,那么如何解決呢?方法是在.vimrc中增加一行:
set tags=tags;/
這是告訴vim在當(dāng)前目錄找不到tags文件時(shí)請(qǐng)到上層目錄查找。
窗口切換快捷鍵
Ctrl+w+w
關(guān)閉分屏
關(guān)閉當(dāng)前窗口。
Ctrl+W c
關(guān)閉當(dāng)前窗口,如果只剩最后一個(gè)了,則退出Vim。
Ctrl+W q
打開多個(gè)窗口了之后,怎么快速切換
:buffers 列表 :bn下一個(gè) :bp 上一個(gè) :b17
取消查找遺留的邊框
set: nohlseach
VIM編輯多行
vim進(jìn)了多行編輯模式:<ESC>之后按CTRL+V進(jìn)入visual block模式(列編輯)。光標(biāo)移到某行行首,進(jìn)入visual block模式,上下鍵選擇行,按I(i的大寫字母),輸入##,然后按<ESC>鍵,這樣就在多行行首添加##了。也可以在多行的固定位置添加固定字符。
如果要?jiǎng)h除這些##,進(jìn)入visual block模式,選中這些##,按d即可。
全局搜索Ack
| 按鍵 | 功能 |
|---|---|
| ? | 顯示鍵盤映射 |
| o | 打開文件 |
| O | 打開文件關(guān)閉QuickFix窗口 |
| go | 預(yù)覽文件,但焦點(diǎn)留在ack搜索結(jié)果上 |
| t | 在新標(biāo)簽頁打開文件 |
| T | 在新標(biāo)簽頁打開但不切換到那個(gè)標(biāo)簽頁 |
| h | 分屏打開 |
| H | 分屏打開,但焦點(diǎn)停留在ack搜索結(jié)果上 |
| v | 豎直分屏打開 |
| gv | 豎直分屏打開,但焦點(diǎn)停留在ack搜索結(jié)果上 |
| q | 關(guān)閉QuickFix窗口 |
windows
在Windows下安裝它們可以使用Chocolatey,安裝方法如下:首先以管理員權(quán)限打開cmd窗口,然后運(yùn)行下列命令,首先以管理員權(quán)限打開cmd窗口(管理員那個(gè)終端才有效),然后運(yùn)行下列命令
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
安裝完了之后
choco install ack
Mac
brew install ack
如果出現(xiàn)一下亂碼

'perl' 不是內(nèi)部或外部命令,也不是可運(yùn)行的程序
下載安裝ActivePerl,配置環(huán)境變量即可解決此問題。
下載地址
SpaceVim
該配色使用的是gruvbox
如果想更換成此主題
- 在vimrc文件中增加
"gruvbox主題"
Plugin 'morhetz/gruvbox'
set bg=dark
colorscheme gruvbox
然后全局搜索let g:airline_theme,改成如下顏色防止顏色不協(xié)調(diào)
let g:airline_theme = 'dark'
終端運(yùn)行
PluginInstall完成之后,重啟就可以了
怎么打開最進(jìn)打開過的文件
啟動(dòng)Vim的時(shí)候Ctrl+o即可
標(biāo)記
使用標(biāo)記可以快速移動(dòng)。到達(dá)標(biāo)記后,可以用Ctrl+o返回原來的位置。 Ctrl+o和Ctrl+i 很像瀏覽器上的 后退 和 前進(jìn) 。
m{a-z}: 標(biāo)記光標(biāo)所在位置,局部標(biāo)記,只用于當(dāng)前文件。
m{A-Z}: 標(biāo)記光標(biāo)所在位置,全局標(biāo)記。標(biāo)記之后,退出Vim, 重新啟動(dòng),標(biāo)記仍然有效。
`{a-z}: 移動(dòng)到標(biāo)記位置。
‘{a-z}: 移動(dòng)到標(biāo)記行的行首。
`{0-9}:回到上[2-10]次關(guān)閉vim時(shí)最后離開的位置。
`: 移動(dòng)到上次編輯的位置。"也可以,不過`精確到列,而"精確到行 。如果想跳轉(zhuǎn)到更老的位置,可以按C-o,跳轉(zhuǎn)到更新的位置用C-i。
`”: 移動(dòng)到上次離開的地方。
`.: 移動(dòng)到最后改動(dòng)的地方。
:marks 顯示所有標(biāo)記。
:delmarks a b – 刪除標(biāo)記a和b。
:delmarks a-c – 刪除標(biāo)記a、b和c。
:delmarks a c-f – 刪除標(biāo)記a、c、d、e、f。
:delmarks! – 刪除當(dāng)前緩沖區(qū)的所有標(biāo)記。
:help mark-motions 查看更多關(guān)于mark的知識(shí)。
Linux版本中粘貼系統(tǒng)剪切板內(nèi)容失敗
- 首先,查看vim版本是否支持clipboard
vim --version | grep "clipboard"

clipboard前面有一個(gè)小小的減號(hào),說明不支持。
如果不支持的話,需要安裝圖形化界面的vim,或者重新編譯vim
sudo apt-get install vim-gnome
安裝完成后再次執(zhí)行:
vim --version | grep "clipboard"
發(fā)現(xiàn)已經(jīng)支持clipboard
那么我們的目的是要復(fù)制到系統(tǒng)剪切板則需要選中內(nèi)容后輸入命令:"+y
粘貼到特定的寄存器也是同理。例如"+p將系統(tǒng)剪切板的內(nèi)容拷貝到vim中(非編輯模式下)。
快速跳轉(zhuǎn)插件Easymotion
配置如下:
let g:EasyMotion_smartcase = 1
"let g:EasyMotion_startofline = 0 " keep cursor colum when JK motion
map <Leader><leader>h <Plug>(easymotion-linebackward)
map <Leader><Leader>j <Plug>(easymotion-j)
map <Leader><Leader>k <Plug>(easymotion-k)
map <Leader><leader>l <Plug>(easymotion-lineforward)
" 重復(fù)上一次操作, 類似repeat插件, 很強(qiáng)大
map <Leader><leader>. <Plug>(easymotion-repeat)
- 用法1: 跳轉(zhuǎn)到當(dāng)前光標(biāo)前后的位置(w/b)
- 用法2: 搜索跳轉(zhuǎn)(s)
- 用法3: 行級(jí)跳轉(zhuǎn)(jk)
- 用法4: 行內(nèi)跳轉(zhuǎn)(hl)
- 用法5: 重復(fù)上一次動(dòng)作(.)
建議
1.還可以<Leader><leader>f和<Leader><leader>t, 不過建議簡單化, 一個(gè)<Leader><leader>w/b走天下.
2.如果你不經(jīng)常使用s, 可以將s改鍵, nmap s <Plug>(easymotion-s), 這樣你只需要輸入s就可以進(jìn)行搜索快速跳轉(zhuǎn)(強(qiáng)迫癥表示不能忍....)
具體做法見官方文檔
3.默認(rèn)<leader><leader>作為這個(gè)插件的快捷鍵其實(shí)挺好的, 貌似沒有其他插件會(huì)導(dǎo)致沖突, 還可以配置一整套, 強(qiáng)迫癥很滿意
4.可以配置2/n個(gè)字符的搜索跳轉(zhuǎn), 更精準(zhǔn), 按需自取(個(gè)人覺得太復(fù)雜了沒必要) 文檔和文檔
5.這個(gè)插件專心做好跳轉(zhuǎn)就好, 沒必要把搜索的活給做了
Vim窗口切換
鼠標(biāo)在各個(gè)窗口間循環(huán)移動(dòng):
ctrl+w+(小寫的 hjkl), "非線性"的跳轉(zhuǎn)的: ctrl_w+t(top : 左上角, +b: bottom, 右下角), p: preview: 上一個(gè)子窗口.
set mouse=a 所有all 的狀態(tài)下都可以使用 鼠標(biāo)..
窗口本身的位值的移動(dòng):
ctrl_w + r: 窗口本身, 不是鼠標(biāo)指針順時(shí)針 (向下, 向右 移動(dòng)), R : 則是逆時(shí)針反方向(向上, 向左)移動(dòng).
ctrl_w+x: 左右上下對(duì)應(yīng)位置的窗口 對(duì)調(diào). 要注意窗口必須是 對(duì)應(yīng)的, 如果不對(duì)應(yīng)將無法對(duì)換, 比如左邊一個(gè)大窗口, 右邊有兩個(gè)小的 子窗口, 則左右不能互換.
窗口本身 的位置移動(dòng), 而且大小也發(fā)生"最大化"變化
Ctrl_w+ HJKL( 注意是大寫的字母 H, J, K, L , 表示要按shift才能實(shí)現(xiàn)的)... 要注意, 可以通過 windows 窗口 "貼邊" 最大化來理解, H和 L 就是 向左或向右 最大化貼邊 顯示; 而 JK 則是 向上 或 向下 貼邊 最大化顯示. 最大化后 就不能 再次操作復(fù)原窗口了, 其實(shí)也沒有必要
調(diào)整窗口的水平/垂直尺寸?
用ctrl+ w 結(jié)合 >, <調(diào)整水平尺寸, 用+ - 調(diào)整垂直尺寸, 這個(gè)是微調(diào). 也可以用純粹的命令用 :resize +/- n, 或者 vertical resize +/- n (支持命令簡寫, 但是要能夠使命令被唯一確定才行. 通常要用5,10,15, 20的大小間隔來調(diào)...太小了沒有意義)
除了這些調(diào)整/ 遍歷鼠標(biāo)的方法, 還有一個(gè)關(guān)閉子窗口的問題. 關(guān)閉的方式, 除了命令外, 還有窗口關(guān)閉 的方式: 用ctrl+w + q(quit), c(close), o(other)等.
VIM注釋插件nerdcommenter
使用:
1、 \cc 注釋當(dāng)前行和選中行
2、 \cn 沒有發(fā)現(xiàn)和\cc有區(qū)別
3、 \c<空格> 如果被選區(qū)域有部分被注釋,則對(duì)被選區(qū)域執(zhí)行取消注釋操作,其它情況執(zhí)行反轉(zhuǎn)注釋操作
4、 \cm 對(duì)被選區(qū)域用一對(duì)注釋符進(jìn)行注釋,前面的注釋對(duì)每一行都會(huì)添加注釋
5、 \ci 執(zhí)行反轉(zhuǎn)注釋操作,選中區(qū)域注釋部分取消注釋,非注釋部分添加注釋
6、 \cs 添加性感的注釋,代碼開頭介紹部分通常使用該注釋
7、 \cy 添加注釋,并復(fù)制被添加注釋的部分
8、 \c$ 注釋當(dāng)前光標(biāo)到改行結(jié)尾的內(nèi)容
9、 \cA 跳轉(zhuǎn)到該行結(jié)尾添加注釋,并進(jìn)入編輯模式
10、\ca 轉(zhuǎn)換注釋的方式,比如: /**/和//
11、\cl \cb 左對(duì)齊和左右對(duì)其,左右對(duì)其主要針對(duì)/**/
12、\cu 取消注釋
It requires Vim 7.3.885 or later with Lua support (“+lua”)
方案一:
brew install vim --with-lua
方案二:
brew uninstall vim
brew install luajit
brew install vim --with-luajit