vim notes

  • 不按 Esc 而是按 ^『或者 ^c,速度快很多
  • 學會幾個定位鍵的區別:0, $, {, }, g, G, w, e, b…
  • Shift+V 選定幾行,然後用 一起移動
  • Ctrl+V 選定行首或行尾的字符,然後用 shift+i 做插入,或者 shift+x 做刪除
  • 學會用 y,d 和 p, P 做粘貼剪切
  • 學會用 ^W 的窗口操作。打開文件用 sp 或者 vs
  • 學會記錄宏的命令。用 q 加任意鍵開始錄製,再按 q 保存。然後可用 @加這個任意鍵回放,在 @前加數字可定義回放次數
  • “.”重複上一個命令,”u”取消上一個命令,”^r”反取消
  • ^n, ^p 用 buf 裏的關鍵詞補全。
  • 學會搜索替換”:%s/ 要搜的東西 / 要換成的東西 /g”
  • 任何時候移到一個單詞上按#的話可以高亮這個文檔裏所有一樣的單詞
  • 用“/”做搜索,按 n 或 N 上一個 / 下一個
  • “:! 命令 &”可直接運行這個命令,用”:! 命令 %&”如果你想讓這個命令對當前所編輯文件做操作。
  • 任何時候可用”:cd %:p:h”來切換目錄到當前編輯文件所在目錄。
  • “.” 這個 mark 代表最後一次修改的地方,所以 “’.” 可以跳到最後一次修改的地方,’. 可以跳到最後一次修改的那一行。
  • g; 和 g, 則可以在整個 changelist 裏面來回跳轉,敲 :help changelist 可以看說明。
  • + or or //change windows size
  • + left or right //rapidly change windows to watch two files diffience

^M how to delete ^M

  • :%s/^M//g
  • ^M “ +”

run markdown

  • rmk
  • open by typora
  • /searchStringlv

move windows center to cursor

  • zz
  • z+
  • z-
  • H M L move cursor to windows
  • :set scrolloff=10 //let cursor on windows center alwaysly

move on buffers

  • :ls, :buffers
    show all buffers
  • :bn[ext]
    next buffer
  • :bp[revious]
    last buffer
  • :b2
    move to number 2 buffer
  • :b exa
    move to match exa file such as example.txt
  • :sb 3
    split windows open buffer number 3 file by horizontal spl
  • :vertical sb 3
    by vertical split

reg pasteclipboard

  • :reg
  • show all reg
  • “+ system reg
  • yyn
    • n is name of reg
    • paste reg content to current lin

on txt file move to title

  • ctrl + ]

2017/2/26 星期日 21:05:31

switch tabel

  • gt

create tabel

  • nt

insert current time

  • tt

switch windows

  • Ctrl + f : next windows
  • Ctrl + b : last windows
  • ctrl + d : next half windows
  • ctrl + u : last half windows

delete trick

  • dw
  • de
  • db
  • d$ delete to row end
  • di
  • dtc delete between c all charcters

read and save

  • :r filename read filename to current cursor
  • 1,20 w filename create new filename to 1,20 line content
  • 1,$ w filename whole content write new filename
  • 1,20 w >> filename write 1,20 content to filename last line

autoindent

  • ==

jump to last cursor

  • ctrl + i
  • ctrl + o

jedi

  • K document
  • g go to
  • not for javascript

setting pwd

  • .

nerdtrem

  • rename file
  • m ->m
  • alter filename
  • delete file
  • use key “m”

emmet key

  • ,, == <ctrl y>,

go to mark

  • mark place: m {a-zA-Z}
  • go to mark: ‘{a-zA-Z}
  • delete mark: :delmarks {a-zA-Z}
  • show all mark: :marks

line choose by visual mode

  • line visual mode: V
  • Vjj
  • 塊 visual mode: ctrl + v but on windows ctrl + q
  • gv => choose last visual chosed text
  • o => cursor move to selected text end
  • O => cursor move to selected text start

run python code on your vim

s = 'djj'
print s
  • Run code by select 2 line Vkk, then press: !python and hit enter
    output:djj
  • anothor example:
def func(x, y):
    return x + y
print func(3, 4)

output:7

for i in 'moonclearner':
    print i

output:

m
o
o
n
c
l
e
a
r
n
e
r

vim-surround

“hello world”
- press cs”’ inside ” switch to ’
‘hello world’
- press cs’ inside ’ switch to
hello world
- cst”
“hello world”
- ds” delete ”
hello world
- cursor on hello ysiw]
[hello] world
- cs]{
{ hello } world
- yssb or yss) wrap entire line
({ hello } world)
- ds{ds) revert to original text
hello world
- ysiw cursor on hello
hello world
- VS

wrap



hello world

close label tag

  • >
    output:

block visual

  • ctrl+v on unix
  • ctrl+q on windows
  • jjj or % muti line select
  • i,I,a,A to input

^ and 0

     this a sentence!
  • cursor on t
  • ^ the cursor will jump to c
  • 0 the cursor will jump to space, first column

$ and g_

  • $ go to the end of line
  • g_ go to the last non-blank character of line

buffer

  • :bn
  • :bp
  • :buffers -> show all buffers

saveas

  • :saveas -> save as

# and *

  • # look previous same character
  • * jump next same character

yank muti times character

  • this my test and test
  • the cursor on i
  • y2/test ->will copy is my test and
    yank up to the second occurence of test
  • y/test -> will yank is my
    yank up to the first test before
  • ye
  • y$

f and t

  • fa -> go to next occurence of the letter a on the line
    , and ; respresent next and previous, reverse use F
  • ta -> go to just before the character a, reverse use T

dt and yt

  • t represent to
  • delete everything util the character before
  • yank everything util the character before

Zone select

  • adb(map(+)(“foo”))nnn
  • cursor on o
  • vi” -> will select foo
  • va” -> will select “foo”
  • vi) -> will select “foo”
  • va) -> will select (“foo”)
  • v2i) -> willl select map(+)("foo")
  • v2a) -> will select (map(+)("foo"))

completion

  • ctrl+n next completion
  • ctrl+p previous completion

Macros

  • qa record actions in the reg a
  • q stop record actions
  • @a replay the macro saved into the reg a
  • @@ to replay the last executed macro
  • number@@

visual using

  • J ->join all the lines together
  • < or > ->indent to left or right
  • = ->auto indent

split

  • :split
  • :vsplit
    open nerdtree
  • :Vexplore
  • :Sexplore

common command

  • add ; three line at the line
  • ctrl+q ->$ ->jjj ->A ->; ->Esc

vim save as sudo

  1. :w !sudo tee %
  2. :%!sudo bash -c “cat > ‘%’”
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章