vim

alexmaodali發表於2024-04-05

1.Normal mode

ctrl v 進入 visual mode

y           yankcopy
y           yankcopy
p
u           撤銷ctrl z
:redo       恢復ctrl y
hjkl
i
w    W       跳躍一個單詞
b     B      退一個單詞
e,ge    E,gE     跳單詞尾
f{} f(  fd  Fd td Td跳到指定單個字元
fd;;

Moving Horizontally Extremely

- `0`: Moves to the first character of a line
- `^`: Moves to the first non-blank character of a line
- `$`: Moves to the end of a line
- `g_`: Moves to the non-blank character at the end of a line

跳一段:{ }ctrl d/u
/{pattern}
?{pattern}跳到輸入的字元位子 n/N

Go back to Normal mode with , or <CTRL-[>.


New Start Vim:

1.saving file:

:write
:w file.txt
:wq
:q!
:qall
:qall!
:wqall

2.Help

:h write-quit <tab>

3.open a file

vim hello1.txt

vim hello.txt hello2.txt hello3.txt -->open mutiple files at once

vim --version or :version in vim

4.Mutiple Windows

vim -o2
vim -O2
vim -o5 file1.txt file2.txt

:suspend

5.Vim grammer

verb+noun

verb:
y   yank text
d delete text and save to register
c delete text ,save to register , and start insert mode

yank a text , u can paste it with p or P

y$
dw
c}

y2h
d2w
c2j
const hello=function(){
	console.log('Hello Vim");
	return true;
}

di( di{ diw

text object

w p s (
{
[
<
t
"
'
`

6.Word navigation

w
W
e
E
b
B
ge
gE
f search forword for a match in the same line
F
t
T
; repeat the last search in the same direction
,
% navigate to another match like ( ) [] {}


7.Line number navigation

gg
G
nG
n%

8.Window Navigation

H 	top
M	medium
L	bottom
nH	n line from top
nL

9.Scrolling

^F/B full-screen
^D/U half-screen
^E/Y line


ralative scrolling:
zt let current line to the top
zz middle
zb bottom

10.Search Navigation

/ forward for a match     ?
n repeat search N

* search for whole word under cursor forward
# search for whole word under cursor backward
g* forward
g# backward

11.Marking Position

mx     mark
return to the mark:  `x  'x

ep:ma  `a 'a

12.Insert Mode

c h
c w
c u

i before the cursor
I before the first non-blank char of the line
a	append text after the cursor
A	end of the cursor
o	new line below the cursor
O	above
s	delete the char under the cursor and insert text
S	like cc in Normal;
gi	insert text in same position where the last insert mode was stopped
gI	insert text at the start of line

Scrolling in insert mode:
-x -y
-x -e
const one='1';
const two='2';
const three='3';

Final order:

進入插入模式:
i 游標之前插入
a 游標之後插入
A 一行的結尾插入
s 刪除游標處字元並進入insert mode
S dd讓後進入insert mode
o 游標的下一行新增空白行並插入
O 反之
  k
h   l
  j

刪除,複製,貼上,剪下
dd 刪除一行
dw 刪除游標所在單詞
yy 複製當前行
y0
y$
yw
y?bar 複製上一個出現bar的位置,且動作之前的游標位置不復制;

zt

d0 d$ dl/x
s -> substitute  /cl
visual mode + manipulate
: d c
C^u up
C^d down
C^r  redo
demo:
def fizz_buzz(limit):
  for i in range(0,limit):
    if i%3==0:
      print('fizz')
    if i%3==0:
      print('fizz')
    if i%3 and i%5:
      print(i)
def main():
  args=10
  fizz_buzz(args)

New__________:

Open Files;

:new 
:e filename;    if not exits creates
:Ex open the directory tree in Vim ;   -  to the parent directory and enter to enter;

Find

*
#
/
?
n
N
f<x>
t<x>

%  (){}[]

buffers

:ls  /  :buffers  to view the buffer list
:bn open the next file in the buffer;
:bp
:b<N>;
:bd<n> to delete the buffer u want to delete in buffer list;

cc to delete the line and into the INSERT MODE
J to merge the current line with the next line;

:wa save all files;
:ZQ / !q ;
:saveas newfileName;

gu$
gU$

window jumping:
c-ww
c-wj
c-wk
c-wh
c-wl
move split screen;
c-wL
c-wH..

tab

:tabnew   or :tabedit  :tabe;  substitution:<space><filename>;
c-w gf open the current cursoring file;


swith tabs:
gt;

tabclose
-tabc
+tabc
:tabonly;