Skip to content

Instantly share code, notes, and snippets.

@zlin888
Last active February 21, 2023 00:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zlin888/8fca29939963a5967cbaade89d7a3c88 to your computer and use it in GitHub Desktop.
Save zlin888/8fca29939963a5967cbaade89d7a3c88 to your computer and use it in GitHub Desktop.
vim_cheatsheet
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
vim +PluginInstall +qall

VIM Frequently-used Commands & Configuration

The ultimate Vim configuration: vimrc

https://github.com/amix/vimrc

highlight search results :set hlsearch
temporarily hide highlight until the next search :noh
traverse word backward b

Typing % while the cursor is on a (,),[,],{, or } goes to its match.
To substitute new for the first old in a line type :s/old/new
To substitute new for all 'old's on a line type :s/old/new/g

VIM in VSCode

https://github.com/VSCodeVim/Vim

File explorer

Open File explorer: shift+cmd+e
Open file: enter
Open file on a new split: ctrl+enter
Rename file: cmd+enter
New file: cmd+n
New folder: cmd+f

Terminal

Toggle Terminal: cmd+j or ctrl+`

netrw

:Explore - opens netrw in the current window
:Sexplore - opens netrw in a horizontal split
:Vexplore - opens netrw in a vertical split

https://shapeshed.com/vim-netrw/

netrw ignore certain files

https://stackoverflow.com/questions/4170887/vimrc-setting-to-ignore-file-types-in-netrw

splits

Navigation C-HJKL changed

Split vertically :vsp
Split horizontally :sp

:10sp and :vsp path/to/file is allowed

https://thoughtbot.com/blog/vim-splits-move-faster-and-more-naturally

Ctrl-w n+ Increase size of current split by n lines
Ctrl-w n- Decrease size of current split by n lines
Ctrl-w n< (For vertical)
Ctrl-w n>

To resize all windows to equal dimensions based on their splits, you can use Ctrl-w =.
To increase a window to its maximum height, use Ctrl-w _.
To increase a window to its maximum width, use Ctrl-w |.

https://vim.fandom.com/wiki/Resize_splits_more_quickly

Tab

To move to the next tab: gt
To move to the previous tab: gT

https://webdevetc.com/blog/tabs-in-vim

My configuration: map tn :tabnew
map t :tabnext
map tm :tabmove
map tc :tabclose
map to :tabonly

##Plug Manager

https://github.com/junegunn/vim-plug

set nocompatible " be iMproved, required
set number
syntax on
" ######################################################### Vundle
filetype off " required
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'easymotion/vim-easymotion'
Plugin 'vim-airline/vim-airline'
Plugin 'ctrlpvim/ctrlp.vim'
Plugin 'rking/ag.vim'
call vundle#end() " required
filetype plugin indent on " required
" ######################################################### EsayMotion
let g:EasyMotion_do_mapping = 0 " Disable default mappings
" Jump to anywhere you want with minimal keystrokes, with just one key
" binding.
" `s{char}{label}`
nmap s <Plug>(easymotion-overwin-f)
" or
" `s{char}{char}{label}`
" Need one more keystroke, but on average, it may be more comfortable.
nmap s <Plug>(easymotion-overwin-f2)
" Turn on case-insensitive feature
let g:EasyMotion_smartcase = 1
" JK motions: Line motions
map <Leader>j <Plug>(easymotion-j)
map <Leader>k <Plug>(easymotion-k)
" ######################################################### Buffer
" This allows buffers to be hidden if you've modified a buffer.
" This is almost a must if you wish to use buffers in this way.
set hidden
" To open a new empty buffer
" This replaces :tabnew which I used to bind to this mapping
nmap <leader>T :enew<cr>
" Move to the next buffer
nmap <leader>l :bnext<CR>
" Move to the previous buffer
nmap <leader>h :bprevious<CR>
" Close the current buffer and move to the previous one
" This replicates the idea of closing a tab
nmap <leader>bq :bp <BAR> bd #<CR>
" Show all open buffers and their status
nmap <leader>bl :ls<CR>
" ######################################################### air-line
" This allows buffers to be hidden if you've modified a buffer.
" Enable the list of buffers
let g:airline#extensions#tabline#enabled = 1
" Show just the filename
let g:airline#extensions#tabline#fnamemod = ':t'
" ######################################################### CtrlP
let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd = 'CtrlP'
let g:ctrlp_working_path_mode = 'r'
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/](\.(git|hg|svn)|\_site)$',
\ 'file': '\v\.(exe|so|dll|class|png|jpg|jpeg)$',
\}
@zlin888
Copy link
Author

zlin888 commented Feb 21, 2023

"""""" VUNDLE
set nocompatible " be iMproved, required
filetype off " required
set rtp+=~/.vim/bundle/Vundle.vim

call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'kien/ctrlp.vim'
Plugin 'preservim/nerdtree'
call vundle#end() " required

filetype plugin indent on " required

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment