Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of MAC/Linux Vi configuration Environment variable and Java Environment variable configuration

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the MAC/Linux Vi configuration environment variables and Java environment variables configuration example analysis, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor with you to understand.

Vi Foundation

1. The basic concept of vi

(1) basically, vi can be divided into three states: command mode (command mode), insert mode (Insert mode) and bottom line mode (last line mode). The functions of each mode are as follows:

1) Command line mode command mode)

Control the movement of the screen cursor, the deletion of characters, words or lines, move and copy a section and enter the Insert mode, or to the last line mode.

2) insert mode (Insert mode)

Text input can only be done under Insert mode, and press the "ESC" key to return to command line mode.

3) bottom line mode (last line mode)

To save or exit vi, you can also set the editing environment, such as finding strings, listing line numbers, etc. Wait.

(2) Mode switching

Vi has three basic working modes: command line mode, text input mode, and end-of-line mode. Their interrelationship is shown in.

Enter a, I, o into text input mode (Input Mode) in instruction mode (Command Mode)

Press ESC in text input mode (Input Mode) to enter instruction mode (Command Mode)

Input in instruction mode (Command Mode): enter last line mode (Last line Mode)

If an instruction error occurs in the last line mode (Last line Mode), the instruction mode (Command Mode) is returned.

However, when we use vi, we usually simplify it into two modes, that is, the last line mode mode is also included in the command line mode command mode).

2. Basic operation of vi

A) enter vi

After the system prompts for the symbol vi and the file name, go to the vi full screen editing screen:

$vi myfile

It is important to note, however, that after you enter vi, you are in "command line mode (command mode)", and you have to switch to "insert mode (Insert mode)" before you can enter text. People who use vi for the first time will want to use the upper and lower keys to move the cursor first, and as a result, the computer beeps all the time, making themselves angry half to death, so after entering the vi, don't move, switch to "insert mode (Insert mode)".

B) switch to insert mode (Insert mode) to edit the file

Press the letter "I" in "command line mode (command mode)" to enter "insert mode (Insert mode)" and you can start typing text.

C) switching of Insert

You are currently in Insert mode mode, so you can only type text all the time if you find that you have typed the wrong word! To use the cursor key to move back and delete the word, press the "ESC" key to go to "command line mode (command mode)" before deleting the text.

D) exit vi and save the file

Under Command Line Mode (command mode), click the: colon key to enter Last line mode, for example:

W filename (enter "w filename" to save the article with the specified file name filename)

: wq (enter "wq", save and exit vi)

: q! (enter qquit, do not save the disk and force to exit vi)

3. Command line mode (command mode) function key

1)。 Insert mode

Press "I" to switch to insert mode "insert mode". Press "I" to enter the file from the current position of the cursor after entering insert mode

After pressing "a" to enter insert mode, the text is entered from the next position where the current cursor is located.

When you press "o" to enter insert mode, insert a new line and enter text at the beginning of the line.

2)。 Switch from insert mode to command line mode

Press the ESC key.

3)。 Move the cursor

Vi can directly use the cursor on the keyboard to move up and down, but the regular vi uses lowercase letters "h", "j", "k" and "l" to control the cursor to move left, down, up and right respectively.

Press "ctrl" + "b": move the screen one page back.

Press "ctrl" + "f": the screen moves one page forward.

Press "ctrl" + "u": move the screen to "back" half a page.

Press "ctrl" + "d": move the screen half a page to the front.

Press the number "0": move to the beginning of the article.

Press "G": move to the end of the article.

Press "$": move to the end of the line where the cursor is located.

Press "^": move to the beginning of the line where the cursor is located

Press "w": the cursor jumps to the beginning of the next word

Press "e": the cursor jumps to the suffix of the next word

Press "b": the cursor goes back to the beginning of the previous word

Press "# l": move the cursor to the # th position on the line, for example: 5lMagne56l

4)。 Delete text

"x": each time you press, delete the "after" character of the cursor location.

"# x": for example, "6x" means to delete "after" 6 characters where the cursor is located.

"X": uppercase X. each time you press it, one character in front of the cursor is deleted.

"# X": for example, "20X" means to delete the "first" 20 characters where the cursor is located.

"dd": delete the line of the cursor.

"# dd": delete # lines from the line where the cursor is located

5)。 Copy

"yw": copies the character where the cursor is located to the suffix into the buffer.

"# yw": copy # words to the buffer

"yy": copies the line of the cursor to the buffer.

"# yy": for example, "6yy" means to copy "count down" six lines of text from the line where the cursor is located.

"p": paste the characters in the buffer to the position of the cursor. Note: all copy commands related to "y" must work with "p" to complete the copy and paste function.

6)。 Replace

"r": replace the character where the cursor is located.

"R": replaces the character where the cursor goes until the "ESC" key is pressed.

7)。 Reply to the last operation

"u": if you execute a command by mistake, you can press "u" immediately to go back to the previous operation. Press "u" multiple times to perform multiple replies.

8)。 Change

"cw": change the word where the cursor is located to the suffix

"c3w": for example, "c3w" means to change 3 words

9)。 Skip to the specified line

"ctrl" + "g" lists the line number of the cursor.

"# G": for example, "15G" means to move the cursor to the beginning of line 15 of the article.

4. Brief introduction of commands under Last line mode

Before using "last line mode", remember to press the "ESC" key to make sure you are under "command mode", and then press the ":" colon to enter "last line mode".

A) list line number

"set nu": after entering "set nu", the line number is listed before each line in the file.

B) skip to a line in the file

The "#" sign represents a number. Enter a number after the colon and press enter to jump to the line. If you enter the number 15 and enter again, you will jump to line 15 of the article.

C) find characters

"/ keyword": first press the "/" key, and then enter the character you are looking for. If the keyword you are looking for for the first time is not what you want, you can press "n" until you find the keyword you are looking for.

"? Keyword ": press the"? "key, and then enter the character you are looking for. If the keyword you are looking for for the first time is not what you want, you can press" n "until you find the keyword you are looking for.

D) Save the file

"w": type the letter "w" in the colon to save the file.

E) leave vi

"Q": press "Q" to quit. If you can't leave vi, you can force you to leave vi after "Q".

"qw": it is generally recommended to use it with "w" when you leave, so that you can save the file when you exit.

5. Vi command list

1. The following table lists the functions of some keys in command mode:

H

Move the cursor one character to the left

L

Move the cursor one character to the right

K

Move the cursor up one line

J

Move the cursor down one line

^

Move the cursor to the beginning of the line

0

The number "0", move the cursor to the beginning of the article

G

Move the cursor to the end of the article

$

Move the cursor to the end of the line

Ctrl+f

Flip the screen forward

Ctrl+b

Flip the screen backward

Ctrl+d

Turn half the screen forward

Ctrl+u

Turn back half the screen

I

Insert a character before the cursor position

A

The last character at the position of the cursor begins to increase.

O

Insert a new line and type at the beginning of the line

ESC

Retreat from input state to command state

X

Delete the characters after the cursor

# x

# characters after the cursor is deleted

X

(capital X), delete the characters in front of the cursor

# X

Delete # characters in front of the cursor

Dd

Delete the line where the cursor is located

# dd

Delete # lines from the number of lines in which the cursor is located

Yw

Copy a word at the location of the cursor

# yw

Copy # words of the location of the cursor

Yy

Copy the line where the cursor is located

# yy

Copy # lines from the number of lines where the cursor is located

P

Paste

U

Cancel the operation

Cw

Change the position of the cursor in # words

# cw

2. The following table lists some instructions in the line command mode.

W filename

Save the file being edited as filename

Wq filename

Save the file you are editing as filename and exit vi

Q!

Discard all changes and exit vi

Set nu

Show line number

/ or?

Find, enter what you are looking for after /

N

And / or? Use together, if the search is not the keyword you are looking for, press n or backward (in conjunction with / with) or forward (with? Keep searching until you find it.

For using vi for the first time, here are a few caveats:

1. After opening the file with vi, you are in "command line mode (command mode)", and you have to switch to "insert mode (Insert mode)" before you can enter text. Switching method: press the letter "I" in "command line mode (command mode)" to enter "insert mode (Insert mode)", and you can start typing text.

2, after editing, you need to switch from insert mode to command line mode to save the file, the switching method: press the "ESC" key.

3. Save and exit the file: type: wq in command mode! (don't forget the one in front of wq:)

MAC environment variable setting *

Mac boot load file location (environment variable can be set)

(1) first of all, you need to know what kind of Shell you are using Mac OS X, use the command

Echo $SHELL

If the output is csh or tcsh, then you are using C Shell.

If the output is: bash,sh,zsh, then you may be using a variant of Bourne Shell.

Before Mac OS X 10.2, the default was C Shell.

After Mac OS X 10.3, the default is Bourne Shell.

(2) if it is Bourne Shell.

Then you can add the environment variable you want to add to .profile or .bash _ profile under your home directory, if it doesn't matter, if it doesn't generate one.

Where Mac configures environment variables

1./etc/profile (it is not recommended to modify this file)

Global (public) configuration, no matter which user, will read the file when logging in.

2./etc/bashrc (usually add system-level environment variables to this file)

Global (public) configuration, this file will be read no matter how the bash shell is executed.

3.~/.bash_profile (usually add user-level environment variables to this file)

Each user can use this file to enter shell information dedicated to their own use, and the file is executed only once when the user logs in!

MAC modifies the host file

Sudo vi / etc/hosts

View and add PATH environment variables under linux

The format of PATH is:

The PATH=$PATH::::...:, is separated by a colon.

Add the PATH environment variable:

Export PATH=/opt/STM/STLinux-2.3/devkit/sh5/bin:$PATH

View the PATH environment variables:

[root@localhost u-boot-sh5] # echo $PATH/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

Example of operation:

Change the PATH by editing the startup file

Vim / etc/profile

At the end of the document, add:

Export PATH= "/ opt/STM/STLinux-2.3/devkit/sh5/bin:$PATH"

Save, exit.

To take effect immediately, run:

Source / etc/profile

If you don't report a mistake, you will succeed.

If you want to take effect immediately, you can execute the following statement:

$source .bash _ profile (this is the file name)

After the environment variable is changed, it will take effect the next time the user logs in.

Example of setting Java environment variables

Open terminal and enter the following command

Vi .bash _ profile

If there is an E325 error, enter e to edit, indicating that the file already exists. Add some code after entering the edit.

If PATH is configured previously, the value of the Java environment is appended with. $PATH when configuring Java.

Then use export to execute the key-value pair, so the value is a string and needs to be quoted, otherwise it will not be recognized

JAVA_HOME= "/ Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home" export JAVA_HOMECLASS_PATH= "$JAVA_HOME/lib" PATH= ". $PATH:$JAVA_HOME/bin" export PATH

[note] is a symbol in the English state

Then press Esc to return to the last line mode and type: wq to save and exit

Echo $PATH can output the value of the newly configured PATH

Thank you for reading this article carefully. I hope the article "sample Analysis of MAC/Linux Vi configuration Environment variables and Java Environment variable configuration" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 269

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report