More updates

20 months ago

author
Armin Ronacher <armin.ronacher@active-4.com>
date
Tue Sep 21 03:57:32 2010 +0200
changeset 13
fa6db39c3e5c
parent 12
e5e30b06250c
child 14
18d18822a7a0

More updates

plugin/scratch.vimfile | annotate | diff | revisions
vimrcfile | annotate | diff | revisions
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/plugin/scratch.vim	Tue Sep 21 03:57:32 2010 +0200
     1.3 @@ -0,0 +1,110 @@
     1.4 +" File: scratch.vim
     1.5 +" Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
     1.6 +" Version: 1.0
     1.7 +" Last Modified: June 3, 2003
     1.8 +"
     1.9 +" Overview
    1.10 +" --------
    1.11 +" You can use the scratch plugin to create a temporary scratch buffer to store
    1.12 +" and edit text that will be discarded when you quit/exit vim. The contents
    1.13 +" of the scratch buffer are not saved/stored in a file.
    1.14 +"
    1.15 +" Installation
    1.16 +" ------------
    1.17 +" 1. Copy the scratch.vim plugin to the $HOME/.vim/plugin directory. Refer to
    1.18 +"    the following Vim help topics for more information about Vim plugins:
    1.19 +"
    1.20 +"       :help add-plugin
    1.21 +"       :help add-global-plugin
    1.22 +"       :help runtimepath
    1.23 +"
    1.24 +" 2. Restart Vim.
    1.25 +"
    1.26 +" Usage
    1.27 +" -----
    1.28 +" You can use the following command to open/edit the scratch buffer:
    1.29 +"
    1.30 +"       :Scratch
    1.31 +"
    1.32 +" To open the scratch buffer in a new split window, use the following command:
    1.33 +"
    1.34 +"       :Sscratch
    1.35 +"
    1.36 +" When you close the scratch buffer window, the buffer will retain the
    1.37 +" contents. You can again edit the scratch buffer by openeing it using one of
    1.38 +" the above commands. There is no need to save the scatch buffer.
    1.39 +"
    1.40 +" When you quit/exit Vim, the contents of the scratch buffer will be lost.
    1.41 +" You will not be prompted to save the contents of the modified scratch
    1.42 +" buffer.
    1.43 +"
    1.44 +" You can have only one scratch buffer open in a single Vim instance. If the
    1.45 +" current buffer has unsaved modifications, then the scratch buffer will be
    1.46 +" opened in a new window
    1.47 +"
    1.48 +" ****************** Do not modify after this line ************************
    1.49 +if exists('loaded_scratch') || &cp
    1.50 +    finish
    1.51 +endif
    1.52 +let loaded_scratch=1
    1.53 +
    1.54 +" Scratch buffer name
    1.55 +let ScratchBufferName = "__Scratch__"
    1.56 +
    1.57 +" ScratchBufferOpen
    1.58 +" Open the scratch buffer
    1.59 +function! s:ScratchBufferOpen(new_win)
    1.60 +    let split_win = a:new_win
    1.61 +
    1.62 +    " If the current buffer is modified then open the scratch buffer in a new
    1.63 +    " window
    1.64 +    if !split_win && &modified
    1.65 +        let split_win = 1
    1.66 +    endif
    1.67 +
    1.68 +    " Check whether the scratch buffer is already created
    1.69 +    let scr_bufnum = bufnr(g:ScratchBufferName)
    1.70 +    if scr_bufnum == -1
    1.71 +        " open a new scratch buffer
    1.72 +        if split_win
    1.73 +            exe "new " . g:ScratchBufferName
    1.74 +        else
    1.75 +            exe "edit " . g:ScratchBufferName
    1.76 +        endif
    1.77 +    else
    1.78 +        " Scratch buffer is already created. Check whether it is open
    1.79 +        " in one of the windows
    1.80 +        let scr_winnum = bufwinnr(scr_bufnum)
    1.81 +        if scr_winnum != -1
    1.82 +            " Jump to the window which has the scratch buffer if we are not
    1.83 +            " already in that window
    1.84 +            if winnr() != scr_winnum
    1.85 +                exe scr_winnum . "wincmd w"
    1.86 +            endif
    1.87 +        else
    1.88 +            " Create a new scratch buffer
    1.89 +            if split_win
    1.90 +                exe "split +buffer" . scr_bufnum
    1.91 +            else
    1.92 +                exe "buffer " . scr_bufnum
    1.93 +            endif
    1.94 +        endif
    1.95 +    endif
    1.96 +endfunction
    1.97 +
    1.98 +" ScratchMarkBuffer
    1.99 +" Mark a buffer as scratch
   1.100 +function! s:ScratchMarkBuffer()
   1.101 +    setlocal buftype=nofile
   1.102 +    setlocal bufhidden=hide
   1.103 +    setlocal noswapfile
   1.104 +    setlocal buflisted
   1.105 +endfunction
   1.106 +
   1.107 +autocmd BufNewFile __Scratch__ call s:ScratchMarkBuffer()
   1.108 +
   1.109 +" Command to edit the scratch buffer in the current window
   1.110 +command! -nargs=0 Scratch call s:ScratchBufferOpen(0)
   1.111 +" Command to open the scratch buffer in a new split window
   1.112 +command! -nargs=0 Sscratch call s:ScratchBufferOpen(1)
   1.113 +
     2.1 --- a/vimrc	Tue Sep 21 03:41:25 2010 +0200
     2.2 +++ b/vimrc	Tue Sep 21 03:57:32 2010 +0200
     2.3 @@ -80,6 +80,12 @@
     2.4  set smartindent
     2.5  inoremap # X#
     2.6  
     2.7 +" quicker window switching
     2.8 +nnoremap <C-h> <C-w>h
     2.9 +nnoremap <C-j> <C-w>j
    2.10 +nnoremap <C-k> <C-w>k
    2.11 +nnoremap <C-l> <C-w>l
    2.12 +
    2.13  " arrow keys move visible lines
    2.14  inoremap <Down> <C-R>=pumvisible() ? "\<lt>Down>" : "\<lt>C-O>gj"<CR>
    2.15  inoremap <Up> <C-R>=pumvisible() ? "\<lt>Up>" : "\<lt>C-O>gk"<CR>
    2.16 @@ -112,9 +118,10 @@
    2.17  
    2.18  " NERDtree on <leader>t
    2.19  nnoremap <leader>t :NERDTree<CR>
    2.20 +let NERDTreeIgnore=['\~$', '\.pyc$', '\.pyo$', '\.class$', 'pip-log\.txt$', '\.o$']
    2.21  
    2.22 -" Replace current split with new file
    2.23 -nnoremap <leader>n :new<CR> <C-w><C-l> :q<CR>
    2.24 +" Scratch
    2.25 +nmap <leader><tab> :Sscratch<CR><C-W>x<C-J>
    2.26  
    2.27  " Quit window on <leader>q
    2.28  nnoremap <leader>q :q<CR>

mercurial