刻意练习Vim30天,可以键指如飞嘛?

这是我参与 8 月更文挑战的第 7 天,活动详情查看:8 月更文挑战

image.png

image.png

DeliberatePracticeVimIn30Days

刻意练习Vim30天能达到什么效果,是麻瓜,还是成神?

本人使用Vim编程方式来开发已经有3年的经验,但是虽然有三年经验,但也仅仅是使用到Vim比较常用的快捷编辑方式而已,虽然只是懂得这冰山一角,但是已经让我在开发效率上面有了很大的提高,由于本人从事的是Android,还有前端开发,虽然用的是IDE,但是并不影响我使用Vim插件来开发,所以为了更好的发挥Vim的编程优势,还有提高自己的编码效率,于是乎就有了这个仓库。

本人非常喜欢并且崇拜Bisqwit敲代码,那种代码在屏幕上快速输出,键指如飞的潇洒,还有喜欢GeoHotz使用Vim敲代码的样子,所以本人也暗下励志要成为像他们一样的人,可能做不到他们的那般优秀,但是这并不影响我离他们更近。

资源名称 简介
七个高效的文本编辑习惯 作者:Bram Moolenaar(即 Vim 的作者)
《 Vim 实践 (第 2 版)》 轻取 Vim 最佳书籍
Vim用户手册中文版72 Vim用户手册
Modern.Vim.2018.5 现代Vim

本人第一次使用的Vim项目是spf13-vim,当初搜Github项目的时候就属它Star最多,后面国人有个项目叫SpaceVim,作者也是一个比较厉害的人,以前每天都能看到他每天满满提交页面。因为项目集成的插件比较多,我印象中的spf13光是插件就有七八十个,启动起来不算卡,但是很多插件都是自己没用过的,自己也没怎么理会了。

本人关于Vim的推荐是先尝试使用别人弄好的Vim dotfiles,因为别人的配置比你的白板强太多了,vim之所以强是因为它有很多插件,就像变形金刚一样自己组装,但是如果你什么都不安装,那么你用Vim真的还不如使用IDE来的快。先尝试使用别人的项目,对Vim操作先熟悉起来,然后再根据自己的需要,定制合适自己的Vim,安装自己需要的插件。

常用Vim插件推荐,更多插件刻意查看vimawesome

资源名称 简介
fugitive-vim fugitive.vim: A Git wrapper so awesome, it should be illegal
surround-vim surround.vim: quoting/parenthesizing made simple
nerdtree A tree explorer plugin for vim
vim-airline lean & mean status/tabline for vim that’s light as air
vimawesome

关于本人之前折腾Vim的记录

Vim折腾帖子

Day01

下载安装NeoVim

NeoVim官网

  • Download nvim-macos.tar.gz
  • Extract: tar xzvf nvim-macos.tar.gz
  • Run ./nvim-osx64/bin/nvim

因为没有桌面快捷启动方式,于是我就在.zshrc文件里面映射了快捷启动方式

# NeoVim
alias nvim='./nvim-osx64/bin/nvim'
复制代码

每次我只需要在终端里面输入nvim就刻意快速打开NeoVim

与Vim的区别

~/.vimrc 对应 $CONFIG_HOME/nvim/init.vim

~/.vim 对应 $CONFIG_HOME/nvim

复制代码

Neovim 是能使用 vim 的配置文件的,如果有 vim 的配置,直接软链接就好:

$(~) ln -s ~/.vim .config/nvim
$(~) ln -s ~/.vimrc .config/nvim/init.vim

复制代码

如果想 nvim 单独使用一个配置,那就在 .config 下创建配置文件就行:

$(~) mkdir .config/nvim
$(~) touch .config/nvim/init.vim
复制代码

之前spf-13项目用的插件安装方式是Vundle,为了体验别的方式这里就更换成为VimPlug来安装插件
第一天先安装一些常用的插件:

- Finishing ... Done!                                                                                                 │~
- fzf: Already installed                                                                                              │~
- ctrlp.vim: Already installed                                                                                        │~
- vim-airline: Already installed                                                                                      │~
- tagbar: Already installed                                                                                           │~
- nerdtree: Already installed                                                                                         │~
- fzf.vim: Already installed                                                                                          │~
- vim-instant-markdown: Already installed                                                                             │~
- gruvbox: Already installed
- vim-easymotion: Already installed

复制代码

Day2

自定义一些常用的快捷键

自定义一些常用的快捷键,但是遇到按键不起作用的问题,查找了很多资料都没找到是什么原因,最后才发现原来是自己的操作不当引起的,这个不是组合按键而是,静默按1s后组合触发按键

发现在iterm2里面启动的nvim设置meta键位是没有作用的,这个是一直存在的问题,查找一下资料看看有没有什么比较好的解决方式

解决方式:[在iterm设置中将left Option设置成Esc+这样子就可以了]

silent 代表不回显,静默的意思

还有学习到了一些简单的Vim功能脚本的使用方法

比如:

function! DateAndTime()
    redraw
    echohl WarningMsg
        echo strftime("   ⏰ 現在時間 %Y-%m-%d %H:%M:%S ⏰ ")
    echohl NONE
endfunction


" 输入xtime 然后按一下tab按键就可以显示时间了 2020-07-29 16:23:13
iab xtime <c-r>=strftime("%Y-%m-%d %H:%M:%S")<cr>

nnoremap <M-t> :call DateAndTime()<CR
复制代码

就能简单快速的输出当前的时间

第二天的init.vim文件如下

"设置相对行号
set relativenumber

:let mapleader = ","
:let g:mapleader = ","

call plug#begin('~/.vim/plugged')

" vim-airline
Plug 'vim-airline/vim-airline'

" colorscheme gruvbox
Plug 'morhetz/gruvbox'

" nerdtree
Plug 'preservim/nerdtree'

" Tagbar
Plug 'majutsushi/tagbar'

" ctrlp
Plug 'ctrlpvim/ctrlp.vim'

" MarkdownPreview
Plug 'suan/vim-instant-markdown', {'for': 'markdown'}

" Fzf Vim
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
set rtp+=/usr/local/opt/fzf
Plug '/usr/local/opt/fzf'


" easymotion
Plug 'easymotion/vim-easymotion'

" wakatime
Plug 'wakatime/vim-wakatime'


call plug#end()


exec 'cd ' . fnameescape('/Users/itgoyo/Documents/Vim')



" use ctrl+hjkl switch window
" nnoremap <C-l> <C-w>l   这种用法没效果因为已经被方向快捷键拦截了
:noremap <leader>h <C-w>h
:noremap <leader>j <C-w>j
:noremap <leader>k <C-w>k
:noremap <leader>l <C-w>l
"使用leader+w 直接保存
inoremap <leader>w <Esc>:w<cr>
noremap <leader>w :w<cr>

"noremap <D-S> :w<cr>
"noremap <leader>s :w<cr>
":noremap <leader>s :w<cr>
:noremap <leader>p :MarkdownPreview<cr>

"stackoverflow 上面绑定ctrl+s 为保存的回答

noremap <silent> <C-S>          :update<CR>
vnoremap <silent> <C-S>         <C-C>:update<CR>
inoremap <silent> <C-S>         <C-O>:update<CR>

"解决insert模式切换回normal模式下延迟的问题
set timeoutlen=1 ttimeoutlen=0


" install easy-motion
" Plugin 'easymotion/vim-easymotion'




"Mode Settings

let &t_SI.="\e[5 q" "SI = INSERT mode
let &t_SR.="\e[4 q" "SR = REPLACE mode
let &t_EI.="\e[1 q" "EI = NORMAL mode (ELSE)

"Cursor settings:

"  1 -> blinking block
"  2 -> solid block
"  3 -> blinking underscore
"  4 -> solid underscore
"  5 -> blinking vertical bar
"  6 -> solid vertical bar



"let &t_SI = "<Esc>]50;CursorShape=1\x7"
"let &t_SR = "<Esc>]50;CursorShape=2\x7"
"let &t_EI = "<Esc>]50;CursorShape=0\x7"




"MarkdownPreview
"let g:instant_markdown_port = 8888

" 退出插入模式指定类型的文件自动保存
au InsertLeave *.go,*.sh,*.php,*.java,*.py,*.md,*.txt,*.html write

" colorscheme
set bg=dark
colorscheme gruvbox

" NERDTree
 map <C-e> :NERDTreeToggle<CR>

" Tagbar
 nmap <C-t> :TagbarToggle<CR>
 " Tagbar
nmap <silent> <leader>tb :TagbarToggle<cr>

" fzf
" Always enable preview window on the right with 60% width
let g:fzf_preview_window = 'right:60%'

nmap <C-z> :Files<CR>
nmap <C-u> :Buffers<CR>


" <Leader>f{char} to move to {char}
nmap <Leader>f <Plug>(easymotion-overwin-f)

" s{char}{char} to move to {char}{char}
nmap s <Plug>(easymotion-overwin-f)

"nmap <Leader>w <Plug>(easymotion-overwin-w)



" 切换buffer
" Buffer Navigation
nmap <C-[> :bprevious<CR>
nmap <C-]> :bnext<CR>
nmap <M-[> :bprevious<CR>
nmap <M-]> :bnext<CR>

nnoremap <Tab> :bnext<CR>
nnoremap <S-Tab> :bprevious<CR>


" 让输入上方,搜索列表在下方
    let $FZF_DEFAULT_OPTS = '--layout=reverse'

    " 打开 fzf 的方式选择 floating window
    let g:fzf_layout = { 'window': 'call OpenFloatingWin()' }

    function! OpenFloatingWin()
  let height = &lines - 3
  let width = float2nr(&columns - (&columns * 2 / 10))
  let col = float2nr((&columns - width) / 2)

  " 设置浮动窗口打开的位置,大小等。
  " 这里的大小配置可能不是那么的 flexible 有继续改进的空间
  let opts = {
        \ 'relative': 'editor',
        \ 'row': height * 0.3,
        \ 'col': col + 30,
        \ 'width': width * 2 / 3,
        \ 'height': height / 2
        \ }

  let buf = nvim_create_buf(v:false, v:true)
  let win = nvim_open_win(buf, v:true, opts)

  " 设置浮动窗口高亮
  call setwinvar(win, '&winhl', 'Normal:Pmenu')

  setlocal
        \ buftype=nofile
        \ nobuflisted
        \ bufhidden=hide
        \ nonumber
        \ norelativenumber
        \ signcolumn=no
endfunction


set modifiable

syntax on " 自动语法高亮

" 键位绑定  Keymap

"<k0> - <k9> 小键盘 0 到 9
"<S-...> Shift+键
"<C-...> Control+键
"<M-...> Alt+键 或 meta+键
"<A-...> 同 <M-...>
"<Esc> Escape 键
"<Up> 光标上移键
"<Space> 插入空格
"<Tab> 插入 Tab
"<CR> 等于 <Enter>
"<D> Command


" 窗口快速切换切换
nmap J <C-w>j
nmap H <C-w>h
nmap K <C-w>k
nmap L <C-w>l
nmap W <C-w>w
" 括号自动不全
inoremap ( (<CR>)<Esc>O
inoremap [ [<CR>]<Esc>O
inoremap { {<CR>}<Esc>O



" 時間顯示 http://vim.wikia.com/wiki/Insert_current_date_or_time
function! DateAndTime()
    redraw
    echohl WarningMsg
        echo strftime("   ⏰ 現在時間 %Y-%m-%d %H:%M:%S ⏰ ")
    echohl NONE
endfunction
nnoremap <M-t> :call DateAndTime()<CR>

" 输入xtime 然后按一下tab按键就可以显示时间了 2020-07-29 16:23:13
iab xtime <c-r>=strftime("%Y-%m-%d %H:%M:%S")<cr>
复制代码

Day03

原本昨天以为解决了键的问题,但是事实上并不是这样子的,昨天只是碰巧能触发而已,并不能随时触发,真正影响键位功能的是因为一句话引起的

"解决insert模式切换回normal模式下延迟的问题 这货会影响leader的事件触发,最好别用 浪费我很多时间
"set timeoutlen=1 ttimeoutlen=0
复制代码

去掉之后现在关于相关的组合键位都能正常使用了

配置相关的已经提交到Github上面去了

现在终于可以正式入门Vim还有自定义一些属于自己的快捷键了,美滋滋,下面的日子就是学习快速跳转,还有窗口切换相关的事情,再者就是Vim的快捷键训练

Vim-Go

到Go官网下载安装Go得安装包,然后在自己的.zshrc文件里面配置好环境变量

export PATH=$HOME/bin:/usr/local/go/bin:$PATH
复制代码

init.vim中添加

" Vim-GO
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
复制代码

然后在Vim里面:GoInstallB...
如果提示guru,依然提示 "could not find 'guru'. Run :GoInstallBinaries to fix it

 go get   golang.org/x/tools/cmd/guru
 go build golang.org/x/tools/cmd/guru
 mv guru $(go env GOROOT)/bin
复制代码

Day04

  • Vim-Ranger
" Vim-Ranger
Plug 'francoiscabrol/ranger.vim'
Plug 'rbgrouleff/bclose.vim'
复制代码
  • Vim-Rainbow
" Rainbow
Plug 'luochen1990/rainbow'
复制代码
  • Vim-css-color
" Color
Plug 'ap/vim-css-color'
复制代码

=======

快速加符号的插件

Normal mode

ds  – delete a surrounding
cs  – change a surrounding
ys  – add a surrounding
yS  – add a surrounding and place the surrounded text on a new line + indent it
yss – add a surrounding to the whole line
ySs – add a surrounding to the whole line, place it on a new line + indent it
ySS – same as ySs

Visual mode

s   – in visual mode, add a surrounding
S   – in visual mode, add a surrounding but place text on new line + indent it

Insert mode

– in insert mode, add a surrounding
– in insert mode, add a new line + surrounding + indent
s – same as
S – same as
示例

复制代码
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享