記錄vim和vi相關
vim和vi相關
有關vim和vi的相關資訊
https://vim.rtorr.com/
https://github.com/kaochenlong/cch/blob/master/README.md
快捷鍵
- 拷貝當前行yy,貼上p, 5yy拷貝5行
- 刪除當前行dd, 5dd刪除5行
- 查找關鍵詞
命令行下/關鍵詞 n是查找下一個位置
- 設置文件的行號和取消文件的行號
命令行下 :set nu set nonu
- 編輯文件到達首行gg , 到達最未行G在正常模式
- 輸入時撒消動作u,在正常模式
- 將光標移到指定的行數 13G
(1) 花式插入模式
i -> 在光標前插入
I -> 在句子前插入
a -> 在光標後插入
A -> 在句子後插入
o -> 在當前行下插入一行
O -> 在當前行上插入一行
(2) 花式移動光標
0 -> 數字零,到行頭
$ -> 到本行行尾
(3) visual
ctrl+v d刪除 shift+i 加入 esc兩次
shift+v
一般vim設定檔
1 | " sudo vim .vimrc |
Vim的設定檔
命令
1 | # 重新載入目前vim的設定檔 |
1 | "設定行號 |
tab還是space?
- set softtabstop=2
使用2個space取代tab - set shiftwidth=2
在>的時候使用2個空格做為縮排 - set expandtab
使用space取代tab
命令
:retab 動新設定文件裡的tab
關於搜尋
- set ignorecase
設定搜尋時不分大小寫 - set incsearch
只要部份關鍵字就有搜尋效果
關於編輯器的樣子
- set showtabline=2
只要有任何分頁都錢秀出來 - set splitbelow
新增水平視窗的時候會出現在下方 - set splitright
新增垂直視窗的時候會出現在右方
工程師的編輯器
- syntax on
打開程式碼語法高亮(幫程式碼上色) - filetype on
偵測檔案型態 - filetype indent on
根據程式種類進行縮排 - filetype plugin on
根㯫程式語言種類載入外掛
以下是參考的設定
1 |
|
Vim的設定之KeyMapping_part1
命令 | Normal Mode | Visual Mode | Insert mode |
---|---|---|---|
map | V | V | |
nmap | V | ||
vmap | V | ||
imap | V |
指令
1 | " 查看特殊鍵 |
- 想把方向鍵的功態關掉,強迫自已使用HJKL來移動游標
1
2:h key-notation
:map <Up> <Nop>
Vim的設定之KeyMapping_part2
map時無窮迴圈
- noremap no recursice mapping
- 什麼時候該用noremap?
如果把原來的功能map用掉了怎麼辦
- Leader 預設值是 \
- 用Leader有什麼好處
1
2" 把Leader設定成逗號
:let mapleader = ","
Vim的設定之KeyMapping_part3
- 設定成舊的vi
1
set nocompatible
- 可檢視目前非預設值的設定
1
:set
- 主題
1
2
3
4colorscheme 列表
" colorscheme ctrl+d
" 如果沒有這個主題
try ... catch ...endtry - 顯示目前游標所在地的狀態
1
set ruler
- 剩下3行就開始捲動
1
set scrolloff=3
- 斷行
1
2
3
4
5
6" 設定如果文字太多的話自動折行
set wrap
set nowrap
" 在比較適當的地方換行
set linebreak - 設定在左下角顯示現在模式
1
set showmode
- 設定顯示敲打了什麼指令
1
set showcmd
- 比較聰渡的搜尋
1
set smarcase
- 設定顯示看不到的東西
1
2set list
set nolist
vim之自動命令
有三個範例
1 | " 視窗切換時候顯示/隱藏游標底線 |
命令
1 | "有關autocmd的事件 |
整理你的 Vim 設定
把設定全部寫在.vimrc有問題嗎?
vim 有一套推薦的規劃
1 | :h vimfiles |
vim的外掛
- 外掛管理工具
1
2
3
4- VimPlug https://github.com/junegunn/vim-plug
- Pathogen https://github.com/tpope/vim-pathogen
- Vundle https://github.com/VundleVim/Vundle.vim
- CSS Color https://github.com/ap/vim-css-color - 外掛夠用就好,用不到的就不要裝
- 建議用Git管理設定
Vim 外掛介紹 part 1
相關連結:
- Vim-Airline https://github.com/vim-airline/vim-airline-themes
- NERDTree https://github.com/scrooloose/nerdtree
- VimAwesome https://vimawesome.com
額外設定:
Vim-AirlineNERDTree1
2let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#enabled = 11
2nnoremap <silent> <F2> :NERDTreeToggle<CR>
let NERDTreeMinimalUI=1
Vim 外掛介紹 part 2
安裝外掛:
- ctrlp https://github.com/ctrlpvim/ctrlp.vim
- emmethttps://github.com/mattn/emmet-vim
- surroundhttps://github.com/tpope/vim-surround
- vim-repeathttps://github.com/tpope/vim-repeat
額外設定:
ctrlp
1 | let g:ctrlp_custom_ignore = { |
Vim 外掛介紹 part 3
- tComment https://github.com/tomtom/tcomment_vim
- vim-ruby https://github.com/vim-ruby/vim-ruby
- vim-rails https://github.com/tpope/vim-rails
- vim-rspec https://github.com/thoughtbot/vim-rspec
額外設定:
- NERDTree 設定:
切換目錄時可以切換起始目錄(Root Directory)
1 | let NERDTreeChDirMode = 2 |
ctrlp 設定:
- 排除不想搜尋的 tmp 目錄。
- 把內建的 grep 換成速度更快的 silver searcher
1 | let g:ctrlp_by_filename = 1 |
需另外安裝 Silver Searcher:
https://github.com/ggreer/the_silver_searcher
參考連結:
Vim 外掛介紹 part 4
- snipMate https://github.com/garbas/vim-snipmate
- tagbar https://github.com/majutsushi/tagbar
- ack https://github.com/mileszs/ack.vim
額外設定:
https://gist.github.com/kaochenlong/a999aee921b477a79fbbb7d251ecff9d
配色
- Molokai https://github.com/tomasr/molokai
- Gruvbox https://github.com/morhetz/gruvbox
- Wombat256 https://github.com/vim-scripts/wombat256.vim
vim的其它
搜尋和取代
1 | :%s/text/cch/g |
vim高見龍參考
- Vim 官方文件 https://www.vim.org/docs.php
- Learn VimScript the Hard Way http://learnvimscriptthehardway.steve…
- Practical Vim https://pragprog.com/book/dnvim2/prac…
- Vimium https://chrome.google.com/webstore/de…
- VimGolf https://www.vimgolf.com
安裝現成設定檔
參考資料
http://wiki.csie.ncku.edu.tw/vim/vimrc?printable
https://stackoverflow.com/questions/58676693/prevent-vscode-from-unfolding-code-when-cursor-moves-past-folded-section
https://www.yuexun.me/blog/the-vim-guide-for-vs-code-users/
https://chengjingchao.com/2020/06/13/VS-Code-%E4%B8%8E-Vim/
將看到脫窗的註解文字 深藍色 改變顏色
1 | shell# vim /home/eric/.vimrc |
這是記錄Vim的顏色的設定
原來的設定有在註解看不清楚,所以來設定一下
下載molokai的配色
先檢查vim安裝的目錄1
whereis vim
在到vim的安裝目錄,會看到vim74或vim73,看你安裝的版本,我的是vim74,在vim74下有目錄是colors,將下載解壓的molokai.vim
放在此,在參考資料下有gitthub,請自行下載,下載後放在colors的目錄下在使用者建立配色
在~目錄建立文件1
vi .vimrc
目前的內容如下
1
2
3
4set t_Co=256
:set nu
:colorscheme molokai
hi Comment ctermfg=lightblue參考資料