Information Security System Design Foundation second week study summary--20135308

Source: Internet
Author: User
Tags set background

This week, I learned how to use vim.

Vim is a very good text editor and many professional programmers use vim to edit the code, VI, a considerable amount of skill is required at the outset, but once you have mastered these skills, you will become more proficient, which is similar to Wubi typing. We recommend learning through practical exercises to learn specifically through Vimtutor. Just type vimtutor on the command line and then follow the tutorial exercises.

    • The uppercase "K" can be used to find help for the function: Look at the man page, in command mode, place the cursor on the function name, press "K" to see the mans page directly.
    • Several settings

: Set NU Displays line number

: Set AI automatically indents rows

: Set ts=4 sets a TAB key equal to several spaces

Move cursor

[[Go to Previous ' {' in first column]

]] to go to the next "{" In the first column

{Go to previous empty row

} go to the next empty line

GD goes to the definition of the local variable referred to by the current cursor

#GCC #

GNU CC (referred to as GCC) is an ANSI C-compliant compilation system in the GNU project that compiles programs written in languages such as C, C + +, and object C. GCC is also a cross-platform compiler that can develop software on the current CPU platform for a variety of hardware platforms of different architectures, so it is especially suitable for development in the embedded domain.

    • Preprocessing: Gcc–e hello.c–o hello.i;gcc–e Call CPP
    • Compilation: Gcc–s hello.i–o hello.s;gcc–s Call CCL
    • Compilation: Gcc–c hello.s–o hello.o;gcc-c Call as
    • Link: gcc hello.o–o hello; gcc-o call ld

#GDB #

Recommended to use CGDB, better than GDB, familiar with the VC debugging methods, you can use DDD. Note Use GCC to compile with the "-G" parameter. Refer to the GDB Reference Card GDB's most basic commands are:

    • GdB Programm (Start gdb)
    • B Set Breakpoints (4 breakpoints are set: Line breakpoint, function breakpoint, conditional breakpoint, temporary breakpoint)
    • Run starts running the program
    • BT Print function Call stack
    • P View variable values
    • C continue running from the current breakpoint to the next breakpoint
    • N Single Step operation
    • S Single Step operation
    • Quit Quit GDB

#练习 #

Next, I learned the basic operation of the Vim editor.

There are six modes of VIM:

    • Normal mode
    • Insertion modes (insert mode)
    • Visual modes (visual mode)
    • Selection mode (select modes)
    • Command line mode
    • Ex modes (ex mode)

In normal mode, there are many ways to get into insert mode. The more common way is to press a (append/append) key or I (insert/insert) key.

In insert mode, you can press the ESC key back to normal mode.

In command-line mode, you can enter text that will be interpreted and executed. For example, execute commands (: keys), search (/and keys) or filter commands (! Key). After the command is executed, VIM returns to the pattern before the command-line mode, usually in normal mode.

#三种常用模式的切换 #

Vim starts into normal mode, in insert mode or command line mode only need to press ESC or ctrl+[(this is not used in the VIM course environment) to enter the normal mode. In normal mode, press I (insert) or a (attach) key to enter the insert mode, in normal mode press: Enter command line mode. Enter WQ in the command line mode to save and exit vim.

1. Enter the following command to enter VIM

$ vim Practice_1.txt

Vim editor can also be opened using Vim directly, but no files will be opened.

$ vim

2. After entering Vim, press the I key to enter insert mode. In this mode you can enter text information below, please enter the following three lines of information:

Press ESC to enter normal mode, using the arrow keys or the H,J,K,L key to move the cursor in this mode.

Keys

Description

H

Left

L

Right (lowercase L)

J

Under

K

On

W

Move to the next word

B

Move to the previous word

Use the following key in normal mode to enter insert mode, and to start typing from the corresponding position

Command

Description

I

Edit at current cursor

I

Insert at beginning of line

A

Inserting at the end of a row

A

Insert an edit after the cursor

O

Insert a new row after the current row

O

Insert a new row before the current line

cw

Replace the character from the position of the cursor to the end of a word

Input from Normal mode: Enter command line mode, enter W return, save document. Enter: W file name you can save the document as a different file name or save it to another path

Input from Normal mode: Enter command line mode, enter WQ carriage return, save and exit edit

Here are a few other ways to exit:

Command

Description

: q!

Force quit, do not save

: Q

Exit

: wq!

Force Save and exit

: W < file path >

Save As

: SaveAs File path

Save As

: X

Save and exit

: Wq

Save and exit

Enter SHIFT+ZZ in normal mode to save and exit vim

Go to normal mode and use the following commands to quickly delete text:

Command

Description

X

Delete the character that the cursor contains

X

Delete the previous character of a cursor

Delete

Same as X

Dd

Delete entire row

Dw

Delete a word (not in Chinese)

d$ or D

Delete to end of line

d^

Delete to beginning of line

Dg

Delete to end of document

d1g

Delete to document header

In addition, you can add a number to the command before it, indicating that multiple rows are deleted at once, such as:

2DD means delete 2 rows at a time

In normal mode, you can also use the DW or the DAW (delete a word) to delete a word, so you can easily think of DNW (n replaced by the corresponding number ) means to delete n words

#行间跳转 #

Command

Description

NG (n shift+g)

Cursor moves to nth row (if no line number is displayed by default, enter command mode first, enter : Set Nu to show line numbers)

Gg

Cursor moves to the first row

G (SHIFT+G)

To the last line

tip: After you have completed the jump, you can use the Ctrl+o quickly go back to the last time ( before jump ) cursor Position , this technique is very practical, such as when you write code, suddenly remembered a bug, need to change, this time you jump to change, just need to press Ctrl+o to return to your previous position. Vim will be waiting for you to explore with a lot of similar tips.

#行内跳转 #

In normal mode, use the following command to jump within a line in a word

Command

Description

W

To the beginning of the next word

E

To the end of the next word

B

To the beginning of the first word

Ge

To the end of the previous word

0 or ^

to the wardrobe.

$

To end of line

f< Alphabet >

Search backwards < letters > and jump to the first matching position (very useful)

f< Alphabet >

Search forward < letters > and jump to the first matching position

t< Alphabet >

Search backwards < letters > and jump to a letter before the first matching position (not used)

t< Alphabet >

Search forward < letter > and jump to a letter after the first matching position (not used)

#复制及粘贴文本 #

    • Use Y to copy in normal mode
      • In normal mode, yy copies the entire row of the cursor (3yy means copy 3 rows)
      • In normal mode, y^ is copied to the beginning of the line, or y0. Does not contain the character at which the cursor is located.
      • In normal mode, y$ is copied to the end of the line. The character where the light is contained.
      • In normal mode, yw copies a word.
      • In normal mode, y2w copies two words.
      • In normal mode, YG is copied to the end of the text.
      • In normal mode, y1g is copied to the beginning of the text.
    • Paste with P in normal mode
      • In normal mode, the P (lowercase) representation is pasted to the cursor (bottom)
      • In normal mode, the P (uppercase) represents the paste to the front of the cursor (top)

#剪切及粘贴 #

In fact, the first DD Delete command is cut, you can use p to paste each time DD deletes the contents of the document, and this allows us to implement a very refreshing function--exchange up and down line:

DDP, as simple as that, implements a fast exchange cursor where the line is the line below it.

#替换和撤销 (Undo) command #

Both the Replace and undo commands are for normal mode operations

Command

Description

r+< to replace letters >

Replace the letter that contains the cursor with the specified letter

R

Replace continuously until ESC is pressed

Cc

Replace the entire row, which deletes the row of the cursor and enters insert mode

cw

Replace a word, delete a word, and enter insert mode

C (uppercase)

Replace cursor later to end of line

~

Reverses the case of a cursor in the same letter

U{n}

Undo One or N operations

U (uppercase)

Undo all changes to the current line

Ctrl+r

Redo, that is, undo undo operation

#使用命令进行快速调整缩进操作 #

This section learns how to indent quickly in vim and indent operations are effective in normal mode

Open a file for editing

$ VIM Protocols

    • Enter 15G in normal mode, jump to 15 lines
    • Normal mode input >> full line indent right (used to format code super cool)
    • Normal mode input << full line left fallback
    • Normal Mode input: Enter command line mode to set the Shiftwidth value to control the number of characters to indent and rewind

#shiftwidth命令 #

The shiftwidth command refers to the indentation (which can be abbreviated to SW) generated by the previous section >> command input in normal mode: Enter the command line mode to set the Shiftwidth value to control the number of characters in the indent and fallback to get the current set value

: Set shiftwidth?

Set indent to 10 characters

: Set shiftwidth=10

Enter ESC back to normal mode and try >> see if indent changes

#调整文本位置 #

Command line mode input: CE (center) command centers the contents of the bank

: CE

Command-line mode: The RI (right) command causes the bank text to be

: RI

Command line mode input: Le (left) command to leave the contents of the bank

: le

#快速查找 #

Enter in normal mode/then type the string you want to find and then press ENTER to find it. Same AS/function, just? is to look up and/or down. After entering the lookup, enter N and N to continue to find N to continue looking, N reverse Lookup

#高级查找 #

    • Enter \* in normal mode to find the word where the cursor is located
    • Normal mode input \ #同上, but \* is forward (up) to find, #则是向后 (bottom) find
    • Normal mode input g\* with \*, but partially conform to the word can be
    • In normal mode, enter G\ #同 \#, but partially conform to the word

The continue find command for find N,n can still be used

#使用vim编辑多个文件 #

There are two forms of editing multiple files, one being a parameter that is used before entering Vim is multiple files. Another is to enter vim and then edit the other files. Create two new files and edit them simultaneously

$ vim 1.txt 2.txt

Default entry to 1.txt file editing interface

    • Input in command line mode: N edit 2.txt file, you can add! That is: n! force switch, the input of a file is not saved, just switch to another file
    • Command line Mode input: N edit 1.txt file, you can add! That is: n! force switch, the input in the previous file is not saved, just switch to another file

#恢复文件 #

If the document is not saved due to a power outage, you can use the recovery method, Vim-r Enter the document, enter: Ewcover 1.txt to restore

$ vim-r 1.txt

#可视模式命令简介 #

    • In normal mode, enter V (lowercase), enter the character selection mode, you can move the cursor, where the cursor will be selected. The selection is deselected when the V-meeting is pressed again.
    • Enter shift+v (lowercase) In normal mode, enter the line selection mode, press V will be the whole row selection, you can move up and down to select more rows, again, press once shift+v can be deselected.
    • In normal mode, enter Ctrl + V (lowercase), which is the area selection mode, where you can select rectangular regions and then press CTRL + V to deselect them.
    • Enter d in normal mode to delete the selection area
    • Enter y in normal mode to copy the selection area

#视窗操作简介 #

Vim can open multiple windows in one interface for editing, which are called Vim windows. There are many ways to open a method, for example, you can use the input in command-line mode: New opens a fresh vim window, and enters the window to edit a new file (normal mode input ctrl+w can also, but ctrl+w in Chrome will close the tab page with Chrome shortcut keys conflict, So with this shortcut you can practice in IE or another browser, in addition to the: New command, the following list of methods can also be opened in command mode or Normal mode to open the window:

    • Input in command line mode: SP 1.txt opens new landscape window to edit 1.txt
    • Input in command line mode: VSP 2.txt Opens new portrait window to edit 1.txt
    • Ctrl-w s splits the current window into two horizontal windows in normal mode
    • Ctrl-w v in normal mode splits the current window into two vertical windows
    • In normal mode, the Ctrl-w Q is the end of the split window. If you have input in a new window, you need to use the mandatory character! namely: q!
    • Normal mode ctrl-w o opens a window and hides all previous windows
    • Ctrl-w J moves to the following window in normal mode
    • Ctrl-w K moves to the upper window in normal mode
    • Ctrl-w h moves to the left window in normal mode
    • Normal mode ctrl-w l move to the right window
    • Ctrl-w J moves the current window below in normal mode
    • Normal mode ctrl-w K moves the current window to the top
    • Normal mode ctrl-w H moves the current window to the left
    • Normal mode ctrl-w L move the current window to the right
    • Ctrl-w in normal mode-reduces the height of the window
    • Normal mode ctrl-w + increase the height of the window

#创建加密文档 #

$ vim-x File1

Enter your password to confirm the password so that the next time you open, VIM will ask you to enter the password

#在vim执行外部命令 #

Enter in command-line mode! External shell commands can be executed

    • :!ls to display the contents of the current directory
    • :!RM filename is used to delete a file named filename
    • : W FILENAME to save the file you are editing in the current VIM as a filename file

#帮助系统 #

#vim中的查看帮助 #

    • Press F1 in normal mode to open Vim's own preset help document
    • Input in command line mode: H shiftwidth open a Help file named Shiftwidth
    • Input in command line mode: Ver display version and Parameters

#功能设定 #

#vim的功能设定 #

Function settings can be set when editing a file, such as command line mode input: Set Nu (show number of rows), set value exit Vim will not be saved. To permanently save the configuration, you need to modify the Vim configuration file. Vim configuration file ~/.VIMRC, can open files for modification, but be careful not to affect the normal use of vim

#获取目前的设定 #

    • Input in command line mode: Set or: SE shows all modified configurations
    • Input in command line mode: Set all displays all SetPoint values
    • Input in command line mode: SET option? Display the Set value of option
    • command-line Mode input: Set nooption cancel the current set value

#set功能的说明 #

    • Input in command line mode: Set Autoindent (AI) settings Auto Indent
    • command-line Mode input: Set Autowrite (AW) Sets AutoArchive, default not open
    • Input in command line mode: Set Background=dark or light, setting the background style
    • Command line mode input: Set backup (BK) sets automatic backup, default is not turned on
    • Input in command-line mode: Set Cindent (CIN) Set C language style indentation

I have all the vim command practiced two to three times, gradually familiar with their usage, although not all the commands are recorded in the brain, but I put them together, learning at any time to take out to review, I believe that after further study and practice, I will be more familiar with vim command and shortcut keys.

Next, I learned the Linux system programming

#gcc Some source file suffix names that support compilation #

Suffix

source file

. C

C Language Source files

. C. cc. cxx

C + + source files

. m

Object-c source File

. I

Pre-processed C source file

, i+

Pre-processed C + + source files

. S. S

assembly language Source file

. h

preprocessing files (header files)

. o

Target file

. A

Archive file

#gcc the process of compiling the program #

Tips:

    1. Linux executables do not have the obvious. exe suffix name as Windows does, just assign x (executable) permissions to sudo chmod u+x excutefile
    2. As a Linux programmer, we can have GCC end at any stage of the compilation in order to check or use the output of that phase (which is important)

Tips:

    1. GCC Hello.c-o Hello---The second hello is the filename, the name is arbitrarily set (but not in violation of Bash's rules) gcc hello.c-o "(-_-| | |)", but as a good programmer, take a meaningful name!
    2. From the programmer's point of view, a simple-o option can omit many intermediate steps to output an executable file at once; But from the compiler's point of view, behind this command is a series of miscellaneous work.

Note: * In the Xfceterminal Open interface, enter: $GCC hello.c-o Hello * If there is no error, the compilation succeeds, will generate an executable file in the current directory Hello * continue to enter:./hello will run the program, Print Hello on bash, shi-yan-lou!

#GCC背后的故事 #

GCC invokes the preprocessor CPP, which is responsible for expanding the macros defined in the source program (example: #include <stdio.h>), inserting the content contained in the # include statement into it (expand stdio.h included code in place)

Enter in the Xfce terminal

$ gcc-e Hello.c-o hello.i

Do you remember the. i suffix? Hello.I This is a C source file that has been processed by the preprocessor, try this command in bash, and then open it with vim.

The-e parameter of GCC allows GCC to stop the compilation process at the end of preprocessing.

In the second step, the HELLO.I is compiled into the target code, and GCC defaults to the. I file as the pre-preprocessed C-language source code, so it skips the preprocessing directly and begins the compilation process.

$ gcc-c Hello.i-o hello.o

Similarly, open the. o file with vim to see what's different from the. I c file? It's supposed to be a garbled piece, isn't it? (It is already a binary file)

Tips:

    1. Keep in mind that when GCC preprocessed the source file (first step), no syntax errors were checked
    2. The grammar check takes place in the second step, such as curly braces mismatch, no semicolon at the end of the line, keyword error ...

In the third step, the GCC connector links the target file to an executable file, and an approximate compilation process ends

GCC Hello.o-o Hello

#gcc compiling a modular program #

Now a lot of software is the use of modular development, usually a program has a lot of source files, corresponding to the formation of a number of compilation units. GCC is able to handle these compilation units very well and eventually form an executable program

Code editing and input references above use the GVIM program input and use GCC to compile in the Xfceterminal interface.

Hello.h

extern void print ();

Tips: The above gcc hello_print.c hello_main.c-o hello can be seen as executing a 3 command

$ gcc-c Hello_print.c-o HELLO_PRINT.O

$ gcc-c Hello_main.c-o HELLO_MAIN.O

$ gcc hello_print.o hello_main.o-o Hello

Information Security System Design Foundation second week study summary--20135308

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.