初装linux和Mac的一些配置

版权声明:本文为Ye pengyu原创文章,随意转载,但是请注明出处。内容自: https://blog.csdn.net/BjarneCpp/article/details/78679891

vim

拷贝vimrc到/home/下,并且改名为.vimrc
(文件vimrc一般在/usr/share/vim下)
添加内容:

syntax on           "使得语法高亮显示

set hls            "高亮显示搜索结果,同set hlsearch
"set nohls          "关闭高亮

set mouse=a         "在所有的模式上使用鼠标
"set mouse-=a       "不使用鼠标
set smartindent     "开启新行时使用智能自动缩进
set tabstop=4       "文件里的<Tab>代表的空格数
set shiftwidth=4    "(自动)缩进每一步使用的4个空格
set softtabstop=4   "插入<Tab>或者使用<BS>时,把<Tab>算作4个空格
set expandtab       "插入<Tab>时使用合适数量的空格
"set noexpandtab    "使插入<Tab>时不使用空格
set number          "显示行号,也可以set nu
"set nonumber       "取消行号显示,也可以=set nonu
set backspace=2    "允许在自动缩进上退格,在换行符上退格(连接行),在插入开始的位置上退格
"set backspace=0    "等同于 set backspace= (Vi 兼 容 )
"set backspace=1    "等同于 set backspace=indent,eol
"set backspace=2    "等同于 set backspace=indent,eol,start

set laststatus=2    "显示状态行,2:总是,1: 至少两个窗口时,0:永不
set ruler           "标尺。显示光标位置的行号和列号,逗号分隔。
                    "如果还有空间,在最右端显示文本在文件中的相对位置,同set ru

这里有 设置 Vim c语言的语法高亮

苹果电脑Mac安装vim(资源地址

1. ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2. brew install macvim ctags git
3. cd ~ && git clone https://github.com/ruchee/vimrc.git
4. rm -rf ~/.vimrc ~/.vim
5. ln -s ~/vimrc/vimfiles ~/.vim && ln -s ~/vimrc/_vimrc ~/.vimrc
6. finished, enjoy

来自:
https://www.zhihu.com/question/28796264/answer/42147165

Debian/Ubuntu和Mint 下载安装vim8.0

来源:链接

sudo apt install ncurses-dev
wget https://github.com/vim/vim/archive/master.zip
unzip master.zip
cd vim-master
cd src/
./configure
make
sudo make install
vim

PS:记得重启电脑

在 Ubuntu 13.10, 13.04, 12.04等linux上升级 Vim 7.4

来源:链接
Vim 7.4 is available in the default repositories of Ubuntu 13.10 Saucy Salamander, Linux Mint 16 Petra and Debian Sid, so installing it on Ubuntu and Linux Mint is easy. All you have to do is:

sudo apt-get update  
sudo apt-get install vim  

To install Vim 7.4 on Ubuntu 13.04 Raring Ringtail, Ubuntu 12.04 Precise Pangolin, Linux Mint 15 Olivia and Linux Mint 13 Maya, we have to add a third-party PPA. Do this for a successful installation:

sudo add-apt-repository ppa:fcwu-tw/ppa

sudo apt-get update

sudo apt-get install vim

Linux在文件夹下内如何右键进入终端(Terminal)

打开终端,输入如下命令:sudo apt-get install nautilus-open-terminal


设置shell,修改rm指令为mv,防止误删文件

因为,经常用到rm指令,有时候稍不留心,在删除xx.c~时不小心把xx.c给删除了,因此,有必要把rm指令改一下,防止误删文件。
另外,我这有个缺陷,就是用到真正的rm指令时,还需要改成这样:rmOPEN = 1,再输入命令source ~/.cshrc设置一下,就能把rm还原了。

  1. 查看使用的shellecho $SHELL
    我的显示为/tool/pandora/bin/tcsh,因此,我的shell用的是tcshell
  2. 一般用默认的文件名.chsrc,用vim ~/.cshrc 即可编辑
#!/tool/pandora/bin/tcsh

set rmOPEN = 0
if($rmOPEN) then
    alias rm 'rm'
else
    #删除文件,xxx为usermame
    alias rm '/home/xxx/.cshrc_rm.sh'
endif

# 恢复删除的文件
alias ur '/home/xxx/.cshrc_ur.sh'

3.文件.cshrc_rm.sh

#!/tool/pandora/bin/tcsh

#将要删除的文件移动到trash下(自己新建一个trash文件夹)
mv $argv[*] /home/xxx/trash

4.文件.cshrc_ur.sh

#!/tool/pandora/bin/tcsh

#计算出argv从1开始的参数个数
set num = $#argv

while($num)
    mv -i /home/xxx/trash/$argv[num] ./
    echo $argv[num] 'recovery'
    @ num--
end

5.source ~/.cshrc,在shell下输入如下指令试试

$ mkdir file
$ rm file
$ ur file
$ mkdir file1 file2 file3
$ rm file1 file2 file3
$ ur file1 file2 file3

argv存储了所有的命令行参数, 每个参数(以空白符分隔)占用一个argv[i]。
argv[0] 在linux指令中为空
argv[1] 为第一个参数比如 file1
argv[2] 为第二个参数比如 file2
argv[3] 为第三个参数比如 file3
若用arg[*],表示所有参数
用$#argv,可以获得参数的个数,从1开始计数,这里是3

参考文件:
tcsh入门 - BlogJava
csh 语法实例参考 | 学步园
csh 语法实例参考 - iTech - 博客园
Csh的基本语法介绍_linux shell_脚本之家


Mac安装软件时提示已损坏的解决方法

Mac从网上下载的软件(或者破解版),安装时提示验证不通过,安装时总是提示“已损坏,移至废纸篓”这类信息,根本无法打开。
一般我们去这里设置,打开系统偏好设置 > 安全性与隐私 > 通用 > 允许从以下位置下载的应用:,但是没有“任何来源”这一选项。
可以打开终端输入:sudo spctl --master-disable(建议直接复制粘贴,若手输则注意空格横线)回车,之后就可以看见“任何来源”这一选项了。
具体见:Mac安装软件时提示已损坏的解决方法

.bashrc配置prompt,PS1

我的配置结果:

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    #PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    #重点下面这句:
    PS1='\[\033[01;33m\][\D{%y-%m-%d} \t]\[\033[00m\]\[\033[01;32m\][\!]\[\033[00m\]${debian_chroot:+($debian_chroot)}\[\033[01;37m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\n  \[\033[05;35m\]\$ \[\033[00m\]'
    ;;
*)

效果如下:
root用户:
root用户
普通用户:
普通用户

参考资料:
关于linux下的PS1的设定与PATH的设定 - a827415225的专栏 - CSDN博客

man bash文件:

 PROMPTING
When executing interactively, bash displays the primary prompt PS1 when it is ready
to read a command, and the secondary prompt PS2 when it needs more  input  to  com‐
plete  a  command.  Bash displays PS0 after it reads a command but before executing
it.  Bash allows these prompt strings to be customized by  inserting  a  number  of
backslash-escaped special characters that are decoded as follows:
   \a     an ASCII bell character (07)
   \d     the date in "Weekday Month Date" format (e.g., "Tue May 26")
   \D{format}
      the  format  is passed to strftime(3) and the result is inserted into
      the prompt string; an empty format results in a locale-specific  time
      representation.  The braces are required                                       
   \e     an ASCII escape character (033)
   \h     the hostname up to the first `.'
   \H     the hostname
   \j     the number of jobs currently managed by the shell
   \l     the basename of the shell's terminal device name
   \n     newline
   \r     carriage return
   \s     the  name of the shell, the basename of $0 (the portion following the
      final slash)
   \t     the current time in 24-hour HH:MM:SS format
   \T     the current time in 12-hour HH:MM:SS format
   \@     the current time in 12-hour am/pm format
   \A     the current time in 24-hour HH:MM format
   \u     the username of the current user
   \v     the version of bash (e.g., 2.00)
   \V     the release of bash, version + patch level (e.g., 2.00.0)
   \w     the current working directory, with $HOME abbreviated  with  a  tilde
      (uses the value of the PROMPT_DIRTRIM variable)
   \W     the basename of the current working directory, with $HOME abbreviated
      with a tilde
   \!     the history number of this command
   \#     the command number of this command
   \$     if the effective UID is 0, a #, otherwise a $
   \nnn   the character corresponding to the octal number nnn
   \\     a backslash
   \[     begin a sequence of non-printing characters, which could be  used  to
      embed a terminal control sequence into the prompt
   \]     end a sequence of non-printing characters                                  

The command number and the history number are usually different: the history number
of a command is its position in  the  history  list,  which  may  include  commands
restored from the history file (see HISTORY below), while the command number is the
position in the sequence of commands executed during  the  current  shell  session.
After  the  string is decoded, it is expanded via parameter expansion, command sub‐
stitution, arithmetic expansion, and quote removal, subject to  the  value  of  the
promptvars  shell  option  (see  the  description  of the shopt command under SHELL
BUILTIN COMMANDS below).
颜色表 
前景  背景   颜色
------------------------
30    40    黑色
31    41    紅色
32    42    綠色
33    43    黃色
34    44    藍色
35    45    紫紅色
36    46    青藍色
37    47    白色

代码    意义
------------------------
0      OFF
1      高亮显示
4      underline
5      闪烁
7      反白显示
8      不可见
------------------------
/e[开头或者\033[开头,m结尾的格式可以定义一种颜色,
我们可以通过设置PS1变量使提示符成为彩色。
在PS1中设置字符序列颜色的格式为:
\[\e[F;Bm\]
其中``F''为字体颜色,编号30~37;``B''为背景色,编号40~47。
可通过``\e[0m''关闭颜色输出;特别的,当B为1时,将显示加亮加粗的文字,详细请看下面的颜色表与代码表

举例:
\[\033[01;33m\]  表示高亮显示,前景色33黄色
\[\033[05;35m\]  表示闪烁显示,前景色35紫红色
\[\033[00m\]     表示关闭颜色输出

没有更多推荐了,返回首页