Linux Editor
A text editor on Linux, similar to Microsoft Word, Visual Studo Code on Windows, is a must-have application. Most of them are all GUI-based. However, this posts will introduce command line text editor for Linux.
Common Text Viewer (DO NOT Support Edit Function):
- cat
- more
- less
- head
- tail
Common Text Editor:
- nano
- vi / vim
- emacs
The posts will only present part of common and useful functions of the editors, please click the related links to learn more!
less Viewer
Cursor Movement
Keyboard Shortcut | Description |
---|---|
SPACE | forward one window |
b | backward one window |
j | move on the next line |
k | move on the previous line |
10j | move on the next 10 line |
10k | move on the previous 10 line |
G | go to the end of file |
g | go to the start of file |
q | exit the less pager |
Search
Keyboard Shortcut | Description |
---|---|
/ | search for a pattern which will take you to the next occurrence |
n | for next match in forward |
N | for previous match in backward |
VI/VIM Editor
Three VI/VIM edit mode:
- Command Mode (Default)
- Insert Mode /** Press
ESC
return to Command Mode **/ - Visual Mode /** Press
ESC
return to Command Mode **/
VI/VIM Cheat Sheet
Command Mode
Cursor Movement
Keyboard Shortcut | Description |
---|---|
↑ / k | Move up one line |
↓ / j | Move down one line |
← / h | move left one character |
→ / l | move right one character |
^ | Go to the begining of this line |
$ | Go to the end of this line |
gg | Go to the first line of the document |
G | Go to the last line of the document |
w / e | Jump forware of a word ( w will jump to the start of a word,e will jump to the end of a word) |
:n | Jump to line n (n is a specifc integer number) |
:set mu | Show line numbers |
Save the file and Exit the Editor
Keyboard Shortcut | Description |
---|---|
:w | Save |
:wq | Save and Quit |
:q | Quit (Fails if there are unsaved changes) |
:q! | Force Quit |
:wq! | Force Save and Quit |
Delete/Cut/Undo/Redo
Keyboard Shortcut | Description |
---|---|
x | Delete (cut) character |
dd | Delete (cut) the line |
dw | Delete (cut) the word |
u | Undo |
5u | Undo 5 times |
Ctrl + r | Redo |
Copy/Paste
Keyboard Shortcut | Description |
---|---|
yy | 复制行 |
p | 在光标后粘贴 |
P | 在光标前粘贴 |
Insert Mode
Enter insert mode
Keyboard Shortcut | Description |
---|---|
i | Insert at cursor |
I | Insert at the begining of the line |
a | Append after the cursor |
A | Append at the end of the line |
o | Open a new line below the current line |
O | Open a new line above the current line |
Visual Mode
Keyboard Shortcut | Description |
---|---|
v | start visual mode |
V | start linewise visual mode |
Ctrl + v | start visual block mode |
Some other useful techniques
Select copy contents
Press v
start visual mode, move the cursor to select the contents, then press y
copy, move the cursor to where you want to paste, press p
.
Comment mutiles lines of code
Using Ctrl
+ v
start visial block mode, select all the lines you want to comment. Then, press capitalized I
insert the begining of the line, put whatever //
or #
. Press ESC
twice.
Manipulate all characters inside brackets/quotes
Delete all characters inside brackets/quotes:
something="This is a string." --> something=""
(123456) --> ()
- Move the cursor inside the brackets/quotes under the normal/command mode
- Press keyborad shortcut:
d
+i
+brackets/quotes
, for example, remove all characters inside the quotes isd
+i
+"
Explain: d
is for delete, i
is define a range, then brackets/quotes
is a flag.
Copy all characters inside brackets/quotes:
- Move the cursor inside the brackets/quotes under the normal/command mode
- Press keyborad shortcut:
y
+i
+brackets/quotes
, for example, copy all characters inside the quotes isy
+i
+"
Customize Vim (Plugins)
Vim editor is already powerful enough out of the box, but we can install some plugins to personalize it.
Notice: Installing to many plugins will effect the editor performance.
vim-plug
vim-plug is a minimalist plugin manager
Unix/Linux Installation
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
For other system environment, please refer vim-plug GitHub readme.
vim-airline
vim-airline is a lean & mean status/tabline for vim that's light as air.
Installing vim-airline (and themes) is adding the following to .vimrc
:
call plug#begin('~/.vim/plugged')
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
call plug#end()
Then, run:
:PlugInstall
Other Configurations:
(Optional: you can put them into .vimrc
)
"----------Plug vim-airline/vim-airline configuration----------
let g:airline#extensions#tabline#enabled = 1 " Enable the list of buffers
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
let g:airline_symbols.colnr = ' ' "Fix the status bar text display problem
" ~/full/path-to/file-name.js
let g:airline#extensions#tabline#formatter = 'default' " f/p/file-name.js
let g:airline#extensions#tabline#formatter = 'jsformatter' " path-to/f
let g:airline#extensions#tabline#formatter = 'unique_tail' " file-name.js
let g:airline#extensions#tabline#formatter = 'unique_tail_improved' " f/p/file-name.js
For more settings, please visit Getting started with vim-airline.
Comments are disabled.