初装linux和Mac的一些配置

20 篇文章 1 订阅
6 篇文章 0 订阅

vim简单配置

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


"=========基本配置=========
"=========颜色=========
syntax on           "使得语法高亮显示, syntax enable
"set t_Co=256        "启用256色。
set encoding=utf-8

"=== 设置字体和shell
"=> mac
"set gfn=Menlo:h14
"set shell=/bin/bash
"=> windows
"set gfn=Bitstream\ Vera\ Sans\ Mono:h10
"=> linux
set gfn=Monospace\ 10
set shell=/bin/bash
  
set showmode        "在底部显示,当前处于命令模式还是插入模式。
set showcmd         "命令模式下,在底部显示,当前键入的指令。
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 number          "显示行号,也可以set nu, 不显示set nonu
set cursorline      "光标所在的当前行高亮。
set whichwrap+=<,>,h,l       "光标移动时行尾连接行首
set textwidth=80    "设置行宽,即一行显示多少个字符。
set wrap            "自动折行,即太长的行分成几行显示。
set backspace=2     "允许在自动缩进上退格,在换行符上退格(连接行),在插入开始的位置上退格
                    "等同于 set backspace=indent,eol,start
set laststatus=2    "显示状态行,2:总是,1: 至少两个窗口时,0:永不
set ruler           "标尺。显示光标位置的行号和列号,逗号分隔。
                    "如果还有空间,在最右端显示文本在文件中的相对位置,同set ru
set tabpagemax=9
set cmdheight=2

"=========搜索=========
set hls            "高亮显示搜索结果,同set hlsearch
set showmatch      "光标遇到圆括号、方括号、大括号时,自动高亮对应的另一个圆括号、方括号和大括号。
set matchtime=2    "配合showmatch, 自动跳到配对括号的时间
set incsearch      "输入搜索模式时,每输入一个字符,就自动跳到第一个匹配的结果。
set ignorecase     "搜索时忽略大小写。
set smartcase      "搜索时智能忽略大小写, 忽略第一个字母大写的单词, 其他的不忽略
set magic          "应用于正则表达式

"=========编辑=========
set nobackup       "不创建备份文件。
set noswapfile     "不创建交换文件。
set undofile       "保留撤销历史。

"设置备份文件、交换文件、操作历史文件的保存位置。
 "结尾的//表示生成的文件名带有绝对路径,路径中用%替换目录分隔符,这样可以防止文件重名。
set backupdir=~/.vim/.backup//  
set directory=~/.vim/.swp//
set undodir=~/.vim/.undo// 

set autochdir      "该配置可以将工作目录自动切换到,正在编辑的文件的目录。
set history=1000   "Vim 需要记住多少次历史操作。
set autoread       "打开文件监视。

"命令模式下,底部操作指令按下 Tab 键自动补全。
 "第一次按下 Tab,会显示所有匹配的操作指令的清单;
 "第二次按下 Tab,会依次选择各个指令。"
set wildmenu
set wildmode=longest:list,full


"参考:http://www.ruanyifeng.com/blog/2018/09/vimrc.html

这里有 设置 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:记得重启电脑

安装vim-spf13插件与配置

github代码:spf13/spf13-vim: The ultimate vim distribution
官网:spf13-vim - The Ultimate Vim Distribution

1.下载 spf13-vim,并解压,路径:https://github.com/spf13/spf13-vim
2.运行bootstrap.sh
3.安装命令vim +BundleInstall! +BundleClean +q

Ubuntu常用命令

修改ubuntu root密码

命令:sudo passwd
Ubuntu如何设置root密码(修改root密码)

安装git

Debian/Ubuntu
For the latest stable version for your release of Debian/Ubuntu
# apt-get install git
For Ubuntu, this PPA provides the latest stable upstream Git version
# add-apt-repository ppa:git-core/ppa # apt update; apt install git
other
Download for Linux and Unix

ubuntu更换源

Ubuntu 换源,安装&卸载软件 - 知乎
中科大开源镜像站 LUG’s repo file generator
Ubuntu | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

删除多余内核
# 查看我们当前使用的内核
$ uname -a
# 查看当前我们系统中有哪些内核启动项
$ dpkg --get-selections | grep linux
# 删除内核启动项, 我删除的是linux-image-2.6.32.21-generic,不同人的内核启动项不同
$ sudo apt-get remove linux-image-2.6.32.21-generic

# 之后一路y,即可
# 更新开机启动控制文件
$ sudo update-grub
在 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

Ubuntu在文件夹下内如何右键进入终端(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\]     表示关闭颜色输出

网络问题

【VMware】虚拟机中Ubuntu无法连接网络的有效解决办法
如何让虚拟机的Ubuntu上网? - 知乎

python问题

切换默认python

查看是否有python,利用update-alternatives,它是Debian提供的一个工具。

查看,若无则修改

$ update-alternatives --display python

添加, 优先级数字越大,级别越高

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 2 # 添加Python2可选项,优先级为2
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.4 1 #添加Python3可选项,优先级为1

配置

sudo update-alternatives --config python

Linux下切换默认Python2和Python3的4种方法

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ha-Ha-Interesting

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值