zoukankan      html  css  js  c++  java
  • shell 总结

    君欲善其事 必先利其器~/.vimrc

    if has("syntax")
    syntax on
    endif
    set nocompatible "取消vi 兼容模式
    
    "{{{ paste mode f6,f7
    :map <F6> :set paste<CR>
    :map <F7> :set nopaste<CR>
    :imap <F6> <C-O>:set paste<CR>
    :imap <F7> <nop>
    :set pastetoggle=<F6>
    "}}}
    
    "{{{ fold 
    set foldenable " 开始折叠
    set foldmethod=syntax " 设置语法折叠
    set foldcolumn=0 " 设置折叠区域的宽度
    setlocal foldlevel=0 " 设置折叠层数
    "set foldopen=all     "光标到达折叠快时,自动打开
    set foldclose=all    " 离开代码块后,自动折叠
    " 用空格键来开关折叠
    nnoremap <space> zi 
    
    "}}}
    set mouse=v "可视模式
    set mouse=a     " Enable mouse usage (all modes) 启用鼠标方便翻页,移动光标
    
    set showmatch           " Show matching brackets.
    "set ignorecase     " Do case insensitive matching
    "set smartcase      " Do smart case matching
    
    set nobackup        "no backup
    set autoread  " 设置当文件被改动时自动载入
    set autowrite       " Automatically save before commands like :next and :make
    set hidden      " Hide buffers when they are abandoned
    
    set nu           "show line number
    set ruler            "show cursor site in right below
    set tabstop=4      " 统一缩进为4
    set shiftwidth=4
    set incsearch " 输入字符串就显示匹配点
    set hlsearch " 高亮度搜寻
    set autoindent    "自动缩进
    set cindent
    
    set completeopt=longest,menu
    set completeopt=preview,menu "代码补全
    "{{{start----- 自动补全  -----------------
    :inoremap ( ()<ESC>i
    :inoremap ) <c-r>=ClosePair(')')<CR>
    :inoremap { {<CR>}<ESC>O
    :inoremap } <c-r>=ClosePair('}')<CR>
    :inoremap [ []<ESC>i
    :inoremap ] <c-r>=ClosePair(']')<CR>
    :inoremap " ""<ESC>i
    :inoremap ' ''<ESC>i
    function! ClosePair(char)
    if getline('.')[col('.') - 1] == a:char
       return "<Right>"
    else
       return a:char
    endif
    endfunction
    "}}} "end--------------------------------
    
    
    
    "----- 打开文件类型检测-----------------
    filetype plugin indent on
    
    au BufNewFile,BufRead *.h set filetype=h
    "start---------- definition  SetTitle() ------------------------------------
    
    autocmd BufNewFile *.cpp,*.c,*.h,*.sh,*.java  exec ":call SetTitle()"
    func SetTitle()
        if &filetype == 'sh'
            call setline(1,"#########################################################################")
            call append(line("."), "# File Name: ".expand("%"))
            call append(line(".")+1, "# Author: steven li")
            call append(line(".")+2, "# Created Time: ".strftime("%c"))
            call append(line(".")+3, "#########################################################################")
            call append(line(".")+4, "#!/bin/bash")
            call append(line(".")+5, "")
        else
            call setline(1, "/*************************************************************************")
            call append(line("."), "    > File Name: ".expand("%"))
            call append(line(".")+1, "    > Author: steven li")
            call append(line(".")+2, "    > Created Time: ".strftime("%c"))
            call append(line(".")+3, " ************************************************************************/")
            call append(line(".")+4, "")
        endif
    
        if &filetype == 'cpp'
            call append(line(".")+5, "#include<iostream>")
            call append(line(".")+6, "using namespace std;")
            call append(line(".")+7, "")
            call append(line(".")+8, "int main()")
            call append(line(".")+9, "{")
            call append(line(".")+10, "	")
            call append(line(".")+11, "	return 0;")
            call append(line(".")+12, "}")
        endif
       
        if &filetype == 'h'
            let tem= expand("%")
            let lens= strlen(tem)
            let substr = strpart(tem,0,lens-2)
            let headstr = toupper(substr).'_H'
            call append(line(".")+5, '#ifndef '.headstr)
            call append(line(".")+6, '#define '.headstr)
            call append(line(".")+7, "")
            call append(line(".")+8, " ")
            call append(line(".")+9, "#endif")
            set filetype=cpp
        endif
       
        if &filetype == 'c'
            call append(line(".")+5, "#include<stdio.h>")
            call append(line(".")+6, "")
            call append(line(".")+7, "")
            call append(line(".")+8, "int main()")
            call append(line(".")+9, "{")
            call append(line(".")+10, "	")
            call append(line(".")+11, "	return 0;")
            call append(line(".")+12, "}")
        endif
    
        normal 12G"
    endfunc
    au  BufRead *.h set filetype=cpp
    
    "end----------- SetTitle() --------------------------------
    
    "start------- set title of file of .py ----------
    autocmd BufNewFile *.py  exec ":call SetTitleOfFilePy()"
    func SetTitleOfFilePy()
        call setline(1,"#! /usr/bin/env python")
        call append(line("."), "# -*- coding: UTF-8 -*-")
        call append(line(".")+1, "####################################################################")
        call append(line(".")+2, "# File Name: ".expand("%"))
        call append(line(".")+3, "# Author: steven li")
        call append(line(".")+4, "# Created Time: ".strftime("%c"))
        call append(line(".")+5, "####################################################################")
        call append(line(".")+6, "")
        call append(line(".")+7, "")
        normal 9G
    endfunc
    "end--------------------------------------------
    
    "start------运行.c/.cpp/.java/.sh文件-----------------
    nnoremap <F4> :call CompileRunGcc()<CR>
    func! CompileRunGcc()
        exec "w"
        if &filetype == 'c'
            exec "!g++ % -o %<"
            exec "! ./%<"
        elseif &filetype == 'cpp'
            exec "!g++ % -std=c++11 -o %<"
            exec "! ./%<"
        elseif &filetype == 'java'   :
            exec "!javac %"
            exec "!java %<"
        elseif &filetype == 'sh'
            exec "!chmod +x %"
            :!./%
        endif
    endfunc
    "end------------------------------------------
    "start------运行.py 文件 <F4> ----------------
    
    nnoremap <F3> :call RunPy()<CR>
    func! RunPy()
        exec "w"
        exec "!chmod +x %"
        :!./%
    endfunc
    "end-----------------------------------
    
    "{{{ cscope setting
    if has("cscope")
      set csprg=/usr/bin/cscope
      set csto=1
      set cst
      set nocsverb
      " add any database in current directory
      if filereadable("cscope.out")
          cs add cscope.out
      endif
      set csverb
    endif
    "}}}
    
    "{{{ CtrlP Settings
    " two setting can prevent change of ctrlp_working_path
    set noautochdir
    let g:ctrlp_working_path_mode = 0
    "}}}
    
    "{{{ map ctags,srcExpl,NerdTree:F8,F9,F10,F12
    " Open and close the taglist.vim separately
    nnoremap <F9>  :TrinityToggleTagList<CR>
    " Open and close the srcexpl.vim separately
    nnoremap <F10> :TrinityToggleSourceExplorer<CR>
    " Open and close the NERD_tree.vim separately
    nnoremap <F12>  :TrinityToggleNERDTree<CR>
    " Open and close all the three plugins on the same time
    "nnoremap <F12> :TrinityToggleAll<CR>
    "}}}
    
    
    
    "add command from tutor
    
    
    :let mapleader = "\"
    :let maplocalleader = "\"
    "{{{ my shortcut key
        :nnoremap  <localleader>q :q<cr>
        :nnoremap  <localleader>qq :q!<cr>
        :nnoremap  <localleader>wq :wq<cr>
        :nnoremap  <localleader>wa :wa<cr>
        :nnoremap  <localleader>qa :qa<cr>
        :nnoremap  <localleader>s  :%s/
        :nnoremap  <localleader>sh :ConqueTerm bash <cr>
        :nnoremap  <localleader>shs :ConqueTermSplit bash<cr>
        :nnoremap  <localleader>shv :ConqueTermVSplit bash<cr> 
        :nnoremap  <localleader>sht :ConqueTermTab bash<cr> 
        
        :nnoremap  <localleader>y  "+y<cr>
        :nnoremap  <localleader>yy "+yy<cr>
        :nnoremap  <localleader>yw "+yw<cr>
        :nnoremap  <localleader>/ :/<>
        :nnoremap  <localleader>? :?<>
        
        :inoremap <c-d> <esc>ddo
        :nnoremap <localleader>ev :vsplit$MYVIMRC<cr>
        :nnoremap <localleader>ms :vsplit $VIMRUNTIME/colors/ims.vim<cr>
        :nnoremap <localleader>sv :source$MYVIMRC<cr>
        :inoremap jk <esc>
        :nnoremap <leader>" viw<esc>a"<esc>hbi"<esc>lel
        :nnoremap <leader>' viw<esc>a'<esc>hbi'<esc>lel
        :autocmd FileType cpp nnoremap <buffer> <localleader>c I//<esc>
        :autocmd FileType python     nnoremap <buffer> <localleader>c I#<esc>
        :autocmd FileType python     :iabbrev <buffer> if if()<left>
        :autocmd FileType cpp :iabbrev <buffer> for for(int i=0; i< ; i++)<esc>7h
        :autocmd FileType c   :iabbrev <buffer> for for(int i=0; i< ; i++)<esc>7h
    "}}}
    
    "{{{ cscope cs find
        :nnoremap  <c-@> :cs f 
    "}}}
    
    "{{{ format text
    nmap <tab> V>
    nmap <s-tab> V<
    vmap <tab> >gv
    vmap <s-tab> <gv
    "}}}
    
    "sdvc{{{
    set keywordprg=sdcv -u 朗道英汉字典5.0
    function! Mydict()
        let retstr=system('sdcv '.expand("<cword>"))
        windo if expand("%")=="dict-win" |q!|endif
        30vsp dict-win
        setlocal buftype=nofile bufhidden=hide noswapfile
        1s/^/=retstr/
        1
    endfunction
    nnoremap F :call Mydict()<CR>
    "use sdcv instead man
    :set keywordprg=sdcv
    "}}}
    
    "{{{ minibufexplore settings
    let g:miniBufExplMapWindowNavVim = 1
    let g:miniBufExplMapWindowNavArrows = 1
    let g:miniBufExplMapCTabSwitchBufs = 1
    let g:miniBufExplModSelTarget = 1
    let g:bufExplorerMaxHeight=3
    "}}}
    
    "{{{ Colors Settings
    "colorscheme ims
    set guifont=Consolas:h13:cANSI
    "}}}
    
    
    
    set clipboard+=unnamedplus
    ~/.vimrc

    小技巧:

    不用vim编辑文件:

    ~ cat > test.sh
    echo "ENTER control+D to end editor"

    使用control+D 结束编辑

    随记

    # 系统日志
    cat /dev/null > /var/log/messages
    
    # 当前用户UID
    echo $UID
    echo $SHELL  grep root /etc/passwd
    # 当前用户
    echo $USER
    # 当前用户家目录
    echo $HOME
    # 当前目录
    echo $PWD
    
    
    
    # 使用vim代替vi
    alias vi=vim
    
    # 判断bash版本是否过旧,存在安全隐患
    env x='() { :;}; echo be careful' bash -c "echo this is a test"
    
    # 用户变量加载顺序
    /etc/profile ~/.bash_profile ~/.bashrc /etc/bashrc
    
    用户环境变量变量优先推荐 ~/.bashrc  ~/.bash_profile 
    
    全局变量
    /etc/bashrc 推荐
    /etc/profile
    /etc/profile.d/xxx.sh  登陆后即可显示c
    
    登陆提示:
    /etc/motd
    或
    /etc/profile.d/xxx.sh 
    
    
    # 查看环境变量
    set 显示全局变量 局部变量
    env 显示全局变量
    declare 全局变量 局部变量 函数 整数 
    set -o 显示bash shell的所有参数配置信息
    
    # 自定义环境变量的三种方式
    export 变量名=value
    变量名=value ;export 变量名
    declare -x 变量名=value
    
    declare 可定义变量的类型
    unset 消除本地变量
    
    # head,tail省略 -n参数
    head -1 /etc/init.d/kafka
    tail -3 aa.py
  • 相关阅读:
    JSP注册登录页教程
    SSH框架搭建详细图文教程
    .Net Core2.2升级到3.1小记
    AspNetCore容器化(Docker)部署(四) —— Jenkins自动化部署
    AspNetCore容器化(Docker)部署(三) —— Docker Compose容器编排
    AspNetCore容器化(Docker)部署(二) —— 多容器通信
    AspNetCore容器化(Docker)部署(一) —— 入门
    asp.net core 3.0 gRPC框架小试
    HttpClient Received an unexpected EOF or 0 bytes from the transport stream
    PdfReader按页将PDF切割成多个PDF
  • 原文地址:https://www.cnblogs.com/sunshine-long/p/12665056.html
Copyright © 2011-2022 走看看