2011-12-13 10:21:42 +08:00
|
|
|
|
" ========================================
|
|
|
|
|
" General vim sanity improvements
|
|
|
|
|
" ========================================
|
|
|
|
|
"
|
2012-01-21 10:01:06 +08:00
|
|
|
|
"
|
2011-12-16 14:20:51 +08:00
|
|
|
|
" alias yw to yank the entire word 'yank inner word'
|
|
|
|
|
" even if the cursor is halfway inside the word
|
|
|
|
|
" FIXME: will not properly repeat when you use a dot (tie into repeat.vim)
|
|
|
|
|
nnoremap ,yw yiww
|
|
|
|
|
|
|
|
|
|
" ,ow = 'overwrite word', replace a word with what's in the yank buffer
|
|
|
|
|
" FIXME: will not properly repeat when you use a dot (tie into repeat.vim)
|
2012-01-21 10:43:49 +08:00
|
|
|
|
nnoremap ,ow "_diwhp
|
2011-12-16 14:20:51 +08:00
|
|
|
|
|
2011-12-13 12:42:54 +08:00
|
|
|
|
"make Y consistent with C and D
|
|
|
|
|
nnoremap Y y$
|
2013-06-17 03:10:45 +08:00
|
|
|
|
function! YRRunAfterMaps()
|
|
|
|
|
nnoremap Y :<C-U>YRYankCount 'y$'<CR>
|
|
|
|
|
endfunction
|
2011-12-13 10:21:42 +08:00
|
|
|
|
|
2014-01-26 02:56:54 +08:00
|
|
|
|
" Make 0 go to the first character rather than the beginning
|
|
|
|
|
" of the line. When we're programming, we're almost always
|
|
|
|
|
" interested in working with text rather than empty space. If
|
|
|
|
|
" you want the traditional beginning of line, use ^
|
|
|
|
|
nnoremap 0 ^
|
|
|
|
|
nnoremap ^ 0
|
|
|
|
|
|
2012-05-08 14:55:41 +08:00
|
|
|
|
" ,# Surround a word with #{ruby interpolation}
|
|
|
|
|
map ,# ysiw#
|
2012-05-10 08:54:30 +08:00
|
|
|
|
vmap ,# c#{<C-R>"}<ESC>
|
|
|
|
|
|
|
|
|
|
" ," Surround a word with "quotes"
|
2012-05-08 14:55:41 +08:00
|
|
|
|
map ," ysiw"
|
2012-05-10 08:54:30 +08:00
|
|
|
|
vmap ," c"<C-R>""<ESC>
|
|
|
|
|
|
|
|
|
|
" ,' Surround a word with 'single quotes'
|
|
|
|
|
map ,' ysiw'
|
|
|
|
|
vmap ,' c'<C-R>"'<ESC>
|
|
|
|
|
|
|
|
|
|
" ,) or ,( Surround a word with (parens)
|
|
|
|
|
" The difference is in whether a space is put in
|
|
|
|
|
map ,( ysiw(
|
|
|
|
|
map ,) ysiw)
|
|
|
|
|
vmap ,( c( <C-R>" )<ESC>
|
|
|
|
|
vmap ,) c(<C-R>")<ESC>
|
|
|
|
|
|
|
|
|
|
" ,[ Surround a word with [brackets]
|
|
|
|
|
map ,] ysiw]
|
|
|
|
|
map ,[ ysiw[
|
|
|
|
|
vmap ,[ c[ <C-R>" ]<ESC>
|
|
|
|
|
vmap ,] c[<C-R>"]<ESC>
|
|
|
|
|
|
|
|
|
|
" ,{ Surround a word with {braces}
|
|
|
|
|
map ,} ysiw}
|
|
|
|
|
map ,{ ysiw{
|
|
|
|
|
vmap ,} c{ <C-R>" }<ESC>
|
|
|
|
|
vmap ,{ c{<C-R>"}<ESC>
|
2012-05-08 14:55:41 +08:00
|
|
|
|
|
2013-08-05 06:58:12 +08:00
|
|
|
|
map ,` ysiw`
|
|
|
|
|
|
2012-04-16 03:31:56 +08:00
|
|
|
|
" gary bernhardt's hashrocket
|
|
|
|
|
imap <c-l> <space>=><space>
|
|
|
|
|
|
2011-12-18 05:27:01 +08:00
|
|
|
|
"Go to last edit location with ,.
|
|
|
|
|
nnoremap ,. '.
|
|
|
|
|
|
2012-01-23 10:47:55 +08:00
|
|
|
|
"When typing a string, your quotes auto complete. Move past the quote
|
|
|
|
|
"while still in insert mode by hitting Ctrl-a. Example:
|
|
|
|
|
"
|
|
|
|
|
" type 'foo<c-a>
|
|
|
|
|
"
|
|
|
|
|
" the first quote will autoclose so you'll get 'foo' and hitting <c-a> will
|
|
|
|
|
" put the cursor right after the quote
|
|
|
|
|
imap <C-a> <esc>wa
|
|
|
|
|
|
2011-12-16 12:01:38 +08:00
|
|
|
|
" ==== NERD tree
|
2012-10-03 12:57:29 +08:00
|
|
|
|
" Open the project tree and expose current file in the nerdtree with Ctrl-\
|
2016-04-29 04:22:53 +08:00
|
|
|
|
" " calls NERDTreeFind iff NERDTree is active, current window contains a modifiable file, and we're not in vimdiff
|
|
|
|
|
function! OpenNerdTree()
|
|
|
|
|
if &modifiable && strlen(expand('%')) > 0 && !&diff
|
|
|
|
|
NERDTreeFind
|
|
|
|
|
else
|
|
|
|
|
NERDTreeToggle
|
|
|
|
|
endif
|
|
|
|
|
endfunction
|
|
|
|
|
nnoremap <silent> <C-\> :call OpenNerdTree()<CR>
|
2011-12-16 12:01:38 +08:00
|
|
|
|
|
2014-02-16 11:08:32 +08:00
|
|
|
|
" ,q to toggle quickfix window (where you have stuff like Ag)
|
2011-12-17 16:46:02 +08:00
|
|
|
|
" ,oq to open it back up (rare)
|
2013-12-16 05:02:54 +08:00
|
|
|
|
nmap <silent> ,qc :cclose<CR>
|
2012-01-21 10:43:49 +08:00
|
|
|
|
nmap <silent> ,qo :copen<CR>
|
2011-12-17 16:46:02 +08:00
|
|
|
|
|
2012-02-11 06:59:48 +08:00
|
|
|
|
"Move back and forth through previous and next buffers
|
|
|
|
|
"with ,z and ,x
|
|
|
|
|
nnoremap <silent> ,z :bp<CR>
|
|
|
|
|
nnoremap <silent> ,x :bn<CR>
|
2011-12-13 10:21:42 +08:00
|
|
|
|
|
2011-12-16 16:04:14 +08:00
|
|
|
|
" ==============================
|
|
|
|
|
" Window/Tab/Split Manipulation
|
|
|
|
|
" ==============================
|
2014-10-25 05:28:04 +08:00
|
|
|
|
" Move between split windows by using the four directions H, L, K, J
|
|
|
|
|
" NOTE: This has moved to vim/settings/vim-tmux-navigator.vim.
|
|
|
|
|
" nnoremap <silent> <C-h> <C-w>h
|
|
|
|
|
" nnoremap <silent> <C-l> <C-w>l
|
|
|
|
|
" nnoremap <silent> <C-k> <C-w>k
|
|
|
|
|
" nnoremap <silent> <C-j> <C-w>j
|
2011-12-13 10:21:42 +08:00
|
|
|
|
|
2013-12-21 10:13:26 +08:00
|
|
|
|
" Make gf (go to file) create the file, if not existent
|
|
|
|
|
nnoremap <C-w>f :sp +e<cfile><CR>
|
|
|
|
|
nnoremap <C-w>gf :tabe<cfile><CR>
|
|
|
|
|
|
2014-06-25 00:38:24 +08:00
|
|
|
|
" Zoom in
|
2012-01-25 06:45:15 +08:00
|
|
|
|
map <silent> ,gz <C-w>o
|
2011-12-16 16:04:14 +08:00
|
|
|
|
|
2011-12-13 10:21:42 +08:00
|
|
|
|
" Create window splits easier. The default
|
|
|
|
|
" way is Ctrl-w,v and Ctrl-w,s. I remap
|
|
|
|
|
" this to vv and ss
|
|
|
|
|
nnoremap <silent> vv <C-w>v
|
|
|
|
|
nnoremap <silent> ss <C-w>s
|
|
|
|
|
|
|
|
|
|
" create <%= foo %> erb tags using Ctrl-k in edit mode
|
|
|
|
|
imap <silent> <C-K> <%= %><Esc>3hi
|
|
|
|
|
|
|
|
|
|
" create <%= foo %> erb tags using Ctrl-j in edit mode
|
|
|
|
|
imap <silent> <C-J> <% %><Esc>2hi
|
|
|
|
|
|
|
|
|
|
" ============================
|
|
|
|
|
" Shortcuts for everyday tasks
|
|
|
|
|
" ============================
|
|
|
|
|
|
|
|
|
|
" copy current filename into system clipboard - mnemonic: (c)urrent(f)ilename
|
|
|
|
|
" this is helpful to paste someone the path you're looking at
|
2012-04-06 01:03:40 +08:00
|
|
|
|
nnoremap <silent> ,cf :let @* = expand("%:~")<CR>
|
2016-06-07 14:29:39 +08:00
|
|
|
|
nnoremap <silent> ,cr :let @* = expand("%")<CR>
|
2012-04-15 07:40:50 +08:00
|
|
|
|
nnoremap <silent> ,cn :let @* = expand("%:t")<CR>
|
2011-12-13 10:21:42 +08:00
|
|
|
|
|
|
|
|
|
"Clear current search highlight by double tapping //
|
|
|
|
|
nmap <silent> // :nohlsearch<CR>
|
|
|
|
|
|
2012-04-26 10:39:31 +08:00
|
|
|
|
"(v)im (c)ommand - execute current line as a vim command
|
2012-03-09 08:46:45 +08:00
|
|
|
|
nmap <silent> ,vc yy:<C-f>p<C-c><CR>
|
2011-12-13 10:21:42 +08:00
|
|
|
|
|
2012-04-26 10:39:31 +08:00
|
|
|
|
"(v)im (r)eload
|
|
|
|
|
nmap <silent> ,vr :so %<CR>
|
|
|
|
|
|
2011-12-13 10:21:42 +08:00
|
|
|
|
" Type ,hl to toggle highlighting on/off, and show current value.
|
|
|
|
|
noremap ,hl :set hlsearch! hlsearch?<CR>
|
|
|
|
|
|
|
|
|
|
" These are very similar keys. Typing 'a will jump to the line in the current
|
|
|
|
|
" file marked with ma. However, `a will jump to the line and column marked
|
|
|
|
|
" with ma. It’s more useful in any case I can imagine, but it’s located way
|
|
|
|
|
" off in the corner of the keyboard. The best way to handle this is just to
|
|
|
|
|
" swap them: http://items.sjbach.com/319/configuring-vim-right
|
|
|
|
|
nnoremap ' `
|
|
|
|
|
nnoremap ` '
|
2011-12-16 01:25:10 +08:00
|
|
|
|
|
2011-12-21 15:48:33 +08:00
|
|
|
|
" ============================
|
2011-12-18 17:38:03 +08:00
|
|
|
|
" SplitJoin plugin
|
2011-12-21 15:48:33 +08:00
|
|
|
|
" ============================
|
2011-12-18 17:38:03 +08:00
|
|
|
|
nmap sj :SplitjoinSplit<cr>
|
|
|
|
|
nmap sk :SplitjoinJoin<cr>
|
2011-12-18 17:05:38 +08:00
|
|
|
|
|
2012-04-04 17:21:19 +08:00
|
|
|
|
" Get the current highlight group. Useful for then remapping the color
|
|
|
|
|
map ,hi :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">" . " FG:" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"fg#")<CR>
|
2012-05-15 21:43:49 +08:00
|
|
|
|
|
2012-09-12 01:19:04 +08:00
|
|
|
|
" ,hp = html preview
|
|
|
|
|
map <silent> ,hp :!open -a Safari %<CR><CR>
|
2015-09-09 02:10:26 +08:00
|
|
|
|
|
2017-03-10 17:14:30 +08:00
|
|
|
|
"paste text in insertion mode
|
|
|
|
|
inoremap <C-X><C-V> <esc>"+pa
|
|
|
|
|
"paste text in normal mode
|
|
|
|
|
nnoremap <C-X><C-V> "+p"
|
|
|
|
|
|
2017-08-01 23:56:20 +08:00
|
|
|
|
"------------------------------------------------------------------------------
|
|
|
|
|
" Misc
|
|
|
|
|
"------------------------------------------------------------------------------
|
|
|
|
|
" Toggle paste mode on and off
|
|
|
|
|
map <leader>pp :setlocal paste!<cr>
|
2017-03-10 17:14:30 +08:00
|
|
|
|
" copy all out of vim
|
|
|
|
|
nnoremap <C-X><C-A> <esc>gg"+yG
|
|
|
|
|
" copy text in visual mode
|
|
|
|
|
vnoremap <C-C> "+yy
|
|
|
|
|
" copy all inside vim
|
|
|
|
|
nnoremap <C-A> <esc>ggyG
|
|
|
|
|
" edit file
|
|
|
|
|
nmap <leader>ev :tabedit $MYVIMRC<cr>'tzo
|
|
|
|
|
nmap <leader>em :tabedit makefile
|
|
|
|
|
nmap <leader>ej :tabedit ~/.jshintrc<cr>'tzo
|
|
|
|
|
|
|
|
|
|
" move around compile errors
|
|
|
|
|
nnoremap <leader>n :cnext<cr>
|
|
|
|
|
nnoremap <leader>p :cprevious<cr>
|
2017-04-09 03:28:56 +08:00
|
|
|
|
|
|
|
|
|
nnoremap <leader>l :redraw!<cr>
|
2017-06-21 01:24:20 +08:00
|
|
|
|
imap <leader>cb 『』
|
2017-06-24 05:15:42 +08:00
|
|
|
|
nnoremap <leader>n :cn<cr>
|
|
|
|
|
nnoremap <leader>p :cp<cr>
|
2017-08-01 22:49:41 +08:00
|
|
|
|
|
|
|
|
|
" Fast Saving
|
|
|
|
|
map <Leader>w :w<CR>
|
|
|
|
|
imap <Leader>w <ESC>:w<CR>
|
|
|
|
|
vmap <Leader>w <ESC><ESC>:w<CR>
|
|
|
|
|
|
|
|
|
|
" :W sudo saves the file
|
|
|
|
|
" (useful for handling the permission-denied error)
|
2017-08-01 23:56:20 +08:00
|
|
|
|
if !exists(':W')
|
|
|
|
|
command W w !sudo tee % > /dev/null
|
|
|
|
|
endif
|
2017-08-01 22:49:41 +08:00
|
|
|
|
|
|
|
|
|
" Highlight current line - allows you to track cursor position more easily
|
|
|
|
|
set cursorline
|
|
|
|
|
|
|
|
|
|
" map CTRL-L to piece-wise copying of the line above the current one
|
|
|
|
|
imap <C-L> @@@<esc>hhkywjl?@@@<CR>P/@@@<cr>3s
|
|
|
|
|
|
2017-08-01 23:56:20 +08:00
|
|
|
|
|
2017-08-01 22:49:41 +08:00
|
|
|
|
" Allow to copy/paste between VIM instances
|
|
|
|
|
"copy the current visual selection to ~/.vbuf
|
|
|
|
|
vmap <leader>y :w! ~/.vbuf<cr>
|
|
|
|
|
|
|
|
|
|
"copy the current line to the buffer file if no visual selection
|
|
|
|
|
vmap <leader>y :.w! ~/.vbuf<cr>
|
|
|
|
|
|
|
|
|
|
"paste the contents of the buffer file
|
|
|
|
|
nmap <leader>p :r ~/.vbuf<cr>
|
|
|
|
|
|
2017-08-01 23:56:20 +08:00
|
|
|
|
"------------------------------------------------------------------------------
|
|
|
|
|
" Moving around, tabs, windows and buffers
|
|
|
|
|
"------------------------------------------------------------------------------
|
2017-08-01 22:49:41 +08:00
|
|
|
|
" Switch between the last two files
|
|
|
|
|
nnoremap <leader><leader> <C-^>
|
|
|
|
|
|
|
|
|
|
" easy way to edit reload .vimrc
|
|
|
|
|
nmap <leader>V :source $MYVIMRC<cr>
|
|
|
|
|
nmap <leader>v :vsp $MYVIMRC<cr>
|
2017-08-01 23:56:20 +08:00
|
|
|
|
|
|
|
|
|
" Quickly open a buffer for scribble
|
|
|
|
|
map <leader>q :e ~/buffer<cr>
|
|
|
|
|
|
|
|
|
|
" Quickly open a markdown buffer for scribble
|
|
|
|
|
map <leader>x :e ~/buffer.md<cr>
|
|
|
|
|
|
|
|
|
|
" Remove the Windows ^M - when the encodings gets messed up
|
|
|
|
|
noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
|
|
|
|
|
|
|
|
|
|
"------------------------------------------------------------------------------
|
|
|
|
|
" Spell checking
|
|
|
|
|
"------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
" Pressing ,ss will toggle and untoggle spell checking
|
|
|
|
|
map <leader>ss :setlocal spell!<cr>
|
|
|
|
|
|
|
|
|
|
" visual shifting (does not exit Visual mode)
|
|
|
|
|
vnoremap < <gv
|
|
|
|
|
vnoremap > >gv
|
|
|
|
|
|
|
|
|
|
" Switch CWD to the directory of the open buffer
|
|
|
|
|
map <leader>cd :cd %:p:h<cr>:pwd<cr>
|
|
|
|
|
|
|
|
|
|
" Treat long lines as break lines (useful when moving around in them)
|
|
|
|
|
map j gj
|
|
|
|
|
map k gk
|
|
|
|
|
|
|
|
|
|
" Close the current buffer (w/o closing the current window)
|
|
|
|
|
map <leader>bd :bd<cr>
|
|
|
|
|
|
|
|
|
|
" Close all the buffers
|
|
|
|
|
map <leader>bda :1,1000 bd!<cr>
|
|
|
|
|
|
|
|
|
|
" Useful mappings for managing tabs
|
|
|
|
|
map <leader>tn :tabnew<cr>
|
|
|
|
|
map <leader>to :tabonly<cr>
|
|
|
|
|
map <leader>tc :tabclose<cr>
|
|
|
|
|
map <leader>tm :tabmove
|
|
|
|
|
map <leader>tj :tabnext
|
|
|
|
|
map <leader>tk :tabprevious
|
|
|
|
|
|
|
|
|
|
" Let 'tl' toggle between this and the last accessed tab
|
|
|
|
|
let g:lasttab = 1
|
|
|
|
|
nmap <Leader>tl :exe "tabn ".g:lasttab<CR>
|
|
|
|
|
au TabLeave * let g:lasttab = tabpagenr()
|
|
|
|
|
|
|
|
|
|
"------------------------------------------------------------------------------
|
|
|
|
|
" Visual mode related
|
|
|
|
|
"------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
" Visual mode pressing * or # searches for the current selection
|
|
|
|
|
" Super useful! From an idea by Michael Naumann
|
|
|
|
|
vnoremap <silent> * :call VisualSelection('f', '')<CR>
|
|
|
|
|
vnoremap <silent> # :call VisualSelection('b', '')<CR>
|
2017-12-04 18:12:49 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
noremap <Up> :echo '戒黄赌毒及上下左右键!'<CR>
|
|
|
|
|
noremap <Down> :echo '戒黄赌毒及上下左右键!'<CR>
|
|
|
|
|
noremap <Left> :echo '戒黄赌毒及上下左右键!'<CR>
|
|
|
|
|
noremap <Right> :echo '戒黄赌毒及上下左右键!'<CR>
|
2017-12-15 07:30:32 +08:00
|
|
|
|
inoremap <leader>fn <C-R>=expand("%:t")<CR>
|