码农必备技能
vim 使用:
Navigating:
%: Jump to matching bracket
>: Indent
<: de-indent
=: Properly Indent
=+G: Format code
~: Change case of character
>+%: Indent block
Navigating words: web, WEB
Navigating lines: $, 0, ^,g_,-,+,<return>
Navigating sentences and paragraphs: {,}, (braces), (,), (parantheses)
Navigaring screen: H, L, M, ctrl+e, ctrl+y
Navigating large file: gg, G, ctrl+b, ctrl+f, ctrl+u, ctrl+d, z+<return>, z+., z+
Editing:
Inserting and appending : i, a, I, A,o, O,
Undo and redo: u, U, ctrl+r
U: undo an entire line.
Replacing text: r, R, ~, c, C, cw,
Delete: x, X, dd, d, .
Cutting and pasting: d, p, P, y, Y
Text object:
Delete a word : daw, diw, ciw, caw
dis, das, dip, dap
Searching:
Searching characters: f, F, t, T, ;, ,
Searching words: /, ?, n, N, #, *
Register:
"[1-9] history registers "0 the yank register "[a-z] are named registers "[A-Z] same as "[a-z] but append "/ current search pattern "- small delete "= expression register "_ the blank hole register
"read-only registers ": last : command ". last inserted text "% filename of the current buffer
Multiple window:
:vs
:sp
Ctrl+ww, Ctrl+ww
, Ctrl+wj
, Ctrl+wk
, Ctrl+wl
, Ctrl+wh
Vertical increase ctrl +w + +
Horisotal increase: ctrl+w + >
Switch the tabs opened by :tabedit command:
gt // Next tab gT // Prior tab <number> gt // Numbered tab
My .vimrc file
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'tpope/vim-vinegar'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
" let g:airline_powerline_fonts = 1
" if !exists('g:airline_symbols')
" let g:airline_symbols={}
" endif
syntax enable
set number relativenumber
set autoindent
set tabstop=4
set softtabstop=4
set shiftwidth=4
set wildmenu
set nobackup
set nowritebackup
set noswapfile
set enc=utf-8
set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
"set langmenu=zh_CN.UTF-8
set helplang=en
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}
set statusline=[%F]%y%r%m%*%=[Line:%l/%L,Column:%c][%p%%]
" 在被分割的窗口间显示空白,便于阅读
""set fillchars=vert:\ ,stl:\ ,stlnc:\
" 高亮显示匹配的括号
set showmatch
" 匹配括号高亮的时间(单位是十分之一秒)
set matchtime=1
" 光标移动到buffer的顶部和底部时保持3行距离
set scrolloff=3
" 为C程序提供自动缩进
set smartindent
" 高亮显示普通txt文件(需要txt.vim脚本)
"" au BufRead,BufNewFile * setfiletype txt
"自动补全
: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
filetype plugin indent on
"打开文件类型检测, 加了这句才可以用智能补全
""set completeopt=longest,menu
"---------------Mappings----------------"
let mapleader = ','
imap jk <ESC>
nnoremap ,ev :tabedit ~/.vimrc<cr>
set backspace=indent,eol,start
"---------------Auto-Commands----------------"
autocmd BufWritePost .vimrc source %
inoremap <C-u> <esc>gUiwea
map <F5> :call CompileRunGcc()<CR> func! CompileRunGcc() # The ! is needed to unset the function declared before exec "w" if &filetype == 'c' exec "!g++ % -o %<" exec "! ./%<" elseif &filetype == 'cpp' exec "!g++ % -o %<" exec "! ./%<" elseif &filetype == 'java' exec "!javac %" exec "!java %<" elseif &filetype == 'sh' :!sh % elseif &filetype == 'python' :!python3 % elseif &filetype == 'go' :!go run % endif endfunc augroup ShellCmds autocmd! # Delete all previours autocmd autocmd Filetype sh call setline(1,"\#!/usr/bin/bash") augroup END
grep sed awk
grep "^G" test.txt grep "m$" test.txt grep "^$" test.txt grep -v "^$" test.txt grep -vn "^$" test.txt grep "." test.txt grep ".*" test.txt grep "x..u" test.txt grep "\.$" test.txt grep -o "8*" test.txt grep [abc] test.txt grep "8\{3\}" test.txt egrep "8{3}" test.txt grep -E "8{3}" test.txt #options: -r #support expand meta character -n # omit default output #command a c d i sed -i '30a listen80' passwd.txt sed -i '30a \\t listen80;' passwd.txt sed '/^SELINUX/p' /etc/selinux/config sed -i '/^SELINUX/c SELINUX=Disabled' /etc/selinux/config sed -i '7c SELINUX=Disabled' /etc/selinux/config sed 's/root/rt' passwd.txt sed 's/root/rt/g' passwd.txt $0 #save file content NR # number of line FNR # The input record number in the current input file awk 'NR<3{print $0}' passwd.txt awk '{print NR $0}' passwd.txt awk 'BEGIN{RS=":"}{print $0}' passwd.txt awk -F: '{if($3==0){print $1 " is admin"}}' passwd.txt
Git 基本命令
configuration
* System : /etc/gitconfig
* Global : ~/.gitconfig
* git config --global user.name "xxx"
* git config --global user.email "xxx@163.com"
* git config --global color.ui true
* Local : .git/config
* git config user.name "xxx"
git config --list
git reset --hard commitID
History
git log --abbrev-commit git log --oneline --graph --decorate git log f05d8a3...8792d97 git log --since="3 days ago" git log -- inner_attr.py git log --follow -- inner_attr.py git show f05d8a
git mv inner_attr.py attr.py git ls-files git checkout -- deleted_file git log --all --graph --decorate --oneline git config --global alias.hist "log --all --graph --decorate --oneline" git config --global diff.tool BCompare git config --global difftool.BCompare.path /Applications/Beyond\ Compare.app/Contents/MacOS/BCompare git config --global difftool.prompt false git config --global merge.tool BCompare git config --global mergetool.BCompare.path /Applications/Beyond\ Compare.app/Contents/MacOS/BCompare git config --global mergetool.prompt false git config --global --list git config --global -e masons-MacBook-Pro:Python_exercise mason$ git difftool git config option diff.tool set to unknown tool: BCompare Resetting to default... This message is displayed because 'diff.tool' is not configured. See 'git difftool --tool-help' or 'git help config' for more details. 'git difftool' will now attempt to use one of the following tools: opendiff kompare emerge vimdiff xcode-select: error: tool 'opendiff' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/
branch
git diff 5194c5b HEAD
git difftool 5194c5b HEAD
git diff master origin/master
git difftool master origin/master
git branch -a
git branch -m oldbranch newbranch #change branch name
git branch -d newbranch
git branch -D newbranch
git checkout -b dev_x
git difftool master dev_x
git merge dev_x # Automatic merge, if conflict happens, add backup file to .gitignore
git merge dev_x --no-ff # disable fast forward merge
git stash
git stash apply
git stash list
git stash drop
git rebase --abort
git rebase --continue
git pull --rebase origin master
git rebase -i
git stash save "simple changes"
git show stash@{1}
git stash apply stash@{1}
git stash drop stash@{1}
git stash branch newchanges
git cat-file -t 0c96bf
git cat-file -p 0c96bf
git tag --list
git tag -a v-1.0
git push origin v-1.1
git push origin master --tags
VS code
Vscode vim 模式下持续按键无法移动光标
# To disable the Apple press and hold for VSCode only defaults write com.microsoft.VSCode ApplePressAndHoldEnabled -bool false

浙公网安备 33010602011771号