- vim的documentation很爛。看他的documentation真的會瘋掉。好像還是要在網路上找解決方法比較實際。
- 游標的位置是在游標方塊的左邊,按i insert插入的話,會在游標方塊的左邊插入。如果有兩個游標方塊(比如說游標在{或}上時),游標的位置是在比較深色的那個。在Mac上是這樣子。
- p是貼在游標的右方。P是貼在游標的左方。
- select/copy/paste/delete
- select
- 在我的mac上,我可以在vim裡直接用滑鼠選取文字。
- 按shift + 左或右 不能選取文字(重要,跟MS Word不同)
- 按v進visual mode,然後按左右選取。
- 按ctrl + v,按左右加上下選取。
- vi) or vi} or vi" or vi' 選取(), {}, " ", ' ' 內的內容,只要游標在裡面就可以。
- viw can select inner word, cursor anyhwere in the word. And if you continue pressing w, visual mode can continue selecting more words.
- after v select, you can p paste the info in your register to replace the text v selected. Or you can ctrl v to paste the info in your system clipboard. This works on my Mac.
- To paste the content you copy from Vim to other programs, in Vim, press "+y$, this yanks the content to the end of line (y$) into system clipboard, paste into other programs with the usual ctrl v. (在Mac上是cmd v).
- v - select text, delete d, into register, paste elsewhere p.
- ciw - change inner word, word includes underscores but not hyphens
- ci' - change inner content in ' ', without ' '.只要指標在' '裡面就可以。
- ca' - change outer content in ' ', with ' '.
- ci} - change content in { }, without }. 只要指標在{ }裡面就可以。
- ca} - change content in { }, with }
- daw, cursor anywhere in a word, including the space in front of or after the word.
- yaw, cursor anywhere, including the space before or after the word.
- yiw, exclude the space
- vim 跟中文輸入切換有點麻煩。常常是esc切換回normal mode以後按指令,但是在中文輸入狀態,因此指令無效。雖然網路上有一些補包可以安裝,但效果好像不夠好。因為他是設定insert後自動進入中文輸入模式,esc後自動解除中文模式。但有時候insert還是需要英文輸入。目前好像無解。好像是要另一個鍵盤專門輸入中文?
- v virtual mode, $ select whole content to the end of line, this will include the change line character. You can see this by the slight color change of the last cursor. So when you p paste the paste content will include the change line character. So you will change line. To not include the change line character you don't want to include the last empty selection. So when you press $ you hit h to go left one letter to deselect the change line character.
- If cursor is at the left parenthesis, % will go to the matching right parenthesis.
- if cursor is at the left parenthesis, d% will delete till the matching right parenthesis. But if cursor is within the parenthesis, d% will delete from cursor point to the front til matching left bracket backward.
- delete inner bracket - di}, cursor anywhere in the {}.
- redo undo - ctrl +r
- to repeat the search /, press n
- relative line number
" turn relative line numbers on :set relativenumber :set rnu " turn relative line numbers off :set norelativenumber :set nornu " toggle relative line numbers :set relativenumber! :set rnu!
- W, w
- let's say you have \draw[step=0.5in, gray, very thin] and you want to get \draw[very thin]. Put the cursor in step=0.5in and press d2W. Doesn't work.
- m{a-z} mark, ’{a-z} jump to mark. ma - mark position into buffer a. 'a - jump to position a
- dt> - delete till > but without >.
- dT> does not work, to delete including > use df>.
- d/pattern, delete lines from the current position up to a line matching a pattern/string
- d/END, This deletes from the cursor position through the line containing
END. - d/, delete till the next space
- delete until certain line “d{motion}” d/]
Let's say that I have a code like this (
|represents the cursor position):func1(x|, func2(), y);I would like to get:
func1(x|);d])which means delete (
d) to the next unmatched ')' (])).- ctrl v, 4j, $, A, </b>, <esc>, <esc> - append </b> to all four lines.
- * - find the words matching the word under cursor, n - next match
- ctrl + e, y - scroll down one line or up
- how to move cursor upward? ctrl-u doesn’t work if windows mapping is flipped on. make ctrl-U scroll up by mapping
- :w <filename> - save to filename.
- :wq - write and quit
- :q! - force quit without saving.
- 0 - beginning of line
- $ - end of the line
- /<word> - find <word> over the whole document
- vim, recording register are the same as delete register 0~9, to avoid overlapping to record use register a~z.
- "a5yy, yank 5 lines into register a
- "byy, yank one line into register b
- "cyy, yank another line into register c
- "ap, paste 5 lines from register a
- "bp, paste one line from register b
- "cp, paste another line from register c
- I get this is how it works with delete but curious if this is an issue I'm causing by the order I do things. Is it better to delete the line first before copy/pasting from the browser
- The solution, use register a~z. So "aya) yank a ( ) into register a, cursor anywhere inside (). paster it using "ap.
- https://www.baeldung.com/linux/vim-registers
- If you want to use registers 0~9, check behavior before use in the above webpage. It is complicated.
- :reg see all registers. :reg a - see register a.
- ciw""<ESC>P put a pair of double quotes around text. Cursor can be anywhere in the word.
- On my Mac, "* and "+ don't work. I have to use insert mode, and select Edit > paste.
Like most of the capitalized movement pairs, b moves by word, but B moves by WORD. The difference is that vim considers a "word" to be letters, numbers, and underscores (and you can configure this with the
iskeywordsetting), but a "WORD" is always anything that isn't whitespace.So given this:
foo-bar-bazIf your cursor is on the
zand you press b, the cursor will move back to the start ofbaz, then to the hyphen, then back to the start ofbar, and so on. Each of these is a different "word" to vim:foo,-,bar,-,baz.But if you press B, the cursor will move all the way left to the
f, becausefoo-bar-bazis all non-whitespace and thus a single WORD.:help wordinside vim explains this too.- vib and viB and ciB and cib don't work for me on my Mac.
- jump, ctrl-O (capt O,shift-o) go back, ctrl-I (capt I) go forward
- /upper/+23 or ?upper?+7 ->match upper and then go down 23 lines
- Fill in a space between all characters in multiple lines.
- .,/}/s/\(\p\)\p\@=/\1 /g
- :%s/\(.\)/\1 /g
- The following recording only partially work. Still not as neat as the first solution. If recording like "q0a Esclq" then then "q115q0j0" then "@1" meet the end of line, it will not move to next line??
- q1, a Escl
- q2, 20@1
- q3, @2
- @2,@3 repeat
- q4, @2@3 -> doesn’t work, because @2 will error and stop
- to repeate same pattern from start, there is a trick, yy, p, k, J, that is paste this line below and then join line.
- what commands available in edit mode?
- select text and replace with ctrl-v
ctrl-q {motion} ctrl-vctrl-q {motion} d “0p - python script auto run
:lcd %:p:h :!python %
- VIM new _vimrc
nnoremap <silent> <F5> :!python %<CR> nnoremap <F6> :!pdflatex %<CR> nnoremap <F7> :!pdflatex -shell-escape %<CR> nnoremap <F8> :!xelatex %<CR> set autochdir
- 去除所有行後面的空白%: all lines, you can also do .,$ to set current line to last line
:%s/\s\+$//e
s: substitute
/:command separator
\s:a white space
\+:one or more preceding atom
$:end of line
/:command separator
/e:no error message when space not found - vim temporary file deal withhttps://stackoverflow.com/questions/743150/how-to-prevent-vim-from-creating-and-leaving-temporary-files
- 在windows install vim要手動把包含vim.exe的directory加入環境變數path中,包含使用者以及global的環境變數,然後要重新開機。
在 macOS Terminal(包括 zsh / bash)裡很常用的是:
Ctrl + A→ 跳到 command 開頭Ctrl + E→ 跳到 command 尾端
No comments:
Post a Comment