What Vim Teaches You?

Reading time: 18 minutes and 46 seconds with 4129 words. 本文总阅读量


vim带给你激情,也给了你生活的智趣,从一开始你练习 Learn-vim-progressively ,并且现在还在练习macro和vim’s text object. 也在不断的学习marks and tags思想,让生活轨迹有迹可循,你使用CtrlSpace来保证你的workspace保存下来,并切换文件和buffer; 随着知识的增长,你使用vimwiki来管理你的知识,并结合 calendar 在vimwiki来管理你的日记。为了让文件查找,文件编辑更加方便, 你使用 shoudo vimfiles 来增强你的vim,使得你的vim变得更像一把瑞士军刀。

  1. Ctrl-Space Plugin
  2. Knowledge tool: Vimwiki
  3. Vimfiles: file operation
  4. Menu for your vim:Startify
  5. Attach File

为了多一点对称美,你使用高丽棒作者 junegunn vim-easy-align (Note: many examples ),为了少犯错误, 你加入了 vim-fat-finger ,使用iabbrev来缩写你需要写的单词,或者修正错误的单词,为了编辑更加有效, 你甚至引入了 vim-multiline-cursor .进一步的你引入了 tpope vim-surround 让你在书写 racket(当然你也可以使用 delimiteMate 补全括号插件)或者lisp代码的时候更加方便一些, 并为了重复或者递归使用,你也引入他的 vim-repeat (vim中的很多插件都是支持增强的,比如f的增强插件 clever-f ); 为了更快捷的编辑文件行,除了使用vim text object, 你也引入了 vim-move vim-easymotion (Very Good)来移动行,使得vim文本更加结构化。

想着让你的vim运行得更快一些,你把你一直用的 vundle 改为了的 junegunn’s vim-plug 来管理你的插件,确没见得有太大的改进,简洁地使用plugins自然就快了。


可以看到你也增加了 Startify 的配置。

然而,上面这些都是你想让vim做的,下面要写的则是vim plugins带给你关于写作的新的概念和思想,这也才是本文的重点。

刚开始接触vim的时候,你是用了scrooloose的 nerdtree , tagbar , vim airline 等, 你也使用了各种 language support vim plugins ,也知道vim使用 tpope vim-gitgutter 结合git管理code, 现在让我们来看第一个vim插件ctrl-space

1.Ctrl-Space Plugin

Github Repo: Click here

vim help: :h ctrlspace


当你在vim中使用:h ctrlspace时候会搜索到这些资料,

【1.vim desktop】: Let's imagine [ Vim ] is a writing desk. 
【2.projects draws】 : Your [ projects ] are like drawers. 
【3.Bookmark  favorite project】:  The [ Bookmark ] List simply displays your favorite projects.
【4.Buffer  paper】: A [ buffer ] is like a sheet of paper lying on the desk. 
        named buffers
        unsaved buffers
【5.workspace  an status snapshot of current project】:All your [ buffers ], [ tabs ], and [ tab ] layouts can be persisted as a workspace.
It's like taking a picture of your desk with an instant camera. You can
save multiple workspaces per project with Workspace List.
【6.workspace  session】 : The word "workspace" can be considered a synonym of a "session". The
ability of having so many sessions available at hand creates a lot of
interesting use cases! For example, you can have a workspace for each task
or feature you are working on. It's very easy to switch from one workspace
to another.


The easiest way to think about tab pages in Vim is to consider them to be viewports, layouts, or workspaces

而且在git的版本中也经常涉及到很多打tag的工作 (git tag  or  git tag  -a)   git checkout某个tag等

其实tags只不过是对事物的一种抽象,这也是你在现实当中经常看到的class field method 注释等等,其实都可以把他们理解为一种tag,一种convinience tag



相同vim tag概念

"" tab encapsulation
" tab 操作
" http://vim.wikia.com/wiki/Alternative_tab_navigation
" http://stackoverflow.com/questions/2005214/switching-to-a-particular-tab-in-vim

" tab切换
map <leader>th :tabfirst<cr>
map <leader>tl :tablast<cr>

map <leader>tj :tabnext<cr>
map <leader>tk :tabprev<cr>
map <leader>tn :tabnext<cr>
map <leader>tp :tabprev<cr>

map <leader>te :tabedit<cr>
map <leader>td :tabclose<cr>
map <leader>tm :tabm<cr>

" normal模式下切换到确切的tab
noremap <leader>1 1gt
noremap <leader>2 2gt
noremap <leader>3 3gt
noremap <leader>4 4gt
noremap <leader>5 5gt
noremap <leader>6 6gt
noremap <leader>7 7gt
noremap <leader>8 8gt
noremap <leader>9 9gt
noremap <leader>0 :tablast<cr>

" Toggles between the active and last active tab "
" The first tab is always 1 "
let g:last_active_tab = 1
" nnoremap <leader>gt :execute 'tabnext ' . g:last_active_tab<cr>
" nnoremap <silent> <c-o> :execute 'tabnext ' . g:last_active_tab<cr>
" vnoremap <silent> <c-o> :execute 'tabnext ' . g:last_active_tab<cr>
nnoremap <silent> <leader>tt :execute 'tabnext ' . g:last_active_tab<cr>
autocmd TabLeave * let g:last_active_tab = tabpagenr()

" 新建tab  Ctrl+t
nnoremap <C-t>     :tabnew<CR>
inoremap <C-t>     <Esc>:tabnew<CR>


Markers will be also used as a storage for `cs_workspaces` (workspaces of
the current project) and `cs_files` (cached files of the current project).

Default value: >

    let g:CtrlSpaceProjectRootMarkers = [
         \ ".git",
         \ ".hg",
         \ ".svn",
         \ ".bzr",
         \ "_darcs",
         \ "CVS"
         \ ]


   A buffer is the in-memory text of a file.
   A window is a viewport on a buffer.
   A tab page is a collection of windows.

A window is a viewport onto a buffer.  You can use multiple windows on one
buffer, or several windows on different buffers.

A buffer is a file loaded into memory for editing.  The original file remains
unchanged until you write the buffer to the file.

#2. Knowledge tool: Vimwiki Github Repo: Click here vimwki setup in vimrc:

" vimwiki  
let g:vimwiki_use_mouse = 1  
let g:vimwiki_list_ignore_newline = 0  
let g:vimwiki_hl_headers = 0  
" vimwiki打开折叠  
"let g:vimwiki_folding = 1  
let g:vimwiki_camel_case = 0  
let g:vimwiki_list_ignore_newline = 0  
let g:vimwiki_CJK_length = 1  

set bsdir=buffer      
"set autochdir  

" 日历插件  
map ca :Calendar<cr>  

map <S-Space> :<C-Space>  

" vimwiki  
let g:vimwiki_list = [{'path': '~/Wiki/wiki/', 'path_html': '~/Wiki/', 'auto_export': 1}]  
" 转化为Html文件  
map <S-F4> :Vimwiki2HTML<cr>  

" 设置颜色  
hi VimwikiHeader1 guifg=#FF0000  
hi VimwikiHeader2 guifg=#00FF00  
hi VimwikiHeader3 guifg=#0000FF  
hi VimwikiHeader4 guifg=#FF00FF  
hi VimwikiHeader5 guifg=#00FFFF  
hi VimwikiHeader6 guifg=#FFFF00  

##vimwiki tagbar 集成

Tagbar integration                                            *vimwiki-tagbar*

As an alternative to the Table of Contents, you can use the Tagbar plugin
(http://majutsushi.github.io/tagbar/) to show the headers of your wiki files
in a side pane.
Download the Python script from
https://raw.githubusercontent.com/vimwiki/utils/master/vwtags.py and follow
the instructions in it.



3. Vimfiles: A tool for file operations

Github Repo: click here

vimfiler setup in vimrc

"for vimfiler
let g:vimfiler_enable_auto_cd=1
"call vimfiler#set_execute_file('txt', 'notepad')
call vimfiler#set_execute_file('txt', 'gvim')
call vimfiler#set_execute_file('c', ['gvim', 'notepad'])

let g:vimfiler_as_default_explorer = 1

" Enable file operation commands.
" Edit file by tabedit.
"call vimfiler#custom#profile('default', 'context', {
"      \ 'safe' : 0,
"      \ 'edit_action' : 'tabopen',
"      \ })

" Like Textmate icons.
let g:vimfiler_tree_leaf_icon = ' '
"let g:vimfiler_tree_closed_icon = '▸'
"let g:vimfiler_tree_opened_icon = '▾'
let g:vimfiler_file_icon = '-'
let g:vimfiler_marked_file_icon = '*'

let g:vimfiler_safe_mode_by_default=0 
  " Use trashbox.
  " Windows only and require latest vimproc.
let g:unite_kind_file_use_trashbox = 1
""  you can create a .vim file, then source it
"need everything.exe
"nnoremap <Leader>f :Unite file buffer file_rec file_mru everything<CR>
nnoremap <Leader>f :VimFiler<CR>
nnoremap <leader>l :Unite line<CR>
let g:unite_source_everything_limit = 100
let g:unite_source_everything_full_path_search = 1
let g:unite_source_everything_posix_regexp_search = 1
let g:unite_source_everything_async_minimum_length = 3
let g:unite_source_everything_cmd_path = 'C:\\Users\\YeZhao\\.vim\\es\\es.exe'

由于vimfiler的使用也了解到了 ag 插件(一个特别好用的搜索插件,在ubuntu底下直接使用ag “expression” 找到当前文件夹所有文件内容 包含表达式的行数据 相当快速)


H作用打开shell  x打开文件夹的意思

&回到project目录  那是相当有用的

N 创建文件



先用m表示选定 然后d删除(重要操作)



:Vimwiki2HTMLConvert current wiki page to HTML
:VimwikiAll2HTMLConvert all your wiki pages to HTML转化为HTML

4. Startify Plugin

Github Repo: click here

##vim 全屏

let w:full_screen=0
    map :call FullScreen()
func! FullScreen()
    if w:full_screen==1
    let w:full_screen=0
    :simalt ~R
    :simalt ~X
    let w:full_screen=1


vim help: :h easyalign

vip= Enter= EnterEnter=(居右,居中,居左对其选项 )


 Delimiter key | Description/Use cases                                              ~
 <Space>       | General alignment around whitespaces
    `:`            | Suitable for formatting JSON or YAML
  `=`            | Operators containing equals sign ( `=` ,  `==,`  `!=` ,  `+=` ,  `&&=` , ...)
  `.`            | Multi-line method chaining
  `,`            | Multi-line method arguments
  `&`            | LaTeX tables (matches  `&`  and  `\\` )
  `#`            | Ruby/Python comments
  `"`            | Vim comments
 <Bar>         | Table markdown

 With visual map   | Description                        | Equivalent command ~
 <Enter><Space>    | Around 1st whitespaces             | :'<,'>EasyAlign\
 <Enter>2<Space>   | Around 2nd whitespaces             | :'<,'>EasyAlign2\
 <Enter>-<Space>   | Around the last whitespaces        | :'<,'>EasyAlign-\
 <Enter>-2<Space>  | Around the 2nd to last whitespaces | :'<,'>EasyAlign-2\
 <Enter>:          | Around 1st colon ( `key:  value` )   | :'<,'>EasyAlign:
 <Enter><Right>:   | Around 1st colon ( `key : value` )   | :'<,'>EasyAlign:<l1
 <Enter>=          | Around 1st operators with =        | :'<,'>EasyAlign=
 <Enter>3=         | Around 3rd operators with =        | :'<,'>EasyAlign3=
 <Enter>*=         | Around all operators with =        | :'<,'>EasyAlign*=
 <Enter>**=        | Left-right alternating around =    | :'<,'>EasyAlign**=
 <Enter><Enter>=   | Right alignment around 1st =       | :'<,'>EasyAlign!=
 <Enter><Enter>**= | Right-left alternating around =    | :'<,'>EasyAlign!**=

##vim-surround 常用命令

1. cs"'
2. cs'"
3. cs'<q>
5. cs"t
4. cst"
6. ds"
7. ysiw"
8. yssb == yss)
9. S"  可视化模式选择快 然后大S这点类似于Multiple-Cursor的Ctrl+N命令

vim copy file name

你使用 vim-copy-filename

"" for vim-copy-filename
nmap <leader>cp :CopyRelativePath<CR>
nmap <leader>cl :CopyRelativePathAndLine<CR>
nmap <leader>cP :CopyAbsolutePath<CR>
nmap <leader>cf :CopyFileName<CR>
nmap <leader>cd :CopyDirectoryPath<CR>


  1. Haya14busa 提供的 incsearch 增加了statusline的查找词当前数 和总个数
  2. Vim-cursorword 表示添加下划线。
  3. AndrewRadev/splitjoin.vim 是提供类似于perl的当行模式的插件[gS gJ]。在scheme估计比较少用到。

一直遗忘的一个快捷查看命令 Ctrl+E 往下滚屏 Ctrl+Y 往上滚屏

运行的话,进入底线命令模式,:!perl %就可以运行,或者可以绑定一个快捷键组合, %表示当前文件的意思



我一个哥们那边,终于有男的出现,我发现我走过的路总是不缺乏女生(所以我是趋向于好色之徒,本来也是), 我梦到了我儿时的


痛苦,才能拥有些许的快乐。Enjoy Painess!但我不想把pain带给亲人,身边的人。我是一个自私的人,没有团队精神,不太会



必然对偶然,自由对随机,自由在必然中,随机在偶然中,原来这才是自由( 胡正自由 是有代价的)。



set editing-mode vi
Control-a: beginning-of-line
Control-b: backward-char
Control-d: delete-char
Control-e: end-of-line
Control-f: forward-char
Control-k: kill-line
Control-n: next-history
Control-p: previous-history
set keymap emacs-ctlx
v: vi-editing-mode
Control-v: "\C-xv\e"
Escape: "\C-xv\e"
set keymap emacs
$if Bash
  Control-w: unix-filename-rubout

Ye Zhaoliang
Engineer of offshore wind turbine technique research

My research interests include distributed energy, wind turbine power generation technique , Computational fluid dynamic and programmable matter.