Vim indent 2


Hôm nay chúng ta sẽ tìm hiểu indent trong vim nhé. Để indent 1 dòng ta dùng:
==

Để indent 3 dòng ta dùng:

3==

Hoặc indent 1 dòng dùng:

>>

de indent 1 dòng ta dùng:

<<

Ví dụ ta có đoạn code sau:

function hello(){
console.log("hello javascript");
console.log("hello javascript"); <--- con trỏ ở trong block code.
console.log("hello javascript");
}

Ta muốn indent các dòng trong block code trên ta gõ:

=iB

Ta sẽ có kết quả:

function hello(){
  console.log("hello javascript");
  console.log("hello javascript"); 
  console.log("hello javascript");
}

Nếu con trỏ ta ở vị trí như sau:

function hello(){ <--- con trỏ ở {

console.log("hello javascript");
console.log("hello javascript"); 
console.log("hello javascript");
}

Ta gỏ

=%

Ta có kết quả:

function hello(){ 
  console.log("hello javascript");
  console.log("hello javascript"); 
  console.log("hello javascript");
}

Ta có block code như sau:

function hello(){ 
  console.log("hello javascript");
  console.log("hello javascript"); 
  console.log("hello javascript");
}

Nếu ta muốn toàn bộ block code indent vào trong như bên dưới:

  function hello(){ <--con trỏ ở { 
    console.log("hello javascript");
    console.log("hello javascript"); 
    console.log("hello javascript");
  }

Ta gỏ

>%

Nếu ta có code html ta dùng :

>at 

để indent html code.

Nếu muốn indent toàn bộ file ta dùng:

gg=G

Như vậy ta đã học được cách indent trong vim rồi đó. Hãy cùng thực tập nào.