Skip to content

Instantly share code, notes, and snippets.

@erikcorry
Created April 1, 2019 07:55
Show Gist options
  • Save erikcorry/24e3a51f8a712429e9e3e23e9e8c6b11 to your computer and use it in GitHub Desktop.
Save erikcorry/24e3a51f8a712429e9e3e23e9e8c6b11 to your computer and use it in GitHub Desktop.
" Looks at the character to the left, and does a shell-style autocomplete
" (ctrl-P) if we are in the middle of a word. If there is white-space
" or beginning-of-line, it does two spaces to indent.
function! CleverTab()
if strpart( getline('.'), col('.')-2, 1) =~ '^\s*$'
return " "
else
return "\<C-P>"
endfunction
inoremap <Tab> <C-R>=CleverTab()<CR>
" Does a git grep of whatever you are currently searching for. Requires
" fugitive.vim
" Bugs:
" Always does a case dependent search, even if vim is ignorecase mode.
" Doesn't understand searches with spaces in them (usually you can just
" replace spaces with dots in the Vim search).
" Doesn't understand most metacharacters that also mean something to the
" shell.
" Understands \<word\> and converts to a grep -w, but doesn't understand
" asymmetric word delimiters like \<word or word\>
"let g:defaultgrep = "Svngrep"
let g:defaultgrep = "Gitgrep"
function! GgrepFromSearch()
let searchterm = @/
echo searchterm
let stripped = matchlist(searchterm, '^\\<\(.*\)\\>$')
if (len(stripped) != 0)
execute g:defaultgrep . " -w " . stripped[1]
else
execute g:defaultgrep . " " . searchterm
endif
endfunction
function! SwitchToGitGrep()
let g:defaultgrep = "Gitgrep"
endfunction
function! SwitchToSvnGrep()
let g:defaultgrep = "Svngrep"
endfunction
function! ErikHelp()
echo "HC - see last 30 commits for current file"
echo "HV - see last 30 versions of this file"
echo "HU - see the HEAD (unedited) version of the current file"
echo "HM - see the origin/master version of the current file"
echo "HB - see blame for the current file"
echo "HA - git grep current search term (in new vsplit)"
echo "Ha - git grep current search term"
echo "HO - next error/search result"
echo "HE - previous error/search result"
echo "HF - see current function"
echo "HD - see current diff file"
echo "HS - switch searcher to Svn mode (default)"
echo "HG - switch searcher to Git mode"
endfunction
map H :call ErikHelp()<CR>
map HH :call ErikHelp()<CR>
map HC :vspl<CR><C-W>l:Glog -30 -- %<CR>
map Hc :vspl<CR><C-W>l:Glog -30 -- %<CR>
map HU :vspl<CR><C-W>l:Gedit HEAD:%<CR>
map Hu :vspl<CR><C-W>l:Gedit HEAD:%<CR>
map HM :vspl<CR><C-W>l:Gedit origin/master:%<CR>
map Hm :vspl<CR><C-W>l:Gedit origin/master:%<CR>
map HV :vspl<CR><C-W>l:Glog -30<CR>
map Hv :vspl<CR><C-W>l:Glog -30<CR>
map HB :Gblame<CR>
map Hb :Gblame<CR>
map HG :call SwitchToGitGrep()<CR>
map Hg :call SwitchToGitGrep()<CR>
map HS :call SwitchToSvnGrep()<CR>
map Hs :call SwitchToSvnGrep()<CR>
" If there's a vertical split, this opens the search in the right side.
" If there is no vertical split, just does the search in the current window.
" If you accidentally do the search in the current window, use :b# to go back.
map å <C-W>l:call GgrepFromSearch()<CR>
map Ha <C-W>l:call GgrepFromSearch()<CR>
" Creates a vertical split and does the search in the right hand one.
map Å :vspl<CR><C-W>l:call GgrepFromSearch()<CR>
map HA :vspl<CR><C-W>l:call GgrepFromSearch()<CR>
map Ho :cnext<CR>
map HO :cnext<CR>
map He :cprevious<CR>
map HE :cprevious<CR>
" For moving back and forth through the Ggrep result.
map æ :cprevious<CR>
map ø :cnext<CR>
set shell=bash
set tabstop=4
set shiftwidth=2
set smartindent
set expandtab
set showmatch
set hlsearch
highlight Search ctermfg=black
highlight Search ctermbg=white
highlight MyExtraWhitespace ctermbg=red guibg=red
highlight MyControlFlow ctermfg=red guifg=red
"2match MyExtraWhitespace /\s\+$/
"2match MyControlFlow /\<break\>\|\<continue\>\|\<goto\>\|......\<return\>/
" enable all vim's cool features
set nocompatible
" flash back to matching bracket, but only for 100ms
set showmatch
set matchtime=1
set ignorecase
set winminheight=0
" Insert-mode mappings for characters that are hard to type on a non-US
" keyboard.
map! qq @
map! QQ $
map! hh {
map! jj }
map! HH [
map! JJ ]
map! uu \
map! UU \|
map! vv ~
map! VV ^
" Better than reaching for the escape key
map! jk <Esc>
" Make $ more accessible on strange keyboards.
map ¤ $
map! ¤ $
" Previous and next split.
" Up one window.
map W <C-W>k
" Down one window.
map E <C-W>j
" Map shift-arrow to navigate between windows.
map <S-Up> <C-W>k
map <S-Down> <C-W>j
map <S-Right> <C-W>l
map <S-Left> <C-W>h
" Make split vertically larger
map Q 10<C-W>+
" Close window.
map T :q
syntax on
execute pathogen#infect()
if has('vim_starting')
set runtimepath+=~/.vim/bundle/dart-vim-plugin
endif
filetype plugin indent on
" Searches up for a line that starts with an identifier and has no
" indentation.
fun! ShowCodeBlockName()
set ls=2
let lnum = line(".")
let col = col(".")
echohl ModeMsg
echo getline(search("^[a-zA-Z_].*$", 'b'))
echohl None
call search("\\%" . lnum . "l" . "\\%" . col . "c")
endfun
map HF :call ShowCodeBlockName() <CR>
" Searches up for a line that starts with diff (unified diff format filename).
fun! ShowDiffFileName()
set ls=2
let lnum = line(".")
let col = col(".")
echohl ModeMsg
echo getline(search("^diff", 'b'))
echohl None
call search("\\%" . lnum . "l" . "\\%" . col . "c")
endfun
map HD :call ShowDiffFileName() <CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment