Vim & Emacs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
[mo@mos-computer ~]$ sudo yum install vim
[mo@mos-computer ~]$ sudo yum install emacs
# Vim tutorial
[mo@mos-computer ~]$ vimtutor

# Vim modes: Interactive, Insert (enter: i, a ,o ignore case; s-delete current word and enter insert mode S-delete current line and enter insert mode; exit: esc), Command Line (':' to enter), Visual mode (v-char visual mode; V-lines' visual mode, Ctrl + v is module visual mode)

content in myFile (learn some useful commands):
[mo@mos-computer ~]$ cat myFile
[mo@mos-computer ~]$ cat myFile
Hello Linuxers !

I just write some lines here in the Vim for filling the screen.
You might feel easier to write things when switched to Insert mode in Vim.
:p

You can move cursor here by: h <-, j up, k down, l ->.

to the head of the line: 0 ; to the end of the line: $; move word by word: w.

save file :w [file_name] ; add '!' to force these command to execute.
[mo@mos-computer ~]$ vim myFile
[mo@mos-computer ~]$ cat myFile
Hello Linuxers !

I just write some lines here in the Vim for filling the screen.
You might feel easier to write things when switched to Insert mode in Vim.
:p

You can move cursor here by: h <-, j up, k down, l ->.

to the head of the line: 0 ; to the end of the line: $; move word by word: w.

save file :w [file_name] ; add '!' to force these command to execute.

': x' has the same effect as
[mo@mos-computer ~]$ vim myFile
[mo@mos-computer ~]$ vim myFile

[No write since last change]
compression htop-2.2.0.tar.gz newly_created_file rarlinux-x64-5.7.0.tar.gz
Desktop Music node redirect
Documents myFile nohup.out repeat.txt
Downloads myFIle number.txt results.txt
errors.log name_sorted.txt output_find Templates
file-copy.txt name.txt Pictures test
grep_log newfile Public unique.txt
htop-2.2.0 new_folder rar Videos

Press ENTER or type command to continue
[mo@mos-computer ~]$ cat myFile
Hello Linuxers !

I just write some lines here in the Vim for filling the screen.
You might feel easier to write things when switched to Insert mode in Vim.
:p

You can move cursor here by: h <-, j up, k down, l ->.

to the head of the line: 0 ; to the end of the line: $; move word by word: w.

save file :w [file_name] ; add '!' to force these command to execute.

': x' has the same effect as;

========================================================================
Advanced command

1. in Interactive mode, enter [word_num] x to delete designated number of words after the cursor.

2. enter d to delete line or words. [line_num] dd to delete current line. [word_num]dw to delete current word. (d0 -->delete to head,d$ --> delete to tail)

3. enter y to copy. yy copy line to storage. yw copy a word. (y0 and y$ also works)

4. enter [paste_num] p to paste (after cursor).

5. enter r[replace_char] to replace current char. (enter R to enter REPLACE mode where you can replace multiple chars)

6. enter [ops_num]u to undo. (Ctrl+r to redo the command)

7. enter g to go to specific line. (enter ':set nu' to show the line number,use 'set:nonu' to cancel. 'G' jump to the end of file.'gg' to jump to the head of the file.'[num]G' or '[num]gg'to jump to desired line. )
8. '/' is used for search things. (show 'pattern not found' when nothing found, 'n' next)
9. find the word and replace it: ':s/[string_to_replace]/[new_string]', if you want to replace all word match in current line then use ':s/[string_to_replace]/[new_string]/g' (a special case: replace a word from line 2 to 4: ':2,4 s/[string_to_replace]/[new_string]', if you want to replace all word in this file then we use ':%s/[string_to_replace]/[new_string]/g')
10. :r [file_name] merge current file with another file.
11. :sp split screen into halve. :vsp vertical split. (Ctrl w + o, save only current viewport)
12. run bash cli in vim : ':!' or in current folder ':!ls'

Vim configuration

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# install vim plug-ins by yourself

# config args .vimrc (USEFUL args: ':set option = value') , let's write it now
# .vimrc file usually located at the /etc/vimrc

some args to add in .vimrc

syntax : on
:set number (the same as :set nu)
set sshowcmd
set ignorecase
set mouse=a

# There are more vim configuration available on Github

Intro to version control software

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Git (and other options...like SVN, Bazaar, Mercurial)
# it can track process, coordinate the work... (can come back to any previous version)
# central model, distributed model.
[mo@mos-computer ~]$ sudo yum install -y git
[mo@mos-computer ~]$ sudo yum install -y gitk
[mo@mos-computer ~]$ git --version
git version 1.8.3.1
[mo@mos-computer ~]$ git config --global color.ui auto
[mo@mos-computer ~]$ git config --global color.diff auto
[mo@mos-computer ~]$ git config --global color.status auto
[mo@mos-computer ~]$ git config --global color.branch auto
# git config --global color.ui false

# username
[mo@mos-computer ~]$ git config --global user.name "Mo"
#[mo@mos-computer ~]$ git config --global --replace-all user.name "Mo"
[mo@mos-computer ~]$ git config --global user.email "moshuheng922@google.com"
# you can replace the email address in a similar way like user name

# man git-config
# 'git-config --list' or 'vim ~/.gitconfig' to view the config file
#config gitgit

# you can simplify the git command
[mo@mos-computer ~]$ git config --global alias.co checkout
# so after this command activated we can use 'git co' to represnets 'git checkout'
# another option was 'vim ~/.gitconfig' and change the option in the alias areas
[mo@mos-computer ~]$ cat ~/.gitconfig
[color]
ui = auto
diff = auto
status = auto
branch = auto
[user]
name = Mo
email = moshuheng922@google.com
[alias]
co = checkout
st = status

# less .gitconfig

Github

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Register in Github, I am sure you can do this yourself

# Work on your personal Github page using tools like: Hexo

# Clone Github repository using bash command line
git clone [https_url] [cloned_repository_name]

# Or you can clone it with SSH
[mo@mos-computer .ssh]$ ssh-keygen -C "bushit4455@126.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/mo/.ssh/id_rsa): /home/mo/.ssh/id_rsa_github
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/mo/.ssh/id_rsa_github.
Your public key has been saved in /home/mo/.ssh/id_rsa_github.pub.
The key fingerprint is:
SHA256:q82xIEhNGqovOyUEaOCCqtFM4CkiBOOQPUF2aMkJkGk bushit4455@126.com
The key's randomart image is:
+---[RSA 2048]----+
|&X+=. |
|&EX. |
|X*o.. |
|** = |
|= = . S |
|+o.. . |
|oo. . . o |
|o. . = o |
|.+. . + |
+----[SHA256]-----+
[mo@mos-computer .ssh]$ ls
config id_rsa id_rsa_github id_rsa_github.pub id_rsa.pub known_hosts
[mo@mos-computer .ssh]$ cat id_rsa_github.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDZ6D0nSdNmfdn0/I+vAtkISL1QE+y4eoxSZr8ho9gv+yFK/r1qAFNv+o3fuq3lS/4yP9+ygADE3FxMNde+W05pvoyu1txOPkT5TLBpgaYgbI2Q/InsSYdG7B0u9drNxhZYerCdjO3WSPs5oEiOqg2wcJIreKiOt8/C7fLz5BRfrxXjYzDUY2oaLFSN3BScyn9Tr9YYNnxV0WImPH9754u2KEIgnQ77XNlVoP/GzUpIEME9ISLAYzq3se7yF8ywJqN2qor2GO2ke7GnEX0O9l4s1fBDUsMQiCApp2+P7ckIPXPXBqA4ONoFaTvIAgZsDRrU4Srq7CBO+QUnWsSdTSuf bushit4455@126.com
# copy this public key to github settings SSH key and then test the connection
[mo@mos-computer .ssh]$ ssh -T git@github.com
The authenticity of host 'github.com (13.250.177.223)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
RSA key fingerprint is MD5:16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,13.250.177.223' (RSA) to the list of known hosts.
Hi M0JaX999429! You've successfully authenticated, but GitHub does not provide shell access.

[mo@mos-computer .ssh]$ cat known_hosts
192.168.0.120 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBG1cXD02hhw5s6ron7bqSYyWbuNyn33zG/IG8QwpkC2esVlGWzJDebsbBsjw/sfqYMq/uwZwsnBSqQE8W3uxg9A=
github.com,13.250.177.223 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==

# How to push code to Github?