Vim Editor, tmux Use

1. Introduction to VIM

Editing tools in Linux: vi, vim, emacs, gedit

  • vi is the default text editor installed on Linux
  • vim is an upgrade of vi
  • centos 7/8 minimum installation, vim is not installed by default

Yum install/remove vim-y install and uninstall software

Coding issues

  • wiidows: Notepad recognizes vim's text with a line break symbol that is not friendly, so it's better to open it with sublime
  • The Linux:vim editor can open sublime and Notepad edited file contents, but opening Notepad may be garbled
    Reason: Notepad uses a different encoding (ANSI) than linux (Unicode, UTF-8). Save the file it opens as another encoding to open it in linux without scrambling
    Unicode is a universal code, utf8 is a branch of Unicode
    python3 defaults to utf-8

2. Mode Switching

/root/.vimrc This configuration file, vim opens the file and automatically loads the configuration inside

2.1 Input mode

Action Keyfunction
iWhere cursor is, where input is
ICursor jumps to the beginning of the line and inputs
oEnter in the next line of the cursor
OEnter on the line above the cursor
aEnter one space behind the cursor
ACursor back to end of line and input
sDelete the character of the cursor for input
SDelete the row of the cursor and enter it

2.2 Last Line Mode

: w!Discard Save
: w aa.txtSave as, followed by absolute path
: wSave Only Don't Exit
: set number = set nuLine Number Settings
: set nonumber =set nonuCancel line number setting
: help : wview help
: q!Force exit without saving
: wq = :xSave and Exit
: wq!= : x!Force exit and save (only root users can)
:qOnly works when no changes are made
: r mobile_phone.txt or: r/etc/hostsImport (read) the contents of the file
:e /lianxi/tang.txtExit the current file to open another file tang.txt
:set ts=4Set a tab key to occupy 4 spaces and a tab key to occupy 8 spaces by default
:set pasteWhen setting up paste, keep the format unchanged according to the original format
:set cursorlineShow cursor cursor in line of cursor line
:set cursorcolumnDisplay column column column where cursor is located

Jump in Last Line Mode

:nLine n
: $Last line

File Content Replacement

: s/old/new/Replace the first character "old" found in the current line with new
: s/old/new/gReplace all strings "old" found in the current line with new
: #,# s/old/new/gReplace all strings "old" in the range of line number "#,#" with new
: %s/old/new/gReplace all "old" with new throughout the file range
: s /old/new/gcPrompt confirmation for each action
: %s/feng//gDelete all Fengs

2.3 Command Mode

ZZSave and Exit in Command Mode
xDelete a single character (equivalent to cutting)
ddDelete the row of the current cursor
#ddDelete #line content starting at cursor
d^Delete all characters before the current cursor to the beginning of the line
d$Remove all characters from the current cursor to the end of the line
dwDelete a word with spaces, colons, etc.
yyCopy the entire line of the current line to the clipboard
#yyCopy #line content from cursor
pPaste the contents of the buffer after the cursor position
PBefore pasting to cursor position

Jump in Command Mode

nGJump to Line n
GJump to the last line

Find String

/wordLook up the string "word" in the file from top to bottom
?wordFind the string "word" in the file from bottom to top
nLocate the next matching lookup string
NLocate the previous matching lookup string

2.4 Replacement Mode

R replace replacement
Move the cursor directly to a location, type directly, and it will be replaced
Undo: Backspace

2.5 Visual Mode

Mainly used to select duplicate block text
In command mode, use the V or V keys to access the visual module
Visual or visual block mode allows you to copy or delete a part of a word, select a part of a word, and then proceed.

Small vVisual ModesThe part between the current position and the last stop of the cursor
Large VVisual Line ModeRow from current position to last stop position of cursor
ctrl+vVisual Block ModeSelect block (rectangle) from current position to last stop position of cursor
Press y copy  x delete
 Press p paste
 Start a new line, press o,Press again esc,again p

Write a program that randomly generates strings and writes them to a file. A line must have 50 characters and produce a text file with 1 million lines
Linux Writing:

[root@localhost lianxi]# cat
#Random Generation of Characters
for i in {1..1000000}
   mychar=$(mkpasswd -l 50)

   echo $i  $mychar>>sc_bigfile.txt

python notation:

[root@localhost lianxi]# cat

import string
import random

#Generate 10 lower case letters

#Stitch together 10 letters

with open("sc_bigfile2.txt","a+") as f:  #Open the file and enter the contents in an appended manner

3. Randomly generated strings


Generate a fixed-length string from a piece of text or a file

[root@sc lianxi]# md5sum a.txt 
1c9f470f675a5a21f7583e1a33f88575  a.txt
[root@sc lianxi]# echo 123|md5sum 
ba1f2511fc30423bdbb183fe33f3dd0f  -
[root@sc lianxi]# echo 123123456|md5sum 
eafa8cafcb3f240cc2d23e0dbf638adf  -

hash function

Hash, commonly translated as hash, hash, or transliterated as hash, is an output that transforms an input of any length into a fixed length through a hash algorithm, which is a hash value.
This simply means a function that compresses messages of any length into a message digest of a fixed length.


l-Length d-Number c-Letter s-Symbol

[root@localhost ~]# Mkpasswd-l 50 specifies the password length
[root@localhost lianxi]# mkpasswd -l 50 -d 10 -c 10 -s 10

string library (library in python)

>>> string.printable  # Print out all characters that can be used as passwords
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'
>>> string.ascii_lowercase  # A lowercase letter
>>> string.ascii_uppercase  #Uppercase
>>> string.digits  #number
>>> string.punctuation  #Special Characters
import random
import string
>>> random.sample(string.ascii_lowercase,k=10) #Randomly generate an array of 10 lowercase letters
['z', 's', 'i', 'r', 'g', 'c', 'f', 'a', 'k', 'e']
>>> random.sample(string.ascii_uppercase,k=10)  #Randomly generate an array of 10 characters
['W', 'M', 'G', 'S', 'L', 'H', 'I', 'U', 'Q', 'K']
>>> random.sample(string.digits,k=10)  #Randomly generate 10 numbers
['0', '3', '4', '7', '8', '1', '9', '5', '2', '6']
>>> random.sample(string.punctuation,k=10)  #Randomly generate 10 special characters
['`', '%', '/', '<', '-', '(', '?', "'", '"', ']']
>>> aa = random.sample(string.punctuation,k=10)   
>>> aa.
aa.append(   aa.copy(     aa.extend(   aa.insert(   aa.remove(   aa.sort(     
aa.clear(    aa.count(    aa.index(    aa.pop(      aa.reverse(  
>>> "".join(aa)   #join method puzzle

4. Use of tmux tools

Initial experience with Tmux

Tags: Linux vim

Posted on Mon, 06 Dec 2021 12:58:23 -0500 by dkphp2