vim的基本使用

说明:vim是一个很强大的编辑器,建议掌握基础使用方法即可,不要过于沉迷:vim有一套专门的语言来编写vim插件,vim也可以配置各种各样的插件打造成IDE,但是不建议在这上面花时间。把时间花在学习算法,学习编程,学习各种找工作实打实的硬技术上,而不是花在花里胡哨的地方(基本使用可以了解了解,装插件建议不要要搞了,pycharm、idea才是yyds)。

1: r !ls
2.i不移位(在前写入字符)
a右移一位(在前写入字符)
o另起一行(三者按Esc都向前移一位)
3.建议把CapsLK改为Esc
4.shift+a(行尾插入)
shift+i(行首插入)
shift+o(在上一行新加一行并写入)

5.~/.vim/vimrc为配置文件
5-1.noremap a b即vim中按a键相当于按了b键(nore意为非递归)
5-2.map S :wq(CR意为回车)
5-3.map s (nop意为no operation,即无效指令)
5-4.map R :source $MYVIMRC(加载vimrc文件)(这个我不能用)
5-5.syntax on 高亮
5-6.set number显示行号(set nu亦可)
5-7.set nonumber不显示行号(set nonu亦可)
5-8.set relativenumber(相对行号)
5-9.set cursorline(设置光标线)
5-10.set showcmd(右下角显示)
5-11.set wildmenu(命令模式下提示菜单)
5-12.set ai(自动缩进)

6.:vsp filename左右分屏<或vspit>(ctl+w跳屏)
:split filename上下分屏(:q 退出)

7.vim的一个规律 ,即动作加被执行者
7-1.x删除当前位置字符(与delete作用有相似之处)
7-2.“d” and number and “->” or “<-” 意为剪切或删除
7-3.dd删除当前光标所在行
7-4.p为粘贴操作,即paste
7-5.“y” and number and “->” or “<-” 意为复制(与d用法类似)
7-6.yy复制当前光标所在行
7-7.w调到下一个"单词首",e跳到下一个"单词尾",跳到上一个"单词首"
7-8.“c” and number and “->” or “<-” 意为剪切或删除,同时进入写入模式
7-9.cw删除该单词,即change word(当你处于词首)
7-10.ciw删除该单词,即change in word(当你处于词中)
7-11.例7-10中w可以灵活去改变,例< ci" >,同理w换为y或d
7-12.0跳至行首,shift+0跳至段尾
7-13.f and charctor,即find,可以用来查找该行下一个出现的特定字符
7-14.同时f可以分别和d、y或c搭配使用,例< df: >
7-15. /charctor 来查找字符,n下一个,N上一个。
7-16.set hlsearch 查找高亮
set incseach 查找时高亮
exec “nohlsearch” 默认先执行"不高亮"(exec “x"即执行 :x)
7-17.set ignorecase 搜小写,大小写都出
set smartcase 搜大写,只出大写
7-18.let mapleader=” " 设置该建为空格
noremap :nohlsearch 设置空格加回车为取消高亮
7-19.:color 加 tab键 来切换颜色

注:终端输入vimtutor可以看关于vim详细教程
一.visual可视模式(三种模式与基础操作配合有神效)
1.普通可视模式(v进入)
2.可视行模式(大写V进入)
2-1.进入可视行模式然后“ 输入冒号接normal I接要往开头加的东西”
2-2.进入可视行模式然后“ 输入冒号接normal A接要往末尾加的东西”
2-3.ggVG全选(gg文首,G文尾)
3.可视块模式(ctl+v进入)
3-1.可视块模式下也可按G来提高效率
3-2.进入可视块模式后,shift+i来批量添加,c来批量替换(最后加ESC)

1.vim黏贴n编:np(例30p)

二、可视行模式下,批量执行命令
:norm $cs"’
:Tabularize /= 排版(等号排一排)
录制宏
函数跳转
coc 强大

这里放一下vim配置文件的大概样子,可以了解了解,但是不要过于花时间:

let mapleader=" "
set number
map S :wq<CR>
"map s <nop>
syntax on
set norelativenumber
set cursorline
set showcmd
set wildmenu
set ai
set hlsearch
set incsearch
exec "nohlsearch"
map R :source ~/.vim/vimrc<CR>
set ignorecase
set smartcase
noremap <LEADER><CR> :nohlsearch<CR>


map h  :vertical resize-5<CR>
map l :vertical resize+5<CR>
map j :res +5<CR>
map k :res -5<CR>

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

Plug 'vim-airline/vim-airline'
Plug 'connorholyday/vim-snazzy'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'preservim/nerdtree'
Plug 'kien/ctrlp.vim'
Plug 'easymotion/vim-easymotion'
Plug 'Yggdroot/indentLine'


call plug#end()


let g:SnazzyTransparent = 1
color  snazzy






" if hidden is not set, TextEdit might fail.
set hidden

" Some servers have issues with backup files, see #649
set nobackup
set nowritebackup

" Better display for messages
set cmdheight=2

" You will have bad experience for diagnostic messages when it's default 4000.
set updatetime=300

" don't give |ins-completion-menu| messages.
set shortmess+=c

" always show signcolumns
set signcolumn=yes

" Use tab for trigger completion with characters ahead and navigate.
" Use command ':verbose imap <tab>' to make sure tab is not mapped by other plugin.
inoremap <silent><expr> <TAB>
      \ pumvisible() ? "\<C-n>" :
      \ <SID>check_back_space() ? "\<TAB>" :
      \ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"

function! s:check_back_space() abort
  let col = col('.') - 1
  return !col || getline('.')[col - 1]  =~# '\s'
endfunction

" Use <c-space> to trigger completion.
inoremap <silent><expr> <c-space> coc#refresh()

" Use <cr> to confirm completion, `<C-g>u` means break undo chain at current position.
" Coc only does snippet and additional edit on confirm.
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
" Or use `complete_info` if your vim support it, like:
" inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"

" Use `[g` and `]g` to navigate diagnostics
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)

" Remap keys for gotos
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)

" Use K to show documentation in preview window
nnoremap <silent> K :call <SID>show_documentation()<CR>

function! s:show_documentation()
  if (index(['vim','help'], &filetype) >= 0)
    execute 'h '.expand('<cword>')
  else
    call CocAction('doHover')
  endif
endfunction

" Highlight symbol under cursor on CursorHold
autocmd CursorHold * silent call CocActionAsync('highlight')

" Remap for rename current word
nmap <leader>rn <Plug>(coc-rename)

" Remap for format selected region
xmap <leader>f  <Plug>(coc-format-selected)
nmap <leader>f  <Plug>(coc-format-selected)

augroup mygroup
  autocmd!
  " Setup formatexpr specified filetype(s).
  autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
  " Update signature help on jump placeholder
  autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end

" Remap for do codeAction of selected region, ex: `<leader>aap` for current paragraph
xmap <leader>a  <Plug>(coc-codeaction-selected)
nmap <leader>a  <Plug>(coc-codeaction-selected)

" Remap for do codeAction of current line
nmap <leader>ac  <Plug>(coc-codeaction)
" Fix autofix problem of current line
nmap <leader>qf  <Plug>(coc-fix-current)

" Create mappings for function text object, requires document symbols feature of languageserver.
xmap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap if <Plug>(coc-funcobj-i)
omap af <Plug>(coc-funcobj-a)

" Use <TAB> for select selections ranges, needs server support, like: coc-tsserver, coc-python
nmap <silent> <TAB> <Plug>(coc-range-select)
xmap <silent> <TAB> <Plug>(coc-range-select)

" Use `:Format` to format current buffer
command! -nargs=0 Format :call CocAction('format')

" Use `:Fold` to fold current buffer
command! -nargs=? Fold :call     CocAction('fold', <f-args>)

" use `:OR` for organize import of current buffer
command! -nargs=0 OR   :call     CocAction('runCommand', 'editor.action.organizeImport')

" Add status line support, for integration with other plugin, checkout `:h coc-status`
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}

" Using CocList
" Show all diagnostics
nnoremap <silent> <space>a  :<C-u>CocList diagnostics<cr>
" Manage extensions
nnoremap <silent> <space>e  :<C-u>CocList extensions<cr>
" Show commands
nnoremap <silent> <space>c  :<C-u>CocList commands<cr>
" Find symbol of current document
nnoremap <silent> <space>o  :<C-u>CocList outline<cr>
" Search workspace symbols
nnoremap <silent> <space>s  :<C-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent> <space>j  :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent> <space>k  :<C-u>CocPrev<CR>
" Resume latest coc list
nnoremap <silent> <space>p  :<C-u>CocListResume<CR>






nnoremap <leader>v :NERDTreeFind<CR>
nnoremap <leader>g :NERDTreeToggle<CR>
let NERDTreeShowHidden=1
let NERDTreeIgnore=[]
"autocmd vimenter * NERDTree


let g:ctrlp_map = '<c-p>'
"ctl+p 来快速查找当前所在目录下文件

nmap s <Plug>(easymotion-s2) 
"s来快速查找

  
inoremap ( ()<left>
inoremap [ []<left>
inoremap { {}<left>
inoremap ' ''<left>
inoremap " ""<left>
inoremap ) <right>
inoremap ] <right>
inoremap } <right>
"inoremap > <right>
"inoremap < <><left>



版权声明:本文为qq_44821149原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。