Chuyển đến nội dung chính

Using Vim Editor

The Vim is a tool editor text. It is used as the most popular and powerful tool. In the context of Vim, it can operate in two modes: command mode and insert mode. The editor always starts in command mode. In the command mode, we can move through the text, search, replace, mark blocks and switch the editor to insert mode. The first, we will install Vim.
On ubuntu
sudo apt-get install vim
On CentOS
sudo yum install vim

We use command vi file_name to open file in the Vim editor. We will start with some basic commands.

Basic commands


  • h to move the cursor to the left
  • l to move it to the right
  • k to move it to the up
  • j to move it to the down
  • G to move it to the begin of last line
  • gg to move it to the begin of first line
  • :n to move it to line n of the file

Basic operations



  • n dd will delete n lines starting from the current cursor position.
  • u will undo.
  • ctr + r will redo.
  • n dw will delete n words starting from the current cursor position to right.
  • n db will delete n words starting from the current cursor position to left.
  • x will delete character on which the cursor is positioned.
  • :w save file.
  • :q will exit the editor.
  • :q! will force the exit when user want unsaved changes.
  • :wq will save and exit
  • :w new_file will save the text to new_file
  • /string_for_search will search the string up-down in the file, position of cursor on the first match.
  • / will perform the same search again, moving the cursor to the next match.
  • ?string will search the string down-up.
  • :1,$s/old_text/new_text/g will replace old_text with new_text throughout the file.
  • yy will copy a block of text.
  • n p will paste it n times.
  • a will change to append text to file.
  • i will change to insert mode.
  • esc will change to command mode.

Scrolling



  • ctr + f will scroll down one screen.
  • ctr + b will scroll up on screen.

Split screen



  • :vsplit file_name will vertical split screen and load another file
  • :split file_name will horizontal split screen and load another file
  • ctr + w will move cursor to next screen.



When we opened file with the Vim editor, the file is opened with not set number line. To set number line please enter :set nu. To set default open file with set number line, we can edit /etc/vim/vimrc and append  set number to this file.  To redefine tab as 4 spaces use :set tabstop=4 or append set tabstop=4 into /etc/vim/vimrc


Nhận xét

Bài đăng phổ biến từ blog này

Introduction Heartbeat

In this tutorial, I show for you some concepts about heartbeat.  Heartbeat is a project from Linux-HA (Linux high available). The goal is t provide a High availability clustering solution for Linux. Heartbeat is the daemon which provides the cluster infrastructure. In order to be useful, heartbeat needs to be combined with a Cluster Resource Manager (CRM), which is the one in charge of starting and stopping the services (Web, DNS, Database, File servers and/or IP Addresss) to make them Highly Available. Through the years, Heartbeat has evolved and has different types of configurations: Heartbeat V1: This type of configuration uses the Version Cluster Resource Manager. This is also known as legacy Heartbeat. It allows us to configure two cluster node in active / passive or active / active configurations. Heartbeat V2: This type of configuration is related  to the use of the version 2 Cluster Resource Manager. It allows us to configure two or more nodes in active / pass...

Thủa sơ khai của React - Pure React

Pure React Chúng ta hãy cùng bắt đầu học Reactjs với cách viết Pure React. Nói không với các bước compile, không với Webpack, Parcel, JSX mà chỉ có Javascript thuần tuý thôi. Vì mình biết nếu bây giờ nhảy thẳng vào các khái niệm đó, các bạn sẽ choáng ngợp bởi có quá nhiều khái niệm, và cũng không hiểu rằng tại sao họ lại dùng những thư viện đó và dùng nó khi nào nữa :) Nào hãy cùng tạo một project tên là adopt-me  mình lấy tên như này bởi mình muốn sử dụng API của trang Petfinder.com  cho các bài hướng dẫn sau về xử lý kết quả trả về từ API. Và cũng vì lý do nhân văn là các bạn nên nhận nuôi một con thú cưng nhé hihi. Mình khuyến khích các bạn lập trình sử dụng hệ điều hành Linux hoặc MacOs nó rất tiện cho bạn sử dụng dòng lệnh và thao tác nhanh chóng như dân lập trình Pro. Chúng ta bắt đầu tạo một thư mục adopt-me , dưới thư mục chúng ta tạo một thư mục src lưu code và tạo một file index.html trong thư mục đó. Cách đơn giản là bạn mở terminal lên và gõ câu lệnh. mkdir -p ...