vim related notes - Serbipunk/notes GitHub Wiki

https://quickref.me/vim

tab -> 4 space

filetype plugin indent on
" show existing tab with 4 spaces width
set tabstop=4
" when indenting with '>', use 4 spaces width
set shiftwidth=4
" On pressing tab, insert 4 spaces
set expandtab

top line gg last line G

disable autoindent

:set noai nocin nosi inde=

previous cursor position

CTRL-o and CTRL-i

replace

在 Vim 中替换字符串可以使用 :s 命令。具体步骤如下:

进入 Vim 编辑器并进入命令模式,即按下 Esc 键。
输入 :%s/old/new/g,其中 old 是要被替换的字符串,new 是替换成的新字符串。
按下回车键,Vim 会将文档中所有匹配的字符串全部替换成新的字符串。

show hex

bin2hex :%!xxd hex2bin :%!xxd -r

copy paste words

  • Place the cursor on the line you want to begin cutting.
  • Press V to select the entire line, or v to select from where your cursor is.
  • Move the cursor to the end of what you want to cut, using h,j,k, or l
  • Press y to copy it, or d to cut it.
  • Place the cursor where you would like to paste your copied stuff.
  • Press P to paste it before your cursor, or p to paste it after the cursor.

link

priv-cursor position

ctrl + o

return cursor

ctrl + i

vim scrolling screen

ctrl + e 向上滚一行(fix cursor at curtain line, just scroll screen line by line)

ctrl + y 向下滚一行 (same as ctrl + e)

ctrl + u 向上滚半屏

ctrl + d 向下滚半屏

link

vim undo and re-undo

undo: u re-undo: ctrl + r

duplicate one line

yy + p dumplicate n line

nyy + p n = 1, 2, 3, 4...

give up change & reload

:edit!

split

:split

:split xxx(要打开的文件名)

join

:join

jump between window

<CTRL+W> k:跳转到上面的窗口 (若为大写K,则是把当前窗口调至上方)

<CTRL+W> j:跳转到下面的窗口 (类似于上)

same line jump by word ? (confusing)

command mode 'b'

set vim indent = 4 space

filetype plugin indent on
set tabstop=4
set shiftwidth=4
set expandtab

link

vim tips and tricks

auto indenting: set autoindent

link

comment & uncomment line in vim

https://stackoverflow.com/questions/2462794/indent-or-comment-several-text-lines-with-vi https://stackoverflow.com/questions/1676632/whats-a-quick-way-to-comment-uncomment-lines-in-vim

vim highlight

:set hlsearch
/search world

:nohlsearch

vim move cursor

With the CTRL-O and CTRL-I command you can go to cursor positions before older jumps, and back again

current vimrc

set number
set tabstop=2
set autoindent
set expandtab
set hlsearch

search current word

ctrl + #

command pipe out vim

cmd | vim -

multiple line editing

https://stackoverflow.com/a/9549765

1 move to position

2 ctrl + v (visual block mode)

3 jump to pos

4 I

5 edit

6 Esc

⚠️ **GitHub.com Fallback** ⚠️