Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "=====================================================================
- " Vundle stuff
- "=====================================================================
- set nocompatible " be iMproved
- filetype off " required!
- set rtp+=~/.vim/bundle/vundle/
- set rtp+=/usr/local/go/misc/vim " install go stuff while we're at it
- call vundle#rc()
- " let Vundle manage Vundle
- " required!
- Bundle 'gmarik/vundle'
- " My Bundles here:
- "
- " original repos on github
- Bundle 'tpope/vim-fugitive'
- "Bundle 'https://github.com/wincent/Command-T.git'
- Bundle "kien/ctrlp.vim"
- Bundle 'taglist.vim'
- Bundle 'altercation/vim-colors-solarized'
- "Bundle 'godlygeek/tabular'
- Bundle "junegunn/vim-easy-align"
- " GitGutter shows a sign on the left to show what lines in a file have changed
- "Bundle "airblade/vim-gitgutter"
- Bundle 'scrooloose/nerdtree'
- " Magic completion for c like languages, python
- "Bundle "scrooloose/syntastic"
- "Bundle "Valloric/YouCompleteMe"
- " Snippets
- Bundle "SirVer/ultisnips"
- " Snippets for twitter bootstrap
- " Easymotion
- Bundle "Lokaltog/vim-easymotion"
- " Matchit (lets me match html tags with %)
- Bundle "matchit.zip"
- " Ack.vim for in editor searching the quickfix list
- Bundle "mileszs/ack.vim"
- " Same thing, but using 'ag' instead of 'ack'
- Bundle "rking/ag.vim"
- " Named bookmarks. Let's try this out.
- "Bundle "AndrewRadev/simple_bookmarks.vim"
- " Vim Start Screen (with recently opened files)
- Bundle "mhinz/vim-startify"
- Bundle "scrooloose/nerdcommenter"
- " Automatically change working dir to match project (where the .git folder is
- " found)
- Bundle "airblade/vim-rooter"
- " Local vimrc
- Bundle "embear/vim-localvimrc"
- " Python text objects
- Bundle "michaeljsmith/vim-indent-object"
- " Surround, repeat
- Bundle "tpope/vim-surround"
- Bundle "tpope/vim-repeat"
- " Airline -- lightweight statusbar line
- Bundle "bling/vim-airline"
- Bundle "JavaScript-Indent"
- " Lets you split or join things -- <div>a</div> onto 3 lines, for example
- Bundle "AndrewRadev/splitjoin.vim"
- " ...
- " Once you add your source above, do reload vim and do :BundleInstall
- filetype plugin indent on " required!
- " =====================================================================
- " Personal preferences
- " =====================================================================
- " Change leader to be ,
- let mapleader = ","
- " Startify settings
- let g:startify_bookmarks = [
- \ '~/.vimrc',
- \ '~/dev/config',
- \ ] " Always show this in Startify
- let g:startify_skiplist = [
- \ 'COMMIT_EDITMSG',
- \ $VIMRUNTIME .'/doc',
- \ 'bundle/.*/doc'
- \ ]
- nnoremap <leader>s :Startify<CR>
- let g:startify_files_number = 20
- let g:startify_custom_header = map(split(system('fortune | cowsay'), '\n'), '" ". v:val') + ['','']
- "let g:UltiSnipsSnippetsDir="~/.vim/mysnippets"
- let g:UltiSnipsExpandTrigger="<c-j>"
- let g:UltiSnipsJumpForwardTrigger="<c-j>"
- let g:UltiSnipsJumpBackwardTrigger="<c-k>"
- let g:UltiSnipsListSnippets="<c-l>"
- let g:UltiSnipsEditSplit="vertical"
- nnoremap <C-e> :UltiSnipsEdit<CR>
- let g:gitgutter_enabled = 1
- let g:rooter_patterns = ['Rakefile', '.git/', 'buildenv.mk']
- " Add bufferlist to top (unless tabs are open)
- let g:airline#extensions#tabline#enabled = 1
- " Make it just show the filename, not the full path
- let g:airline#extensions#tabline#fnamemod = ':t'
- let NERDTreeIgnore = ['\.pyc$', '\.class$']
- set cursorline
- set ttymouse=xterm2
- if has("gui_running")
- set mouse=a
- else
- set mouse=
- endif
- set ff=unix
- set ignorecase
- set smartcase
- " fix slight delay after pressing ESC then O
- " http://ksjoberg.com/vim-esckeys.html
- " set noesckeys
- set timeout timeoutlen=1000 ttimeoutlen=100
- " So, after building from source, my backspace got messed up. Perhaps
- " the debian repo changes the default behavior here? Weird. This fixes:
- set backspace=indent,eol,start
- "colorscheme torte
- syntax enable
- set background=dark
- colorscheme solarized
- let g:solarized_termcolors=256
- syntax on
- set guioptions-=m
- " Don't litter my darn folders!:
- set nobackup
- set nowritebackup
- set noswapfile
- " Indentation prefs:
- set tabstop=4
- set shiftwidth=4
- set expandtab
- " Other:
- set hlsearch
- set incsearch
- set number
- set relativenumber
- set showcmd " when visually selecting N lines, you'll see that number in the lower right
- " This beauty remembers where you were the last time you edited the file, and returns to the same position:
- au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif
- " Make F2 map to toggle numbers:
- nnoremap <F2> :set nonumber!<CR>
- :set guioptions-=T "remove toolbar
- "set autochdir " current dir given by file
- " Make 'Y' yank to the end of the line:
- nnoremap Y y$
- " <C-y> will now do an OS level copy:
- map <C-y> "+y
- " ... and <C-p> will paste it
- nnoremap <C-p> "+p
- set undofile
- set undodir=~/.vim/undodir
- " Make jj and jk (in insert mode) equal escape
- imap jj <Esc>
- imap jk <Esc>
- " n always searches forward (even after a ? search)
- noremap <silent> n /<CR>
- " N always searches backward (even after a / search)
- noremap <silent> N ?<CR>
- " Exhuberant ctags install is here:
- let Tlist_Ctags_Cmd = '/usr/bin/ctags'
- let Tlist_Show_One_File = 1 " Just show the current buffer
- let Tlist_Use_Right_Window = 1
- let Tlist_WinWidth = 40
- set ut=1000 " Update every 1 second (works for taglist)
- " Looks for tags file 1) where it us, else 2) up a folder (until root)
- set tags=tags;/
- " Omni completion brings up a menu for even just 1 item
- set completeopt=menuone
- set nocrb " Cursorbind is an evil, evil thing
- " If I move my cursor to the bottom 5 lines on screen, scroll down to keep
- " some context
- "set scrolloff=5
- " C-n toggles numbers on and off
- map <C-n> :set rnu! number!<CR>
- set wildignore=*.o,*.obj,*.pyc,*.class,*.mod.c,*.cmd,*.ko
- let g:netrw_list_hide= '.*\.swp$,.*\.pyc,.*\.o,.*\.obj,.*\.class,.*\.mod\.c,.*\.cmd,.*\.ko'
- " =====================================================================
- " Filetype specific stuff
- " =====================================================================
- filetype on
- filetype plugin on
- filetype plugin indent on
- " Use less.vim to syntax highlight less css files:
- au BufNewFile,BufRead *.less set filetype=less
- au BufNewFile,BufRead *.in set noexpandtab " Don't expand in .in files (buildroot configuration files)
- "autocmd FileType c setlocal autoindent
- "autocmd FileType c setlocal cindent
- "autocmd FileType cpp setlocal autoindent
- "autocmd FileType cpp setlocal cindent
- "autocmd FileType php setlocal autoindent
- "autocmd FileType php setlocal cindent
- "set cindent -- this is screwing up trying to put # in normal files
- set autoindent
- "autocmd FileType make setlocal noexpandtab "Turns tabs off for makefiles
- " Python:
- " Python files will indent #comments:
- autocmd BufRead *.py inoremap # X<c-h>#
- " Autoload python crazy script
- "if !exists("autocommands_loaded")
- " let autocommands_loaded = 1
- " autocmd BufRead,BufNewFile,FileReadPost *.py source ~/.vim/python
- "endif
- " CTRL-Tab is next tab
- noremap <C-Tab> :tabnext<CR>
- inoremap <C-Tab> <ESC>:tabnext<CR>
- cnoremap <C-Tab> :tabnext<CR>
- onoremap <C-Tab> :tabnext<CR>
- " CTRL-Shift-Tab is previous tab
- noremap <C-S-Tab> :tabprev<CR>
- inoremap <C-S-Tab> <ESC>:tabprev<CR>
- cnoremap <C-S-Tab> :tabprev<CR>
- onoremap <C-S-Tab> :tabprev<CR>
- " Make <C-f> go to item in the quickfix list, <C-b> go to the previous item
- noremap <C-b> :cp<CR>
- noremap <C-f> :cn<CR>
- " Make it easy to get move to the far left and right windows:
- nnoremap L <C-w>5l
- nnoremap H <C-w>5h
- nnoremap <C-l> <C-w>l
- nnoremap <C-h> <C-w>h
- nnoremap <C-j> <C-w>j
- nnoremap <C-k> <C-w>k
- " Abbreviations
- function! EatChar(pat)
- let c = nr2char(getchar(0))
- return (c =~ a:pat) ? '' : c
- endfunction
- function! MakeSpacelessIabbrev(from, to)
- execute "iabbrev <silent> ".a:from." ".a:to."<C-R>=EatChar('\\s')<CR>"
- endfunction
- call MakeSpacelessIabbrev('CC_', 'CC_EXE_PATH=/opt/armgcc/bin')
- "ga* does a grep and puts results in the quickfix window
- " The sequence of evil hackery:
- " 1) Mark location globally with ("mZ")
- " 2) Clear the quickfix list (":call setqflist([])<CR>")
- " 3) Set hightlighting by making this local search too, but staying put ("*N")
- " 4) Run :Ag command
- " (":Ag --literal --word-regexp <cword> <CR>")
- " 5) Hit the first result to reset focus to main window ("<CR>")
- " 6) Go to wherever we were before this whole mess ('Z)
- " 7) Reset focus to quickfix window
- nnoremap <silent> g* mZ:call setqflist([])<CR>*N:Ag --literal --word-regexp <cword> <CR><CR>'Z:copen<CR>
- nnoremap <silent> ga* mZ:call setqflist([])<CR>*N:Ag --literal --word-regexp <cword> <CR><CR>'Z:copen<CR>
- nnoremap <silent> gah mZ:call setqflist([])<CR>*N:Ag -G "h$" --literal --word-regexp <cword> <CR><CR>'Z:copen<CR>
- "gf now uses AckFile to do results (none that start with a period)
- nnoremap <silent> gf :call setqflist([])<CR>:AckFile "^[^.].*<cfile>"<CR>
- "
- " <C-space> now gets rid of highlighting and then does the redraw
- nnoremap <silent> <C-space> :noh<CR><C-k>
- " above works in gui, this works in terminal. no idea why.
- nnoremap <silent> <C-@> :noh<CR><C-k>
- nnoremap <silent> <Leader>f :NERDTreeFind<CR>zz
- let g:CommandTMaxHeight=20
- let g:CommandTMaxFiles=80000
- let g:CommandTMaxCachedDirectories=10
- let g:CommandTNeverShowDotFiles=1
- nnoremap <silent> <Leader>t :CtrlP<CR>
- let g:ctrlp_max_files = 100000
- " Ack motions ------------------------------------------------------------- {{{
- " Motions to Ack for things. Works with pretty much everything, including:
- " "
- " " w, W, e, E, b, B, t*, f*, i*, a*, and custom text objects
- " "
- " " Awesome.
- " "
- " " Note: If the text covered by a motion contains a newline it won't work.
- " Ack
- " " searches line-by-line.
- nnoremap <silent> \a :set opfunc=<SID>AckMotion<CR>g@
- xnoremap <silent> \a :<C-U>call <SID>AckMotion(visualmode())<CR>
- function! s:CopyMotionForType(type)
- if a:type ==# 'v'
- silent execute "normal! `<" . a:type . "`>y"
- elseif a:type ==# 'char'
- silent execute "normal! `[v`]y"
- endif
- endfunction
- function! s:AckMotion(type) abort
- let reg_save = @@
- call s:CopyMotionForType(a:type)
- execute "normal! :Ack! --literal " . shellescape(@@) . "\<cr>"
- let @@ = reg_save
- endfunction
- " }}}
- " =====================================================================
- " Tabularize
- " =====================================================================
- "nmap <Leader>a= :Tabularize /=<CR>
- "vmap <Leader>a= :Tabularize /=<CR>
- "nmap <Leader>a: :Tabularize /:<CR>
- "vmap <Leader>a: :Tabularize /:<CR>
- "nmap <Leader>aa :Tabularize /\S\+$<CR>
- "vmap <Leader>aa :Tabularize /\S\+$<CR>
- "
- ""nmap <Leader>a: :Tabularize /:\zs<CR>
- ""vmap <Leader>a: :Tabularize /:\zs<CR>
- "
- "" This means that inserting a | will automatically Tabularize. Cool!
- "" https://gist.github.com/287147
- "inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a
- "
- "function! s:align()
- " let p = '^\s*|\s.*\s|\s*$'
- " if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
- " let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
- " let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
- " Tabularize/|/l1
- " normal! 0
- " call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
- " endif
- "endfunction
- "
- " =====================================================================
- " Easy Align
- " =====================================================================
- " Start interactive EasyAlign in visual mode (e.g. vip<Enter>)
- vmap <Enter> <Plug>(EasyAlign)
- " Start interactive EasyAlign for a motion/text object (e.g. <Leader>aip)
- nmap <Leader>a <Plug>(EasyAlign)
- "Fugitive stuff
- let g:fugitive_summary_format = '%s ---- (%an, %aE, %ad, %ar)'
- "Automatically clear fugitive buffers back out - see http://vimcasts.org/episodes/fugitive-vim-browsing-the-git-object-database/
- autocmd BufReadPost fugitive://* set bufhidden=delete
- " Hint from: http://vimcasts.org/episodes/fugitive-vim-browsing-the-git-object-database/
- " Give myself parent directories '..' when browsing tree
- autocmd User fugitive
- \ if fugitive#buffer().type() =~# '^\%(tree\|blob\)$' |
- \ nnoremap <buffer> .. :edit %:h<CR> |
- \ endif
- nnoremap <silent> <c-g> :Gstatus<CR>
- nnoremap <silent> <leader>d :Gdiff<CR>
- nnoremap <silent> gd :diffoff<CR>
- " Status line stuff:
- set statusline=
- set statusline +=%1*\ %<%f%* "relative path
- set statusline +=%1*%r%* "read only flag
- set statusline +=%1*%m%* "modified flag
- set statusline +=%1*\ \ \ \ "a few spaces
- set statusline+=%3*%{fugitive#statusline()} " fugitive git workspace
- set statusline +=%2*%=%5l%* "current line
- set statusline +=%2*/%L%* "total lines
- set statusline +=%2*%4v\ %* "virtual column number
- set statusline +=%2*0x%04B\ %* "character under cursor
- " Colors for statusline
- hi User1 guifg=White guibg=DarkBlue ctermfg=White ctermbg=DarkBlue
- hi User2 guifg=LightGray guibg=DarkBlue ctermfg=LightGray ctermbg=DarkBlue
- hi User3 guifg=Red guibg=DarkBlue ctermfg=Red ctermbg=DarkBlue
- hi User5 guifg=White guibg=DarkBlue ctermfg=White ctermbg=DarkBlue
- set laststatus=2 " Always show status line
- " Use ranger as vim file manager
- function! Ranger()
- " Get a temp file name without creating it
- let tmpfile = substitute(system('mktemp -u'), '\n', '', '')
- " Launch ranger, passing it the temp file name
- silent exec '!RANGER_RETURN_FILE='.tmpfile.' ranger'
- " If the temp file has been written by ranger
- if filereadable(tmpfile)
- " Get the selected file name from the temp file
- let filetoedit = system('cat '.tmpfile)
- exec 'edit '.filetoedit
- call delete(tmpfile)
- endif
- redraw!
- endfunction
- nmap <leader>r :call Ranger()<cr>
- let g:EasyMotion_leader_key = '<Space>'
- function! SaveIfValidBuffer()
- let bufname = expand('%:p')
- if bufname != ""
- write
- endif
- endfunction
- " Use <Enter> to save the file... If it's valid (ignore quickfix, etc). Add a
- " second <CR> at the end to keep the normal behavior
- "nnoremap <CR> :call SaveIfValidBuffer()<CR><CR>
- "cabbrev w nope
- " =====================================================================
- " Git Gutter stuff
- " =====================================================================
- highlight clear SignColumn " without this the column colorscheme looks funny
- nnoremap <leader>p :GitGutterPrevHunk<CR>
- nnoremap <leader>n :GitGutterNextHunk<CR>
- " Local vimrc - don't ask, just take .lvimrc changes
- let g:localvimrc_ask=0
- let g:localvimrc_sandbox=0
- " Python import:
- " This is a kinda clumsy way to guess at how to import a given thingy
- " Basically, hover over a word and try to figure out what the appropriate
- " import statement is to add -- grep through the project for import
- " statements and sort then by frequency, and then take the most frequent one
- " (You'll have to double check it -- don't worry, your cursor will go to the
- " import line. Two ticks ('') will take you back.)
- function! ImportComplete()
- let word = expand("<cword>")
- let output = system('git grep -h "^from.*' . word . '" | sort | uniq -c | sort -rn | head -n1 | sed "s/^ *[0-9]* *//"')
- execute "normal! G?^from\<cr>"
- call append(line('.'), output)
- " Delete the garbage newline thingy at the end of that line
- normal j$x0
- endfunction
- nnoremap <leader>i :call ImportComplete()<CR>
- " http://vimcasts.org/episodes/tidying-whitespace/
- function! Preserve(command)
- " Preparation: save last search, and cursor position.
- let _s=@/
- let l = line(".")
- let c = col(".")
- " Do the business:
- execute a:command
- " Clean up: restore previous search history, and cursor position
- let @/=_s
- call cursor(l, c)
- endfunction
- " Delete all trailing whitespace
- nmap _$ :call Preserve("%s/\\s\\+$//e")<CR>
- " Format the whole document:
- nmap _= :call Preserve("normal gg=G")<CR>
- " Delete debug printfs (c)
- nmap _d :call Preserve("%s/^\\s*dbg_printf(\"%s:%d reached.n\", __FUNCTION__, __LINE__);\\s*$\\n//e")<CR>
- nmap gj :SplitjoinSplit<cr>
- nmap gk :SplitjoinJoin<cr>
- " =====================================================================
- " ========================== PERFORCE =================================
- " =====================================================================
- function! ShowHL()
- echohl Conceal | echo "Conceal Test characters."
- echohl Cursor | echo "Cursor Test characters."
- echohl CursorIM | echo "CursorIM Test characters."
- echohl CursorColumn | echo "CursorColumn Test characters."
- echohl CursorLine | echo "CursorLine Test characters."
- echohl Directory | echo "Directory Test characters."
- echohl DiffAdd | echo "DiffAdd Test characters."
- echohl DiffChange | echo "DiffChange Test characters."
- echohl DiffDelete | echo "DiffDelete Test characters."
- echohl DiffText | echo "DiffText Test characters."
- echohl ErrorMsg | echo "ErrorMsg Test characters."
- echohl VertSplit | echo "VertSplit Test characters."
- echohl Folded | echo "Folded Test characters."
- echohl FoldColumn | echo "FoldColumn Test characters."
- echohl SignColumn | echo "SignColumn Test characters."
- echohl IncSearch | echo "IncSearch Test characters."
- echohl LineNr | echo "LineNr Test characters."
- echohl MatchParen | echo "MatchParen Test characters."
- echohl ModeMsg | echo "ModeMsg Test characters."
- echohl MoreMsg | echo "MoreMsg Test characters."
- echohl NonText | echo "NonText Test characters."
- echohl Normal | echo "Normal Test characters."
- echohl Pmenu | echo "Pmenu Test characters."
- echohl PmenuSel | echo "PmenuSel Test characters."
- echohl PmenuSbar | echo "PmenuSbar Test characters."
- echohl PmenuThumb | echo "PmenuThumb Test characters."
- echohl Question | echo "Question Test characters."
- echohl Search | echo "Search Test characters."
- echohl SpecialKey | echo "SpecialKey Test characters."
- echohl SpellBad | echo "SpellBad Test characters."
- echohl SpellCap | echo "SpellCap Test characters."
- echohl SpellLocal | echo "SpellLocal Test characters."
- echohl SpellRare | echo "SpellRare Test characters."
- echohl StatusLine | echo "StatusLine Test characters."
- echohl StatusLineNC | echo "StatusLineNC Test characters."
- echohl TabLine | echo "TabLine Test characters."
- echohl TabLineFill | echo "TabLineFill Test characters."
- echohl TabLineSel | echo "TabLineSel Test characters."
- echohl Title | echo "Title Test characters."
- echohl Visual | echo "Visual Test characters."
- echohl VisualNOS | echo "VisualNOS Test characters."
- echohl WarningMsg | echo "WarningMsg Test characters."
- echohl WildMenu | echo "WildMenu Test characters."
- echohl None
- endfunction
- " Perforce commands:
- function! P4FormatOutput(output)
- let lines = split(a:output,'\n')
- for line in lines
- let line = " " . line
- " Green stuff:
- if line =~ ' - updating'
- echohl Question | echo line | echohl None
- elseif line =~ ' - added'
- echohl Question | echo line | echohl None
- elseif line =~ ' - opened for edit'
- echohl Question | echo line | echohl None
- elseif line =~ ' - currently opened for edit'
- echohl Question | echo line | echohl None
- elseif line =~ '- was edit, reverted'
- echohl Question | echo line | echohl None
- elseif line =~ '- deleted as'
- echohl Question | echo line | echohl None
- " Default gray
- elseif line =~ ' - edit default change'
- echohl None | echo line
- elseif line =~ ' - add default change'
- echohl None | echo line
- elseif line =~ 'File(s) up-to-date.'
- echohl None | echo line
- " Red
- elseif line =~ 'file(s) not in client view.'
- echohl WarningMsg | echo line | echohl None
- elseif line =~ '- file(s) not opened on this client.'
- echohl WarningMsg | echo line | echohl None
- " Underlined red
- elseif line =~ ' - also opened by'
- echohl SpellBad | echo line | echohl None
- " Default case
- else
- echohl WarningMsg | echo line | echohl None
- endif
- endfor
- " Add a few blank lines at the end
- echo ""
- echo ""
- endfunction
- function! P4Func(arg)
- let refresh_qfix = 1
- if $P4CLIENT == ""
- echohl ErrorMsg | echo "P4CLIENT isn't set!" | echohl None
- return
- endif
- "echo a:arg
- "echo expand('%:p')
- if a:arg == 'sync'
- let myCommand = 'p4 sync'
- elseif a:arg == 'opened'
- call OpenPerf()
- return
- elseif a:arg == 'revert'
- " I've accidentally reverted a lot of work. I'm not going to do that
- " again. Reverts now make a copy of the file and put it in ~/tmp/vimbu
- let output = system('mkdir -p ~/.vimbu')
- let output = system('cp ' . expand('%:p') . ' ~/.vimbu/')
- let myCommand = 'p4 ' . a:arg . ' ' . expand('%:p')
- elseif a:arg == 'diff'
- let output = system('mkdir -p ~/tmp/p4') " temp folder for files to diff against
- let myCommand = 'p4 print -o ~/tmp/p4/_ ' . expand('%:p') " Grab a perforce copy of the file
- else
- let myCommand = 'p4 ' . a:arg . ' ' . expand('%:p')
- endif
- " run command
- let output = system(myCommand)
- " Do we need to reload the current file? (and update NERDTree)
- if a:arg == 'edit' || a:arg == 'revert'
- " Refresh NERDTree
- silent NERDTreeFind
- "sleep 3 " When above command hits disk we open the wrong file. It appears that the above command is non blocking?
- silent normal ro
- " Force reload of file
- silent :e!
- " mark wherever I am into Z
- "silent normal mZ
- "silent NERDTreeFind
- " Refresh the tree, reopen my file
- "silent normal Ro
- " Sometimes, on the above refresh, our tree shifts and we opened the
- " wrong file. Let's ensure that we go back where we were:
- "silent normal 'Z
- elseif a:arg == 'diff'
- if output =~ '^//'
- " Successful checkouts will start with the remote path name,
- " beginning with '//'
- let diff_file = split( output )[0]
- let diff_file = system( 'basename ' . diff_file )
- " Tweak the string name.
- " Example was: wifi_debug_serial.c#12
- " becomes: wifi_debug_serial__12.c
- " By ending with the right filetype, we preserve pretty syntax
- " highlighting, etc
- let diff_file = '~/tmp/p4/' . system( 'echo "' . diff_file . '" | sed "s/\.\(.*\)#\(.*\)/__\2.\1/" ')
- let _ = system( 'rm -f ' . diff_file ) " Kill read only old version if it exists
- let _ = system( 'cp ~/tmp/p4/_ ' . diff_file )
- else
- let diff_file = '/dev/null'
- endif
- diffthis " original
- vsplit
- execute 'edit ' . diff_file
- diffthis " diff_file
- cclose " let the diff line up nicely
- let refresh_qfix = 0
- wincmd l " put focus on the important window
- endif
- if refresh_qfix
- " Open (and refresh) Perforce version quickfix
- " Then move focus back up
- call OpenPerf()
- wincmd k
- redraw
- endif
- echo '$ ' . myCommand
- call P4FormatOutput(output)
- endfunction
- function! OpenPerf()
- if $P4CLIENT == ""
- echohl ErrorMsg | echo "P4CLIENT isn't set!" | echohl None
- return
- endif
- let myCommand = 'p4 opened'
- " run command
- let output = system(myCommand)
- let lines = split(output,'\n')
- let qflist = [ { 'text' : 'Perforce checked out files:'} ]
- for line in lines
- "Each line looks like this:
- " //unity/...pipr.c#3 - edit default change (text)
- let parts = split(line, '#')
- if(len(parts) > 1)
- let text = parts[1]
- " p4 where <unity path> gives output like this:
- "//unity/...../pipr.c //ballen_unity_sandstone/.../pipr.c /Users/ballen/dev/ballen_unity_sandstone/common/devices/pipr/src/pipr.c
- let filename = split(system('p4 where ' . parts[0]), ' ')[2]
- let filename = substitute(filename, '\n', '', '') " remove newline
- " In cases of a full path, remove as much as we can
- let mydir = getcwd() . '/'
- if filename =~ "^" . mydir
- let filename = substitute(filename, mydir, '', '') " remove newline
- endif
- let dic = {'filename' : filename, 'text' : text}
- call add(qflist, dic)
- endif
- endfor
- call setqflist(qflist)
- copen " Set the focus there
- return
- endfunction
- :map <silent> <Space>p :call OpenPerf()<CR>
- command! -nargs=1 Perf call P4Func(<f-args>)
- set clipboard=unnamed
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement