Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added visual star command, and TextMate/NERD comment toggle.

  • Loading branch information...
commit ff45eb970f6b447c654f956114138c5fcd8e6ce7 1 parent 926b0da
Drew Neil authored

Showing 1 changed file with 60 additions and 0 deletions. Show diff stats Hide diff stats

  1. +60 0 vimrc
60 vimrc
... ... @@ -1,6 +1,9 @@
1 1 " Folding cheet sheet
2 2 " zR open all folds
3 3 " zM close all folds
  4 +" za toggle fold at cursor position
  5 +" zj move down to start of next fold
  6 +" zk move up to end of previous fold
4 7 " An example for a vimrc file. {{{1
5 8 "
6 9 " Maintainer: Bram Moolenaar <Bram@vim.org>
@@ -157,6 +160,7 @@ function! <SID>SynStack()
157 160 echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
158 161 endfunc
159 162 " Set tabstop, softtabstop and shiftwidth to the same value {{{2
  163 +" From http://vimcasts.org/episodes/tabs-and-spaces/
160 164 command! -nargs=* Stab call Stab()
161 165 function! Stab()
162 166 let l:tabstop = 1 * input('set tabstop = softtabstop = shiftwidth = ')
@@ -184,12 +188,68 @@ function! SummarizeTabs()
184 188 endtry
185 189 endfunction
186 190
  191 +" Strip trailing whitespaces {{{2
  192 +function! <SID>StripTrailingWhitespaces()
  193 + " Preparation: save last search, and cursor position.
  194 + let _s=@/
  195 + let l = line(".")
  196 + let c = col(".")
  197 + " Do the business:
  198 + %s/\s\+$//e
  199 + " Clean up: restore previous search history, and cursor position
  200 + let @/=_s
  201 + call cursor(l, c)
  202 +endfunction
  203 +nnoremap <silent> <F5> :call <SID>StripTrailingWhitespaces()<CR>
  204 +" Search for current visual selection with */# {{{2
  205 +" Tip tip from: http://amix.dk/blog/viewEntry/19334
  206 +function! CmdLine(str)
  207 + exe "menu Foo.Bar :" . a:str
  208 + emenu Foo.Bar
  209 + unmenu Foo
  210 +endfunction
  211 +
  212 +function! VisualSearch(direction) range
  213 + let l:saved_reg = @"
  214 + execute "normal! vgvy"
  215 +
  216 + let l:pattern = escape(@", '\\/.*$^~[]')
  217 + let l:pattern = substitute(l:pattern, "\n$", "", "")
  218 +
  219 + if a:direction == 'b'
  220 + execute "normal ?" . l:pattern . "^M"
  221 + elseif a:direction == 'gv'
  222 + call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.')
  223 + elseif a:direction == 'f'
  224 + execute "normal /" . l:pattern . "^M"
  225 + endif
  226 +
  227 + let @/ = l:pattern
  228 + let @" = l:saved_reg
  229 +endfunction
  230 +
  231 +"Basically you press * or # to search for the current selection
  232 +"then 'n' should search forward, 'N' should search backwards.
  233 +vnoremap <silent> * :call VisualSearch('f')<CR>
  234 +vnoremap <silent> # :call VisualSearch('b')<CR>
  235 +vnoremap <silent> gv :call VisualSearch('gv')<CR>
  236 +
  237 +" Status line {{{1
  238 +" Good article on setting a statusline:
  239 +" http://got-ravings.blogspot.com/2008/08/vim-pr0n-making-statuslines-that-own.html
  240 +
187 241 " Mappings for a recovering TextMate user {{{1
188 242 " Indentation {{{2
189 243 nmap <D-[> <<
190 244 nmap <D-]> >>
191 245 vmap <D-[> <gv
192 246 vmap <D-]> >gv
  247 +
  248 +" Commenting {{{2
  249 +" requires NERDCommenter plugin
  250 +vmap <D-/> ,c<space>gv
  251 +map <D-/> ,c<space>
  252 +
193 253 " Move selection {{{2
194 254 " Move current line down/up
195 255 map <C-Down> ddp

0 comments on commit ff45eb9

Please sign in to comment.
Something went wrong with that request. Please try again.