Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add rename file, switch quotes and run tests

  • Loading branch information...
commit 751639a59f656baef6cb966db21d37a39e3e2c98 1 parent 0f11a21
@txus txus authored
Showing with 88 additions and 5 deletions.
  1. +12 −2 Readme.md
  2. +76 −3 vimrc
View
14 Readme.md
@@ -8,7 +8,7 @@ These are the new Codegram vimfiles!
If you trust me, do this:
- rm -fR ~/.vim && git clone https://github.com/codegram/vimfiles.git ~/.vim && rm ~/.vimrc && ln -s ~/.vim/vimrc ~/.vimrc && git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle && vim +BundleInstall +qa! && echo "Done! :)"
+ rm -fR ~/.vim && git clone https://github.com/codegram/vimfiles.git ~/.vim && rm ~/.vimrc && ln -s ~/.vim/vimrc ~/.vimrc && git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle && vim +BundleInstall +qa! && clear && echo "Done! :)"
### Manual way
@@ -37,6 +37,10 @@ TA-DA! Everything's done!
* The leader key is `,` (comma).
+### Files
+
+* `,n` renames current file, asking for the new name.
+
### Moving
* Arrow keys are disabled.
* `jk` is mapped to `<ESC>`, so you don't have to reach out to `<ESC>`.
@@ -52,12 +56,17 @@ TA-DA! Everything's done!
* `<leader>D` closes ALL the buffers.
### Splits
-* `,v` opens a new vertical split.
+* `,v` opens a new vertical split and switches to it.
* `<C-h>` switches to the left split.
* `<C-j>` switches to the split below.
* `<C-k>` switches to the split above.
* `<C-l>` switches to the right split.
+### Running tests (Ruby)
+
+* `,t` runs the current test file (RSpec, MiniTest or Cucumber).
+* `,T` runs the specific test under the cursor (RSpec or Cucumber).
+
### Other
* `<F2>` to toggle Paste mode (to paste stuff from the system clipboard).
@@ -122,6 +131,7 @@ Integration with Rails.
* `cs"'` changes surround from `"` to `'`.
* `ysiw"` surrounds inside the word with `"`.
+* `,'` switches `'` and `"` quotes.
### [vim-tcomment](https://github.com/jmartindf/vim-tcomment)
View
79 vimrc
@@ -41,9 +41,8 @@ colorscheme badwolf
" ------------
" VIM SETTINGS
" ------------
-filetype plugin indent on
-" colorscheme badwolf
syntax on
+filetype plugin indent on
set autoindent
set autoread
@@ -111,6 +110,12 @@ if has("gui_running")
endif
set guifont=Monaco:h12
+" Autocommands depending on file type
+autocmd FileType ruby,haml,eruby,yaml,html,javascript,sass,cucumber set ai sw=2 sts=2 et
+autocmd FileType python set sw=4 sts=4 et
+autocmd BufRead *.md set ai formatoptions=tcroqn2 comments=n:&gt;
+autocmd BufRead *.markdown set ai formatoptions=tcroqn2 comments=n:&gt;
+
" --------
" MAPPINGS
" --------
@@ -151,7 +156,7 @@ nmap <leader>D :bufdo bd<CR>
nmap <silent> <leader>b :FufBuffer<CR>
" Splits
-nnoremap <leader>v :vs<CR>
+nnoremap <leader>v :vs<CR> <C-w>l
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
@@ -178,6 +183,70 @@ endfunction
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
inoremap <s-tab> <c-n>
+" Rename current file
+function! RenameFile()
+ let old_name = expand('%')
+ let new_name = input('New file name: ', expand('%'))
+ if new_name != '' && new_name != old_name
+ exec ':saveas ' . new_name
+ exec ':silent !rm ' . old_name
+ redraw!
+ endif
+endfunction
+map <leader>n :call RenameFile()<cr>
+
+"--------------
+" RUNNING TESTS
+"--------------
+function! RunTests(filename)
+ " Write the file and run tests for the given filename
+ :w
+ :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
+ :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
+ :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
+ :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
+ :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
+ :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
+ if match(a:filename, '\.feature') != -1
+ exec ":!cucumber " . a:filename
+ elseif match(a:filename, '_spec\.rb') != -1
+ exec ":!rspec " . a:filename
+ elseif match(a:filename, '_test\.rb') != -1
+ exec ":!ruby -I'lib:test' " . a:filename
+ end
+endfunction
+
+function! SetTestFile()
+ " Set the spec file that tests will be run for.
+ let t:grb_test_file=@%
+endfunction
+
+function! RunTestFile(...)
+ if a:0
+ let command_suffix = a:1
+ else
+ let command_suffix = ""
+ endif
+
+ " Run the tests for the previously-marked file.
+ let in_test_file = match(expand("%"), '\(.feature\|_spec.rb\|_test.rb\)$') != -1
+ if in_test_file
+ call SetTestFile()
+ elseif !exists("t:grb_test_file")
+ return
+ end
+ call RunTests(t:grb_test_file . command_suffix)
+endfunction
+
+function! RunNearestTest()
+ let spec_line_number = line('.')
+
+ call RunTestFile(":" . spec_line_number)
+endfunction
+
+map <leader>t :call RunTestFile()<CR>
+map <leader>T :call RunNearestTest()<CR>
+
" ----------------
" PLUG-IN SETTINGS
" ----------------
@@ -216,6 +285,10 @@ map <F9> :tprev<CR>
" Ctrl-p
let g:ctrlp_map = '<leader>o'
+" Surround
+" ,' switches ' and "
+nnoremap <leader>' ""yls<c-r>={'"': "'", "'": '"'}[@"]<cr><esc>
+
" --------------------
" CUSTOM CONFIGURATION
" --------------------

0 comments on commit 751639a

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