diff --git a/Rakefile b/Rakefile index 7e57a03..06eb01a 100644 --- a/Rakefile +++ b/Rakefile @@ -68,6 +68,15 @@ task :install_prezto do install_prezto if want_to_install?('zsh enhancements & prezto') end +desc 'install spacevim and related config files' +task :install_spacevim do + run %( + curl -sLf https://spacevim.org/install.sh | bash + rm -rf ~/.SpaceVim.d + ln -s $(pwd)/SpaceVim.d ~/.SpaceVim.d + ) +end + desc 'Install tools which are necessary for developers' task :install_tools do if macos? diff --git a/SpaceVim.d/autoload/README.md b/SpaceVim.d/autoload/README.md new file mode 100644 index 0000000..961db93 --- /dev/null +++ b/SpaceVim.d/autoload/README.md @@ -0,0 +1,9 @@ +This directory contains settings for various vim plugins and vim itself. + +## Plugin Settings + +Each plugin's overrides/settings should be put in a separate file named `{plugin-name}.vim`. + +## Vim Settings + +General vim overrides/settings should be put in a separate file named `yadr-{descriptive-name}.vim`. diff --git a/SpaceVim.d/autoload/abbr.vim b/SpaceVim.d/autoload/abbr.vim new file mode 100644 index 0000000..c33260b --- /dev/null +++ b/SpaceVim.d/autoload/abbr.vim @@ -0,0 +1,9 @@ +"Abbreviations, trigger by typing the abbreviation and hitting space + +abbr rlb Rails.logger.banner +abbr rld Rails.logger.debug +abbr pry! require 'pry'; binding.pry +abbr cl! console.log( ) + +" Rspec Before +abbr rbf before { } diff --git a/SpaceVim.d/autoload/ag.vim b/SpaceVim.d/autoload/ag.vim new file mode 100644 index 0000000..a6dcd27 --- /dev/null +++ b/SpaceVim.d/autoload/ag.vim @@ -0,0 +1,3 @@ +" Open the Ag command and place the cursor into the quotes +nmap ,ag :Ag "" +nmap ,af :AgFile "" diff --git a/SpaceVim.d/autoload/autotag.vim b/SpaceVim.d/autoload/autotag.vim new file mode 100644 index 0000000..342dff4 --- /dev/null +++ b/SpaceVim.d/autoload/autotag.vim @@ -0,0 +1,3 @@ +" AutoTag +" Seems to have problems with some vim files +let g:autotagExcludeSuffixes="tml.xml.text.txt.vim" diff --git a/SpaceVim.d/autoload/camelcasemotion.vim b/SpaceVim.d/autoload/camelcasemotion.vim new file mode 100644 index 0000000..2f6784b --- /dev/null +++ b/SpaceVim.d/autoload/camelcasemotion.vim @@ -0,0 +1,7 @@ +map W CamelCaseMotion_w +map B CamelCaseMotion_b +map E CamelCaseMotion_e + +sunmap W +sunmap B +sunmap E \ No newline at end of file diff --git a/SpaceVim.d/autoload/ctrlp.vim b/SpaceVim.d/autoload/ctrlp.vim new file mode 100644 index 0000000..bb94db8 --- /dev/null +++ b/SpaceVim.d/autoload/ctrlp.vim @@ -0,0 +1,74 @@ +if exists("g:ctrlp_user_command") + unlet g:ctrlp_user_command +endif +if executable('rg') + " Use rg in CtrlP for listing files. Lightning fast and respects .gitignore + let g:ctrlp_user_command = 'rg --hidden --files -g \!.git -g \!.DS_Store --smart-case %s' + + " rg is fast enough that CtrlP doesn't need to cache + let g:ctrlp_use_caching = 0 +elseif executable('ag') + " Use ag in CtrlP for listing files. Lightning fast and respects .gitignore + let g:ctrlp_user_command = 'ag %s --hidden --files-with-matches -g "" --ignore "\.git$\|\.hg$\|\.svn$"' + + " ag is fast enough that CtrlP doesn't need to cache + let g:ctrlp_use_caching = 0 +else + " Fall back to using git ls-files if Ag is not available + let g:ctrlp_custom_ignore = '\.git$\|\.hg$\|\.svn$' + let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files . --cached --exclude-standard --others'] +endif + +" Default to filename searches - so that appctrl will find application +" controller +let g:ctrlp_by_filename = 1 + +let g:ctrlp_working_path_mode = 'ra' +set wildignore+=*/tmp/*,*.so,*.swp,*.zip " MacOSX/Linux +let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$' +let g:ctrlp_custom_ignore = { + \ 'dir': '\v[\/](\.git|\.hg|\.svn|node_modules)$', + \ 'file': '\v\.(exe|so|dll)$', + \ 'link': 'some_bad_symbolic_links', + \ } + +" show even .ssh/config file +let g:ctrlp_show_hidden = 1 + +" Don't jump to already open window. This is annoying if you are maintaining +" several Tab workspaces and want to open two windows into the same file. +let g:ctrlp_switch_buffer = 0 + +" We don't want to use Ctrl-p as the mapping because +" it interferes with YankRing (paste, then hit ctrl-p) +let g:ctrlp_map = ',t' +nnoremap ,t :CtrlP + +" Additional mapping for buffer search +nnoremap ,b :CtrlPBuffer + +" Cmd-Shift-P to clear the cache +nnoremap :ClearCtrlPCache + +" Idea from : http://www.charlietanksley.net/blog/blog/2011/10/18/vim-navigation-with-lustyexplorer-and-lustyjuggler/ +" Open CtrlP starting from a particular path, making it much +" more likely to find the correct thing first. mnemonic 'jump to [something]' +map ,ja :CtrlP app/assets +map ,jm :CtrlP app/models +map ,jc :CtrlP app/controllers +map ,jv :CtrlP app/views +map ,jj :CtrlP app/assets/javascripts +map ,jh :CtrlP app/helpers +map ,jl :CtrlP lib +map ,jp :CtrlP public +map ,js :CtrlP spec +map ,jf :CtrlP fast_spec +map ,jd :CtrlP db +map ,jC :CtrlP config +map ,jV :CtrlP vendor +map ,jF :CtrlP factories +map ,jT :CtrlP test + +"Cmd-Shift-(M)ethod - jump to a method (tag in current file) +"Ctrl-m is not good - it overrides behavior of Enter +nnoremap :CtrlPBufTag diff --git a/SpaceVim.d/autoload/easy-grep.vim b/SpaceVim.d/autoload/easy-grep.vim new file mode 100644 index 0000000..973eaae --- /dev/null +++ b/SpaceVim.d/autoload/easy-grep.vim @@ -0,0 +1 @@ +nnoremap :Gsearch diff --git a/SpaceVim.d/autoload/easymotion.vim b/SpaceVim.d/autoload/easymotion.vim new file mode 100644 index 0000000..a7d4821 --- /dev/null +++ b/SpaceVim.d/autoload/easymotion.vim @@ -0,0 +1,8 @@ +" These keys are easier to type than the default set +" We exclude semicolon because it's hard to read and +" i and l are too easy to mistake for each other slowing +" down recognition. The home keys and the immediate keys +" accessible by middle fingers are available +let g:EasyMotion_keys='asdfjkoweriop' +nmap , ,,w +nmap , ,,b diff --git a/SpaceVim.d/autoload/gh-markdown.vim b/SpaceVim.d/autoload/gh-markdown.vim new file mode 100644 index 0000000..99d037e --- /dev/null +++ b/SpaceVim.d/autoload/gh-markdown.vim @@ -0,0 +1,6 @@ +" Support for github flavored markdown +" via https://github.com/jtratner/vim-flavored-markdown +augroup markdown + au! + au BufNewFile,BufRead *.md,*.markdown setlocal filetype=ghmarkdown +augroup END diff --git a/SpaceVim.d/autoload/go.vim b/SpaceVim.d/autoload/go.vim new file mode 100644 index 0000000..c91a021 --- /dev/null +++ b/SpaceVim.d/autoload/go.vim @@ -0,0 +1,56 @@ +let g:go_fmt_fail_silently = 1 +let g:go_fmt_command = "gofmt" "Explicited the formater plugin (gofmt, goimports, goreturn...) + +" Show a list of interfaces which is implemented by the type under your cursor +au FileType go nmap s (go-implements) + +" Show type info for the word under your cursor +au FileType go nmap i (go-info) + +" Open the relevant Godoc for the word under the cursor +au FileType go nmap gd (go-doc) +au FileType go nmap gv (go-doc-vertical) + +" Open the Godoc in browser +au FileType go nmap gb (go-doc-browser) + +" Run/build/test/coverage +au FileType go nmap gr (go-run) +au FileType go nmap gb (go-build) +au FileType go nmap gt (go-test) +au FileType go nmap gc (go-coverage) + +" By default syntax-highlighting for Functions, Methods and Structs is disabled. +" Let's enable them! +let g:go_highlight_functions = 1 +let g:go_highlight_methods = 1 +let g:go_highlight_structs = 1 + +nmap :TagbarToggle +let g:tagbar_type_go = { + \ 'ctagstype' : 'go', + \ 'kinds' : [ + \ 'p:package', + \ 'i:imports:1', + \ 'c:constants', + \ 'v:variables', + \ 't:types', + \ 'n:interfaces', + \ 'w:fields', + \ 'e:embedded', + \ 'm:methods', + \ 'r:constructor', + \ 'f:functions' + \ ], + \ 'sro' : '.', + \ 'kind2scope' : { + \ 't' : 'ctype', + \ 'n' : 'ntype' + \ }, + \ 'scope2kind' : { + \ 'ctype' : 't', + \ 'ntype' : 'n' + \ }, + \ 'ctagsbin' : 'gotags', + \ 'ctagsargs' : '-sort -silent' +\ } diff --git a/SpaceVim.d/autoload/gotofile.vim b/SpaceVim.d/autoload/gotofile.vim new file mode 100644 index 0000000..f2e7526 --- /dev/null +++ b/SpaceVim.d/autoload/gotofile.vim @@ -0,0 +1,6 @@ +" Automatically jump to a file at the correct line number +" i.e. if your cursor is over /some/path.rb:50 then using 'gf' on it will take +" you to that line + +" use ,gf to go to file in a vertical split +nnoremap ,gf :vertical botright wincmd F diff --git a/SpaceVim.d/autoload/grep.vim b/SpaceVim.d/autoload/grep.vim new file mode 100644 index 0000000..f400d84 --- /dev/null +++ b/SpaceVim.d/autoload/grep.vim @@ -0,0 +1,4 @@ +"Use RipGrep for lightning fast Gsearch command +set grepprg=rg\ --vimgrep\ --no-heading +set grepformat=%f:%l:%c:%m,%f:%l:%m +let g:grep_cmd_opts = '--line-number' diff --git a/SpaceVim.d/autoload/gundo.vim b/SpaceVim.d/autoload/gundo.vim new file mode 100644 index 0000000..2392ad5 --- /dev/null +++ b/SpaceVim.d/autoload/gundo.vim @@ -0,0 +1,7 @@ +nmap ,u :GundoToggle + +" open on the right so as not to compete with the nerdtree +let g:gundo_right = 1 + +" a little wider for wider screens +let g:gundo_width = 60 diff --git a/SpaceVim.d/autoload/iterm-rspec.vim b/SpaceVim.d/autoload/iterm-rspec.vim new file mode 100644 index 0000000..032aee8 --- /dev/null +++ b/SpaceVim.d/autoload/iterm-rspec.vim @@ -0,0 +1,6 @@ +nnoremap ,rs :RunItermSpec +nnoremap ,rl :RunItermSpecLine +nnoremap ,ss :RunItermSpringSpec +nnoremap ,sl :RunItermSpringSpecLine +nnoremap zl :RunItermZeusSpecLine +nnoremap zs :RunItermZeusSpec diff --git a/SpaceVim.d/autoload/js.vim b/SpaceVim.d/autoload/js.vim new file mode 100644 index 0000000..6072f07 --- /dev/null +++ b/SpaceVim.d/autoload/js.vim @@ -0,0 +1,29 @@ +let javascript_enable_domhtmlcss = 0 +let javascript_ignore_javaScriptdoc = 0 +let g:javascript_conceal=0 +let b:javascript_fold=1 + +function! IndexComponentSwitch() + let b:filename=expand('%') + if b:filename =~ 'index\.js$' + execute 'edit' substitute(b:filename, "index.js", "component.js", "") + else + execute 'edit' substitute(b:filename, "component.js", "index.js", "") + endif +endfunction + +au FileType javascript nmap s :call IndexComponentSwitch() + +let g:javascript_conceal_function = "ƒ" +let g:javascript_conceal_null = "ø" +let g:javascript_conceal_this = "@" +let g:javascript_conceal_return = "⇚" +let g:javascript_conceal_undefined = "¿" +let g:javascript_conceal_NaN = "ℕ" +let g:javascript_conceal_prototype = "¶" +let g:javascript_conceal_static = "•" +let g:javascript_conceal_super = "Ω" +let g:javascript_conceal_arrow_function = "⇒" +let g:javascript_conceal_noarg_arrow_function = "🞅" +let g:javascript_conceal_underscore_arrow_function = "🞅" +map c :exec &conceallevel ? "set conceallevel=0" : "set conceallevel=1" diff --git a/SpaceVim.d/autoload/lightline.vim b/SpaceVim.d/autoload/lightline.vim new file mode 100644 index 0000000..892f509 --- /dev/null +++ b/SpaceVim.d/autoload/lightline.vim @@ -0,0 +1,40 @@ +let g:lightline = { + \ 'colorscheme': 'solarized', + \ 'active': { + \ 'left': [ [ 'mode', 'paste' ], + \ [ 'fugitive', 'readonly', 'filename', 'modified' ] ] + \ }, + \ 'component_function': { + \ 'fugitive': 'MyFugitive', + \ 'readonly': 'MyReadonly', + \ 'filename': 'MyFilename', + \ }, + \ 'separator': { 'left': '⮀', 'right': '⮂' }, + \ 'subseparator': { 'left': '⮁', 'right': '⮃' } + \ } + +function! MyReadonly() + if &filetype == "help" + return "" + elseif &readonly + return "⭤ " + else + return "" + endif +endfunction + +function! MyFugitive() + if exists("*fugitive#head") + let _ = fugitive#head() + return strlen(_) ? '⭠ '._ : '' + endif + return '' +endfunction + +function! MyFilename() + return ('' != MyReadonly() ? MyReadonly() . ' ' : '') . + \ ('' != expand('%') ? expand('%') : '[NoName]') +endfunction + +" Use status bar even with single buffer +set laststatus=2 diff --git a/SpaceVim.d/autoload/markdown.vim b/SpaceVim.d/autoload/markdown.vim new file mode 100644 index 0000000..d6d662b --- /dev/null +++ b/SpaceVim.d/autoload/markdown.vim @@ -0,0 +1,9 @@ +let g:instant_markdown_slow = 1 +let g:instant_markdown_autostart = 1 +augroup filetype_markdown + autocmd! + autocmd FileType mkd setlocal spell + autocmd FileType mkd setlocal sw=2 ts=2 + autocmd BufNewFile,BufReadPost *.md set filetype=markdown + let g:vim_markdown_initial_foldlevel=1 +augroup END diff --git a/SpaceVim.d/autoload/next-textobject.vim b/SpaceVim.d/autoload/next-textobject.vim new file mode 100644 index 0000000..836d8f6 --- /dev/null +++ b/SpaceVim.d/autoload/next-textobject.vim @@ -0,0 +1,136 @@ +" Stolen from Steve Losh +" https://github.com/sjl/dotfiles/blob/master/vim/vimrc#L1380 +" +" Motion for "next/last object". "Last" here means "previous", not "final". +" Unfortunately the "p" motion was already taken for paragraphs. +" +" Next acts on the next object of the given type, last acts on the previous +" object of the given type. These don't necessarily have to be in the current +" line. +" +" Currently works for (, [, {, and their shortcuts b, r, B. +" +" Next kind of works for ' and " as long as there are no escaped versions of +" them in the string (TODO: fix that). Last is currently broken for quotes +" (TODO: fix that). +" +" Some examples (C marks cursor positions, V means visually selected): +" +" din' -> delete in next single quotes foo = bar('spam') +" C +" foo = bar('') +" C +" +" canb -> change around next parens foo = bar('spam') +" C +" foo = bar +" C +" +" vin" -> select inside next double quotes print "hello ", name +" C +" print "hello ", name +" VVVVVV + +onoremap an :call NextTextObject('a', '/') +xnoremap an :call NextTextObject('a', '/') +onoremap in :call NextTextObject('i', '/') +xnoremap in :call NextTextObject('i', '/') + +onoremap al :call NextTextObject('a', '?') +xnoremap al :call NextTextObject('a', '?') +onoremap il :call NextTextObject('i', '?') +xnoremap il :call NextTextObject('i', '?') + + +function! s:NextTextObject(motion, dir) + let c = nr2char(getchar()) + let d = '' + + if c ==# "b" || c ==# "(" || c ==# ")" + let c = "(" + elseif c ==# "B" || c ==# "{" || c ==# "}" + let c = "{" + elseif c ==# "r" || c ==# "[" || c ==# "]" + let c = "[" + elseif c ==# "'" + let c = "'" + elseif c ==# '"' + let c = '"' + else + return + endif + + " Find the next opening-whatever. + execute "normal! " . a:dir . c . "\" + + if a:motion ==# 'a' + " If we're doing an 'around' method, we just need to select around it + " and we can bail out to Vim. + execute "normal! va" . c + else + " Otherwise we're looking at an 'inside' motion. Unfortunately these + " get tricky when you're dealing with an empty set of delimiters because + " Vim does the wrong thing when you say vi(. + + let open = '' + let close = '' + + if c ==# "(" + let open = "(" + let close = ")" + elseif c ==# "{" + let open = "{" + let close = "}" + elseif c ==# "[" + let open = "\\[" + let close = "\\]" + elseif c ==# "'" + let open = "'" + let close = "'" + elseif c ==# '"' + let open = '"' + let close = '"' + endif + + " We'll start at the current delimiter. + let start_pos = getpos('.') + let start_l = start_pos[1] + let start_c = start_pos[2] + + " Then we'll find it's matching end delimiter. + if c ==# "'" || c ==# '"' + " searchpairpos() doesn't work for quotes, because fuck me. + let end_pos = searchpos(open) + else + let end_pos = searchpairpos(open, '', close) + endif + + let end_l = end_pos[0] + let end_c = end_pos[1] + + call setpos('.', start_pos) + + if start_l == end_l && start_c == (end_c - 1) + " We're in an empty set of delimiters. We'll append an "x" + " character and select that so most Vim commands will do something + " sane. v is gonna be weird, and so is y. Oh well. + execute "normal! ax\\" + execute "normal! vi" . c + elseif start_l == end_l && start_c == (end_c - 2) + " We're on a set of delimiters that contain a single, non-newline + " character. We can just select that and we're done. + execute "normal! vi" . c + else + " Otherwise these delimiters contain something. But we're still not + " sure Vim's gonna work, because if they contain nothing but + " newlines Vim still does the wrong thing. So we'll manually select + " the guts ourselves. + let whichwrap = &whichwrap + set whichwrap+=h,l + + execute "normal! va" . c . "hol" + + let &whichwrap = whichwrap + endif + endif +endfunction diff --git a/SpaceVim.d/autoload/open-changed-files.vim b/SpaceVim.d/autoload/open-changed-files.vim new file mode 100644 index 0000000..c5e0599 --- /dev/null +++ b/SpaceVim.d/autoload/open-changed-files.vim @@ -0,0 +1,20 @@ +"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" OpenChangedFiles COMMAND +" Open a split for each dirty file in git +" +" Shamelessly stolen from Gary Bernhardt: https://github.com/garybernhardt/dotfiles +"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +function! OpenChangedFiles() + only " Close all windows, unless they're modified + let status = system('git status -s | grep "^ \?\(M\|A\)" | cut -d " " -f 3') + let filenames = split(status, "\n") + if len(filenames) > 0 + exec "edit " . filenames[0] + for filename in filenames[1:] + exec "sp " . filename + endfor + end +endfunction +command! OpenChangedFiles :call OpenChangedFiles() + +nnoremap ,ocf :OpenChangedFiles diff --git a/SpaceVim.d/autoload/outerblock.vim b/SpaceVim.d/autoload/outerblock.vim new file mode 100644 index 0000000..bc65559 --- /dev/null +++ b/SpaceVim.d/autoload/outerblock.vim @@ -0,0 +1,13 @@ +" Navigate to the block surrounding this one +" For example if you're inside +" foo do +" bar do +" # you are here +" end +" end +" +" Then hitting ,orb ("outer ruby block") will take you to 'foo do' +" +" This is relying on the textobj-rubyblock which gives us 'ar' around ruby +" and matchit.vim which gives us jumping to the matching +nnoremap ,orb :normal varar% diff --git a/SpaceVim.d/autoload/paiyou.vim b/SpaceVim.d/autoload/paiyou.vim new file mode 100644 index 0000000..95b51c5 --- /dev/null +++ b/SpaceVim.d/autoload/paiyou.vim @@ -0,0 +1,327 @@ +function! paiyou#after() abort + let g:ale_fixers = { + \ 'javascript': ['eslint'], + \ 'ruby': ['rubocop'], + \} + let g:ale_fix_on_save = 1 +endfunction + +" ======================================== +" General vim sanity improvements +" ======================================== +" +" +" alias yw to yank the entire word 'yank inner word' +" even if the cursor is halfway inside the word +" FIXME: will not properly repeat when you use a dot (tie into repeat.vim) +nnoremap ,yw yiww + +" ,ow = 'overwrite word', replace a word with what's in the yank buffer +" FIXME: will not properly repeat when you use a dot (tie into repeat.vim) +nnoremap ,ow "_diwhp + +"make Y consistent with C and D +nnoremap Y y$ +function! YRRunAfterMaps() + nnoremap Y :YRYankCount 'y$' +endfunction + +" Make 0 go to the first character rather than the beginning +" of the line. When we're programming, we're almost always +" interested in working with text rather than empty space. If +" you want the traditional beginning of line, use ^ +nnoremap 0 ^ +nnoremap ^ 0 + +" ,# Surround a word with #{ruby interpolation} +map ,# ysiw# +vmap ,# c#{"} + +" ," Surround a word with "quotes" +map ," ysiw" +vmap ," c""" + +" ,' Surround a word with 'single quotes' +map ,' ysiw' +vmap ,' c'"' + +" ,) or ,( Surround a word with (parens) +" The difference is in whether a space is put in +map ,( ysiw( +map ,) ysiw) +vmap ,( c( " ) +vmap ,) c(") + +" ,[ Surround a word with [brackets] +map ,] ysiw] +map ,[ ysiw[ +vmap ,[ c[ " ] +vmap ,] c["] + +" ,{ Surround a word with {braces} +map ,} ysiw} +map ,{ ysiw{ +vmap ,} c{ " } +vmap ,{ c{"} + +map ,` ysiw` + +" gary bernhardt's hashrocket +imap => + +"Go to last edit location with ,. +nnoremap ,. '. + +"When typing a string, your quotes auto complete. Move past the quote +"while still in insert mode by hitting Ctrl-a. Example: +" +" type 'foo +" +" the first quote will autoclose so you'll get 'foo' and hitting will +" put the cursor right after the quote +imap wa + +" ==== NERD tree +" Open the project tree and expose current file in the nerdtree with Ctrl-\ +" " calls NERDTreeFind iff NERDTree is active, current window contains a modifiable file, and we're not in vimdiff +function! OpenNerdTree() + if &modifiable && strlen(expand('%')) > 0 && !&diff + NERDTreeFind + else + NERDTreeToggle + endif +endfunction +nnoremap :call OpenNerdTree() + +" ,q to toggle quickfix window (where you have stuff like Ag) +" ,oq to open it back up (rare) +nmap ,qc :cclose +nmap ,qo :copen + +"Move back and forth through previous and next buffers +"with ,z and ,x +nnoremap ,z :bp +nnoremap ,x :bn + +" ============================== +" Window/Tab/Split Manipulation +" ============================== +" Move between split windows by using the four directions H, L, K, J +" NOTE: This has moved to vim/settings/vim-tmux-navigator.vim. +" nnoremap h +" nnoremap l +" nnoremap k +" nnoremap j + +" Make gf (go to file) create the file, if not existent +nnoremap f :sp +e +nnoremap gf :tabe + +" Zoom in +map ,gz o + +" Create window splits easier. The default +" way is Ctrl-w,v and Ctrl-w,s. I remap +" this to vv and ss +nnoremap vv v +nnoremap ss s + +" create <%= foo %> erb tags using Ctrl-k in edit mode +imap <%= %>3hi + +" create <%= foo %> erb tags using Ctrl-j in edit mode +imap <% %>2hi + +" ============================ +" Shortcuts for everyday tasks +" ============================ + +" copy current filename into system clipboard - mnemonic: (c)urrent(f)ilename +" this is helpful to paste someone the path you're looking at +nnoremap ,cf :let @* = expand("%:~") +nnoremap ,cr :let @* = expand("%") +nnoremap ,cn :let @* = expand("%:t") + +"Clear current search highlight by double tapping // +nmap // :nohlsearch + +"(v)im (c)ommand - execute current line as a vim command +nmap ,vc yy:p + +"(v)im (r)eload +nmap ,vr :so % + +" Type ,hl to toggle highlighting on/off, and show current value. +noremap ,hl :set hlsearch! hlsearch? + +" These are very similar keys. Typing 'a will jump to the line in the current +" file marked with ma. However, `a will jump to the line and column marked +" with ma. Its more useful in any case I can imagine, but its located way +" off in the corner of the keyboard. The best way to handle this is just to +" swap them: http://items.sjbach.com/319/configuring-vim-right +nnoremap ' ` +nnoremap ` ' + +" ============================ +" SplitJoin plugin +" ============================ +nmap sj :SplitjoinSplit +nmap sk :SplitjoinJoin + +" Get the current highlight group. Useful for then remapping the color +map ,hi :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">" . " FG:" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"fg#") + +" ,hp = html preview +map ,hp :!open -a Safari % + +"paste text in insertion mode +inoremap "+pa +"paste text in normal mode +nnoremap "+p" + +"------------------------------------------------------------------------------ +" Misc +"------------------------------------------------------------------------------ +" Toggle paste mode on and off +map pp :setlocal paste! +" copy all out of vim +nnoremap gg"+yG +" copy text in visual mode +vnoremap "+yy +" copy all inside vim +nnoremap ggyG +" edit file +nmap ev :tabedit $MYVIMRC'tzo +nmap em :tabedit makefile + +" move around compile errors +nnoremap n :cnext +nnoremap p :cprevious + +nnoremap l :redraw! +imap cb ?? +nnoremap n :cn +nnoremap p :cp + +" Fast Saving +map w :w +imap w :w +vmap w :w + +" :W sudo saves the file +" (useful for handling the permission-denied error) +if !exists(':W') + command W w !sudo tee % > /dev/null +endif + +" Highlight current line - allows you to track cursor position more easily +set cursorline + +" map CTRL-L to piece-wise copying of the line above the current one +imap @@@hhkywjl?@@@P/@@@3s + + +" Allow to copy/paste between VIM instances +"copy the current visual selection to ~/.vbuf +vmap y :w! ~/.vbuf + +"copy the current line to the buffer file if no visual selection +vmap y :.w! ~/.vbuf + +"paste the contents of the buffer file +nmap p :r ~/.vbuf + +"------------------------------------------------------------------------------ +" Moving around, tabs, windows and buffers +"------------------------------------------------------------------------------ +" Switch between the last two files +nnoremap + +" easy way to edit reload .vimrc +nmap V :source $MYVIMRC +nmap v :vsp $MYVIMRC + +" Quickly open a buffer for scribble +map q :e ~/buffer + +" Quickly open a markdown buffer for scribble +map x :e ~/buffer.md + +" Remove the Windows ^M - when the encodings gets messed up +noremap m mmHmt:%s///ge'tzt'm + +"------------------------------------------------------------------------------ +" Spell checking +"------------------------------------------------------------------------------ + +" Pressing ,ss will toggle and untoggle spell checking +map ss :setlocal spell! + +" visual shifting (does not exit Visual mode) +vnoremap < >gv + +" Switch CWD to the directory of the open buffer +map cd :cd %:p:h:pwd + +" Treat long lines as break lines (useful when moving around in them) +map j gj +map k gk + +" Close the current buffer (w/o closing the current window) +map bd :bd + +" Close all the buffers +map bda :1,1000 bd! + +" Useful mappings for managing tabs +map tn :tabnew +map to :tabonly +map tc :tabclose +map tm :tabmove +map tj :tabnext +map tk :tabprevious + +" Let 'tl' toggle between this and the last accessed tab +let g:lasttab = 1 +nmap tl :exe "tabn ".g:lasttab +au TabLeave * let g:lasttab = tabpagenr() + +"------------------------------------------------------------------------------ +" Visual mode related +"------------------------------------------------------------------------------ + +" Visual mode pressing * or # searches for the current selection +" Super useful! From an idea by Michael Naumann +vnoremap * :call VisualSelection('f', '') +vnoremap # :call VisualSelection('b', '') + + +noremap :echo 'Action is not allowed' +noremap :echo 'Action is not allowed' +noremap :echo 'Action is not allowed' +noremap :echo 'Action is not allowed' +inoremap fn =expand("%:t") + + +function! TogglePaste() + if &paste + setlocal nopaste + else + setlocal paste + endif +endfunction + +function! ToggleRspecTest() + let l:line=getline('.') + if l:line =~? ',\s*now:\s.*true' + call setline('.', substitute(l:line, "\,\\s*now:\\s*true", "", "")) + else + call setline('.', substitute(l:line, "\\([^\\s]\\)\\s*do", "\\1, now: true do", "")) + endif +endfunction + +" set paste +nnoremap tp :call TogglePaste() +nnoremap tt :call ToggleRspecTest() + diff --git a/SpaceVim.d/autoload/path.vim b/SpaceVim.d/autoload/path.vim new file mode 100644 index 0000000..a13fa5a --- /dev/null +++ b/SpaceVim.d/autoload/path.vim @@ -0,0 +1,12 @@ +" Set the shell to bash so we inherit its path, to make sure +" we inherit its path. This affects :Rtags finding the right +" path to homebrewed ctags rather than the XCode version of ctags +if has("unix") + let s:uname = system("uname -s") + if s:uname =~ "Darwin" + set shell=/usr/local/bin/zsh + else + set shell=/usr/bin/zsh + endif +elseif has('win32') +endif diff --git a/SpaceVim.d/autoload/python-mode.vim b/SpaceVim.d/autoload/python-mode.vim new file mode 100644 index 0000000..74344d5 --- /dev/null +++ b/SpaceVim.d/autoload/python-mode.vim @@ -0,0 +1,24 @@ +" Override go-to.definition key shortcut to Ctrl-] +autocmd FileType python set colorcolumn=160 +let g:pymode_rope_goto_definition_bind = "" + +" Override run current python file key shortcut to Ctrl-Shift-e +let g:pymode_run_bind = "" + +" Override view python doc key shortcut to Ctrl-Shift-d +let g:pymode_doc_bind = "" +let g:pymode_lint_ignore = "W0611" +let g:pymode_options_max_line_length=160 +let g:pymode_rope_lookup_project = 0 + +augroup filetype_python + autocmd! + "autocmd FileType python set omnifunc=pythoncomplete#Complete + autocmd FileType python setlocal foldmethod=indent + autocmd FileType python nnoremap :execute "!./" . expand("%") + autocmd FileType python setlocal foldlevel=99 + autocmd FileType python setlocal statusline=%f-%y-[%l]/[%L] + autocmd FileType python nnoremap c I#cesc> + autocmd FileType python :iabbrev iff if: + autocmd FileType python set nowrap +augroup END diff --git a/SpaceVim.d/autoload/python.vim b/SpaceVim.d/autoload/python.vim new file mode 100644 index 0000000..3a745b4 --- /dev/null +++ b/SpaceVim.d/autoload/python.vim @@ -0,0 +1,4 @@ +autocmd FileType python set shiftwidth=4 +autocmd FileType python set tabstop=4 +autocmd FileType python set softtabstop=4 +autocmd FileType python set expandtab diff --git a/SpaceVim.d/autoload/quickfix-search.vim b/SpaceVim.d/autoload/quickfix-search.vim new file mode 100644 index 0000000..a1d6414 --- /dev/null +++ b/SpaceVim.d/autoload/quickfix-search.vim @@ -0,0 +1,6 @@ +" Stolen from Steve Losh vimrc: https://bitbucket.org/sjl/dotfiles/src/tip/vim/.vimrc +" Open a Quickfix window for the last search. +nnoremap q/ :execute 'vimgrep /'.@/.'/g %':copen + +" Ag for the last search. +nnoremap qa/ :execute "Ag! '" . substitute(substitute(substitute(@/, "\\\\<", "\\\\b", ""), "\\\\>", "\\\\b", ""), "\\\\v", "", "") . "'" diff --git a/SpaceVim.d/autoload/rails.vim b/SpaceVim.d/autoload/rails.vim new file mode 100644 index 0000000..ab673d2 --- /dev/null +++ b/SpaceVim.d/autoload/rails.vim @@ -0,0 +1,4 @@ +" Better key maps for switching between controller and view +nnoremap ,vv :Eview +nnoremap ,cc :Econtroller +nnoremap ,hc :%s/:\([^=,'"]*\) =>/\1:/gc diff --git a/SpaceVim.d/autoload/ripgrep.vim b/SpaceVim.d/autoload/ripgrep.vim new file mode 100644 index 0000000..ccece01 --- /dev/null +++ b/SpaceVim.d/autoload/ripgrep.vim @@ -0,0 +1,3 @@ +" Open the Rg command and place the cursor into the quotes +nmap ,rg :Rg "" +nmap ,rf :Rg --files "" diff --git a/SpaceVim.d/autoload/rspec.vim b/SpaceVim.d/autoload/rspec.vim new file mode 100644 index 0000000..da92d2b --- /dev/null +++ b/SpaceVim.d/autoload/rspec.vim @@ -0,0 +1,29 @@ +" Does not work on pending 'blocks', only single lines +" +" Given: +" it "foo bar" do +" pending("bla bla" +" +" Produce: +" xit "foo bar" do +" +function! ChangePendingRspecToXit() + " Find the next occurrence of pending + while(search("pending(") > 0) + " Delete it + normal dd + " Search backwards to the it block + ?it\s + " add an 'x' to the 'it' to make it 'xit' + normal ix + endwhile +endfunction + +nnoremap ,rxit :call ChangePendingRspecToXit() + +" insert a before { } block around a line +nnoremap \bf ^ibefore { $a } + +" insert a specify { } block around a line +nnoremap \sp ^ispecify { $a } + diff --git a/SpaceVim.d/autoload/search.vim b/SpaceVim.d/autoload/search.vim new file mode 100644 index 0000000..82cf075 --- /dev/null +++ b/SpaceVim.d/autoload/search.vim @@ -0,0 +1,30 @@ +function! GetVisual() + let reg_save = getreg('"') + let regtype_save = getregtype('"') + let cb_save = &clipboard + set clipboard& + normal! ""gvy + let selection = getreg('"') + call setreg('"', reg_save, regtype_save) + let &clipboard = cb_save + return selection +endfunction + +"grep the current word using ,k (mnemonic Kurrent) +nnoremap ,k :Ag + +"grep visual selection +vnoremap ,k :execute "Ag " . GetVisual() + +"grep current word up to the next exclamation point using ,K +nnoremap ,K viwf!:execute "Ag " . GetVisual() + +"grep for 'def foo' +nnoremap ,gd :Ag 'def ' + +",gg = Grep! - using Ag the silver searcher +" open up a grep line, with a quote started for the search +nnoremap ,gg :Ag "" + +"Grep for usages of the current file +nnoremap ,gcf :exec "Ag " . expand("%:t:r") diff --git a/SpaceVim.d/autoload/showmarks.vim b/SpaceVim.d/autoload/showmarks.vim new file mode 100644 index 0000000..c844c53 --- /dev/null +++ b/SpaceVim.d/autoload/showmarks.vim @@ -0,0 +1,2 @@ +" Tell showmarks to not include the various brace marks (),{}, etc +let g:showmarks_include = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXY" diff --git a/SpaceVim.d/autoload/smart_jump_to_tag.vim b/SpaceVim.d/autoload/smart_jump_to_tag.vim new file mode 100644 index 0000000..e0609c9 --- /dev/null +++ b/SpaceVim.d/autoload/smart_jump_to_tag.vim @@ -0,0 +1,6 @@ +" hit ,f to find the definition of the current class +" this uses ctags. the standard way to get this is Ctrl-] +nnoremap ,f + +" use ,F to jump to tag in a vertical split +nnoremap ,F :let word=expand(""):vsp:wincmd w:exec("tag ". word) diff --git a/SpaceVim.d/autoload/sneak.vim b/SpaceVim.d/autoload/sneak.vim new file mode 100644 index 0000000..7e634c2 --- /dev/null +++ b/SpaceVim.d/autoload/sneak.vim @@ -0,0 +1 @@ +nmap SneakForward diff --git a/SpaceVim.d/autoload/surround.vim b/SpaceVim.d/autoload/surround.vim new file mode 100644 index 0000000..1a0800b --- /dev/null +++ b/SpaceVim.d/autoload/surround.vim @@ -0,0 +1,12 @@ +" via: http://whynotwiki.com/Vim +" Ruby +" Use v or # to get a variable interpolation (inside of a string)} +" ysiw# Wrap the token under the cursor in #{} +" v...s# Wrap the selection in #{} +let g:surround_113 = "#{\r}" " v +let g:surround_35 = "#{\r}" " # + +" Select text in an ERb file with visual mode and then press s- or s= +" Or yss- to do entire line. +let g:surround_45 = "<% \r %>" " - +let g:surround_61 = "<%= \r %>" " = diff --git a/SpaceVim.d/autoload/syntastic.vim b/SpaceVim.d/autoload/syntastic.vim new file mode 100644 index 0000000..b9353b9 --- /dev/null +++ b/SpaceVim.d/autoload/syntastic.vim @@ -0,0 +1,35 @@ +set statusline+=%#warningmsg# +set statusline+=%{SyntasticStatuslineFlag()} +set statusline+=%* + +let g:syntastic_aggregate_errors = 1 +let g:syntastic_always_populate_loc_list = 0 +let g:syntastic_auto_jump=0 "automatically jump to the error when saving the file +let g:syntastic_auto_loc_list=1 "show the error list automatically +let g:syntastic_check_on_open = 1 +let g:syntastic_check_on_wq = 0 +let g:syntastic_enable_signs=1 "mark syntax errors with :signs +let g:syntastic_quiet_messages = {'level': 'warnings'} "don't care about warnings + +" Default to eslint. If you need jshint, you can override this in +" ~/.vimrc.after +let g:syntastic_javascript_checkers = ['eslint'] +let g:syntastic_python_checkers = ['flake8'] +let g:syntastic_python_flake8_args='--ignore=F401,F403,F405,W0401,E501' +let g:syntastic_python_pylint_post_args="--max-line-length=160" +let g:syntastic_go_checkers = ['go', 'golint', 'errcheck'] + +" I have no idea why this is not working, as it used to +" be a part of syntastic code but was apparently removed +" This will make syntastic find the correct ruby specified by mri +function! s:FindRubyExec() + if executable("rvm") + return system("rvm tools identifier") + endif + + return "ruby" +endfunction + +if !exists("g:syntastic_ruby_exec") + let g:syntastic_ruby_exec = s:FindRubyExec() +endif diff --git a/SpaceVim.d/autoload/tComment.vim b/SpaceVim.d/autoload/tComment.vim new file mode 100644 index 0000000..ddfd078 --- /dev/null +++ b/SpaceVim.d/autoload/tComment.vim @@ -0,0 +1,8 @@ +" tComment +" ======================================== +" extensions for tComment plugin. Normally +" tComment maps 'gcc' to comment current line +" this adds 'gcp' comment current paragraph (block) +" using tComment's built in p mapping +nmap gcp p + diff --git a/SpaceVim.d/autoload/tagbar.vim b/SpaceVim.d/autoload/tagbar.vim new file mode 100644 index 0000000..85e564b --- /dev/null +++ b/SpaceVim.d/autoload/tagbar.vim @@ -0,0 +1 @@ +nmap :TagbarToggle diff --git a/SpaceVim.d/autoload/tidy.vim b/SpaceVim.d/autoload/tidy.vim new file mode 100644 index 0000000..360a0d0 --- /dev/null +++ b/SpaceVim.d/autoload/tidy.vim @@ -0,0 +1 @@ +:vmap ,gt :!tidy -q -i --show-errors 0 diff --git a/SpaceVim.d/autoload/ultisnips.vim b/SpaceVim.d/autoload/ultisnips.vim new file mode 100644 index 0000000..2e3769d --- /dev/null +++ b/SpaceVim.d/autoload/ultisnips.vim @@ -0,0 +1,6 @@ +let g:UltiSnipsExpandTrigger="" +let g:UltiSnipsJumpForwardTrigger="" +let g:UltiSnipsJumpBackwardTrigger="" +" If you want :UltiSnipsEdit to split your window. +let g:UltiSnipsEditSplit="vertical" +nmap ue :UltiSnipsEdit diff --git a/SpaceVim.d/autoload/unimpaired.vim b/SpaceVim.d/autoload/unimpaired.vim new file mode 100644 index 0000000..f0cca4a --- /dev/null +++ b/SpaceVim.d/autoload/unimpaired.vim @@ -0,0 +1,10 @@ +" https://github.com/carlhuda/janus/blob/master/vimrc + +" Unimpaired configuration +" Bubble single lines +nmap [e +nmap ]e + +" Bubble multiple lines +vmap [egv +vmap ]egv diff --git a/SpaceVim.d/autoload/vim-fugitive.vim b/SpaceVim.d/autoload/vim-fugitive.vim new file mode 100644 index 0000000..0e71dac --- /dev/null +++ b/SpaceVim.d/autoload/vim-fugitive.vim @@ -0,0 +1,14 @@ +" The tree buffer makes it easy to drill down through the directories of your +" git repository, but it’s not obvious how you could go up a level to the +" parent directory. Here’s a mapping of .. to the above command, but +" only for buffers containing a git blob or tree +autocmd User fugitive + \ if get(b:, 'fugitive_type', '') =~# '^\%(tree\|blob\)$' | + \ nnoremap .. :edit %:h | + \ endif + +" Every time you open a git object using fugitive it creates a new buffer. +" This means that your buffer listing can quickly become swamped with +" fugitive buffers. This prevents this from becomming an issue: + +autocmd BufReadPost fugitive://* set bufhidden=delete diff --git a/SpaceVim.d/autoload/vim-gitgutter.vim b/SpaceVim.d/autoload/vim-gitgutter.vim new file mode 100644 index 0000000..5d6d58b --- /dev/null +++ b/SpaceVim.d/autoload/vim-gitgutter.vim @@ -0,0 +1,4 @@ +nmap hn GitGutterNextHunk +nmap hp GitGutterPrevHunk +nmap ha GitGutterStageHunk +nmap hr GitGutterUndoHunk diff --git a/SpaceVim.d/autoload/vim-indent-guides.vim b/SpaceVim.d/autoload/vim-indent-guides.vim new file mode 100644 index 0000000..79473f8 --- /dev/null +++ b/SpaceVim.d/autoload/vim-indent-guides.vim @@ -0,0 +1,3 @@ +let g:indent_guides_auto_colors = 1 +let g:indent_guides_start_level = 2 +let g:indent_guides_guide_size = 1 diff --git a/SpaceVim.d/autoload/vim-multiple-cursors.vim b/SpaceVim.d/autoload/vim-multiple-cursors.vim new file mode 100644 index 0000000..aeb01ee --- /dev/null +++ b/SpaceVim.d/autoload/vim-multiple-cursors.vim @@ -0,0 +1,13 @@ +" Turn off default key mappings +let g:multi_cursor_use_default_mapping=0 + +" Switch to multicursor mode with ,mc +let g:multi_cursor_start_key=',mc' + +" Ctrl-n, Ctrl-p, Ctrl-x, and are mapped in the special multicursor +" mode once you've added at least one virtual cursor to the buffer +let g:multi_cursor_next_key='' +let g:multi_cursor_prev_key='' +let g:multi_cursor_skip_key='' +let g:multi_cursor_quit_key='' + diff --git a/SpaceVim.d/autoload/vim-session.vim b/SpaceVim.d/autoload/vim-session.vim new file mode 100644 index 0000000..aed4bc0 --- /dev/null +++ b/SpaceVim.d/autoload/vim-session.vim @@ -0,0 +1,4 @@ +" Prevent vim-session from asking us to load the session. +" If you want to load the session, use :SaveSession and :OpenSession +let g:session_autosave = 'no' +let g:session_autoload = 'no' diff --git a/SpaceVim.d/autoload/vim-tmux-navigator.vim b/SpaceVim.d/autoload/vim-tmux-navigator.vim new file mode 100644 index 0000000..ead6707 --- /dev/null +++ b/SpaceVim.d/autoload/vim-tmux-navigator.vim @@ -0,0 +1,10 @@ +" Don't allow any default key-mappings. +let g:tmux_navigator_no_mappings = 1 + +" Re-enable tmux_navigator.vim default bindings, minus . +" conflicts with NERDTree "current file". + +nnoremap :TmuxNavigateLeft +nnoremap :TmuxNavigateDown +nnoremap :TmuxNavigateUp +nnoremap :TmuxNavigateRight diff --git a/SpaceVim.d/autoload/yadr-appearance.vim b/SpaceVim.d/autoload/yadr-appearance.vim new file mode 100644 index 0000000..bbca3a9 --- /dev/null +++ b/SpaceVim.d/autoload/yadr-appearance.vim @@ -0,0 +1,33 @@ +" Make it beautiful - colors and fonts + +if has("gui_running") + "tell the term has 256 colors + set t_Co=256 + set guioptions-=T + set guioptions-=e + + " Show tab number (useful for Cmd-1, Cmd-2.. mapping) + " For some reason this doesn't work as a regular set command, + " (the numbers don't show up) so I made it a VimEnter event + autocmd VimEnter * set guitablabel=%N:\ %t\ %M + + set lines=60 + set columns=190 + + if has("gui_gtk2") + set guifont=Inconsolata\ XL\ 12,Inconsolata\ 15,Monaco\ 12 + else + set guifont=Inconsolata\ XL:h17,Inconsolata:h20,Monaco:h17 + end +else + let g:CSApprox_loaded = 1 + + " For people using a terminal that is not Solarized + if exists("g:yadr_using_unsolarized_terminal") + let g:solarized_termcolors=256 + let g:solarized_termtrans=1 + end +endif + +colorscheme solarized +set background=dark diff --git a/SpaceVim.d/autoload/yadr-guioptions.vim b/SpaceVim.d/autoload/yadr-guioptions.vim new file mode 100644 index 0000000..28a8617 --- /dev/null +++ b/SpaceVim.d/autoload/yadr-guioptions.vim @@ -0,0 +1,6 @@ +" Disable the scrollbars (NERDTree) +set guioptions-=r +set guioptions-=L + +" Disable the macvim toolbar +set guioptions-=T diff --git a/SpaceVim.d/autoload/yadr-keymap-linux.vim b/SpaceVim.d/autoload/yadr-keymap-linux.vim new file mode 100644 index 0000000..3205b09 --- /dev/null +++ b/SpaceVim.d/autoload/yadr-keymap-linux.vim @@ -0,0 +1,75 @@ +" ======================================== +" Linux specific General vim sanity improvements +" ======================================== +" +" ======================================== +" RSI Prevention - keyboard remaps +" ======================================== +" Certain things we do every day as programmers stress +" out our hands. For example, typing underscores and +" dashes are very common, and in position that require +" a lot of hand movement. Vim to the rescue +" +" Now using the middle finger of either hand you can type +" underscores with Alt-k or Alt-d, and add Shift +" to type dashes +imap _ +imap _ +imap - +imap - + +" Change inside various enclosures with Alt-" and Alt-' +" The f makes it find the enclosure so you don't have +" to be standing inside it +nnoremap f'ci' +nnoremap f"ci" +nnoremap f(ci( +nnoremap f)ci) +nnoremap f[ci[ +nnoremap f]ci] + +" ==== NERD tree +" Alt-Shift-N for nerd tree +nmap :NERDTreeToggle + +" move up/down quickly by using Alt-j, Alt-k +" which will move us around by functions +nnoremap } +nnoremap { +autocmd FileType ruby map ]m +autocmd FileType ruby map [m +autocmd FileType rspec map } +autocmd FileType rspec map { +autocmd FileType javascript map } +autocmd FileType javascript map { + +" Command-/ to toggle comments +map :TComment +imap :TCommenti + +" Use Alt- numbers to pick the tab you want +map :tabn 1 +map :tabn 2 +map :tabn 3 +map :tabn 4 +map :tabn 5 +map :tabn 6 +map :tabn 7 +map :tabn 8 +map :tabn 9 + +" Resize windows with arrow keys +nnoremap + +nnoremap - +nnoremap < +nnoremap > + +" ============================ +" Tabularize - alignment +" ============================ +" Hit Alt-Shift-A then type a character you want to align by +nmap :Tabularize / +vmap :Tabularize / + +" Source current file Alt-% (good for vim development) +map :so % diff --git a/SpaceVim.d/autoload/yadr-keymap-mac.vim b/SpaceVim.d/autoload/yadr-keymap-mac.vim new file mode 100644 index 0000000..a351a4a --- /dev/null +++ b/SpaceVim.d/autoload/yadr-keymap-mac.vim @@ -0,0 +1,75 @@ +" ======================================== +" Mac specific General vim sanity improvements +" ======================================== +" +" ======================================== +" RSI Prevention - keyboard remaps +" ======================================== +" Certain things we do every day as programmers stress +" out our hands. For example, typing underscores and +" dashes are very common, and in position that require +" a lot of hand movement. Vim to the rescue +" +" Now using the middle finger of either hand you can type +" underscores with apple-k or apple-d, and add Shift +" to type dashes +imap _ +imap _ +imap - +imap - + +" Change inside various enclosures with Cmd-" and Cmd-' +" The f makes it find the enclosure so you don't have +" to be standing inside it +nnoremap f'ci' +nnoremap f"ci" +nnoremap f(ci( +nnoremap f)ci) +nnoremap f[ci[ +nnoremap f]ci] + +" ==== NERD tree +" Cmd-Shift-N for nerd tree +nmap :NERDTreeToggle + +" move up/down quickly by using Cmd-j, Cmd-k +" which will move us around by functions +nnoremap } +nnoremap { +autocmd FileType ruby map ]m +autocmd FileType ruby map [m +autocmd FileType rspec map } +autocmd FileType rspec map { +autocmd FileType javascript map } +autocmd FileType javascript map { + +" Command-/ to toggle comments +map :TComment +imap :TCommenti + +" Use numbers to pick the tab you want (like iTerm) +map :tabn 1 +map :tabn 2 +map :tabn 3 +map :tabn 4 +map :tabn 5 +map :tabn 6 +map :tabn 7 +map :tabn 8 +map :tabn 9 + +" Resize windows with arrow keys +nnoremap + +nnoremap - +nnoremap < +nnoremap > + +" ============================ +" Tabularize - alignment +" ============================ +" Hit Cmd-Shift-A then type a character you want to align by +nmap :Tabularize / +vmap :Tabularize / + +" Source current file Cmd-% (good for vim development) +map :so % diff --git a/SpaceVim.d/autoload/yadr-keymap.vim b/SpaceVim.d/autoload/yadr-keymap.vim new file mode 100644 index 0000000..9be1dfb --- /dev/null +++ b/SpaceVim.d/autoload/yadr-keymap.vim @@ -0,0 +1,318 @@ +" ======================================== +" General vim sanity improvements +" ======================================== +" +" +" alias yw to yank the entire word 'yank inner word' +" even if the cursor is halfway inside the word +" FIXME: will not properly repeat when you use a dot (tie into repeat.vim) +nnoremap ,yw yiww + +" ,ow = 'overwrite word', replace a word with what's in the yank buffer +" FIXME: will not properly repeat when you use a dot (tie into repeat.vim) +nnoremap ,ow "_diwhp + +"make Y consistent with C and D +nnoremap Y y$ +function! YRRunAfterMaps() + nnoremap Y :YRYankCount 'y$' +endfunction + +" Make 0 go to the first character rather than the beginning +" of the line. When we're programming, we're almost always +" interested in working with text rather than empty space. If +" you want the traditional beginning of line, use ^ +nnoremap 0 ^ +nnoremap ^ 0 + +" ,# Surround a word with #{ruby interpolation} +map ,# ysiw# +vmap ,# c#{"} + +" ," Surround a word with "quotes" +map ," ysiw" +vmap ," c""" + +" ,' Surround a word with 'single quotes' +map ,' ysiw' +vmap ,' c'"' + +" ,) or ,( Surround a word with (parens) +" The difference is in whether a space is put in +map ,( ysiw( +map ,) ysiw) +vmap ,( c( " ) +vmap ,) c(") + +" ,[ Surround a word with [brackets] +map ,] ysiw] +map ,[ ysiw[ +vmap ,[ c[ " ] +vmap ,] c["] + +" ,{ Surround a word with {braces} +map ,} ysiw} +map ,{ ysiw{ +vmap ,} c{ " } +vmap ,{ c{"} + +map ,` ysiw` + +" gary bernhardt's hashrocket +imap => + +"Go to last edit location with ,. +nnoremap ,. '. + +"When typing a string, your quotes auto complete. Move past the quote +"while still in insert mode by hitting Ctrl-a. Example: +" +" type 'foo +" +" the first quote will autoclose so you'll get 'foo' and hitting will +" put the cursor right after the quote +imap wa + +" ==== NERD tree +" Open the project tree and expose current file in the nerdtree with Ctrl-\ +" " calls NERDTreeFind iff NERDTree is active, current window contains a modifiable file, and we're not in vimdiff +function! OpenNerdTree() + if &modifiable && strlen(expand('%')) > 0 && !&diff + NERDTreeFind + else + NERDTreeToggle + endif +endfunction +nnoremap :call OpenNerdTree() + +" ,q to toggle quickfix window (where you have stuff like Ag) +" ,oq to open it back up (rare) +nmap ,qc :cclose +nmap ,qo :copen + +"Move back and forth through previous and next buffers +"with ,z and ,x +nnoremap ,z :bp +nnoremap ,x :bn + +" ============================== +" Window/Tab/Split Manipulation +" ============================== +" Move between split windows by using the four directions H, L, K, J +" NOTE: This has moved to vim/settings/vim-tmux-navigator.vim. +" nnoremap h +" nnoremap l +" nnoremap k +" nnoremap j + +" Make gf (go to file) create the file, if not existent +nnoremap f :sp +e +nnoremap gf :tabe + +" Zoom in +map ,gz o + +" Create window splits easier. The default +" way is Ctrl-w,v and Ctrl-w,s. I remap +" this to vv and ss +nnoremap vv v +nnoremap ss s + +" create <%= foo %> erb tags using Ctrl-k in edit mode +imap <%= %>3hi + +" create <%= foo %> erb tags using Ctrl-j in edit mode +imap <% %>2hi + +" ============================ +" Shortcuts for everyday tasks +" ============================ + +" copy current filename into system clipboard - mnemonic: (c)urrent(f)ilename +" this is helpful to paste someone the path you're looking at +nnoremap ,cf :let @* = expand("%:~") +nnoremap ,cr :let @* = expand("%") +nnoremap ,cn :let @* = expand("%:t") + +"Clear current search highlight by double tapping // +nmap // :nohlsearch + +"(v)im (c)ommand - execute current line as a vim command +nmap ,vc yy:p + +"(v)im (r)eload +nmap ,vr :so % + +" Type ,hl to toggle highlighting on/off, and show current value. +noremap ,hl :set hlsearch! hlsearch? + +" These are very similar keys. Typing 'a will jump to the line in the current +" file marked with ma. However, `a will jump to the line and column marked +" with ma. It’s more useful in any case I can imagine, but it’s located way +" off in the corner of the keyboard. The best way to handle this is just to +" swap them: http://items.sjbach.com/319/configuring-vim-right +nnoremap ' ` +nnoremap ` ' + +" ============================ +" SplitJoin plugin +" ============================ +nmap sj :SplitjoinSplit +nmap sk :SplitjoinJoin + +" Get the current highlight group. Useful for then remapping the color +map ,hi :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">" . " FG:" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"fg#") + +" ,hp = html preview +map ,hp :!open -a Safari % + +"paste text in insertion mode +inoremap "+pa +"paste text in normal mode +nnoremap "+p" + +"------------------------------------------------------------------------------ +" Misc +"------------------------------------------------------------------------------ +" Toggle paste mode on and off +map pp :setlocal paste! +" copy all out of vim +nnoremap gg"+yG +" copy text in visual mode +vnoremap "+yy +" copy all inside vim +nnoremap ggyG +" edit file +nmap ev :tabedit $MYVIMRC'tzo +nmap em :tabedit makefile + +" move around compile errors +nnoremap n :cnext +nnoremap p :cprevious + +nnoremap l :redraw! +imap cb 『』 +nnoremap n :cn +nnoremap p :cp + +" Fast Saving +map w :w +imap w :w +vmap w :w + +" :W sudo saves the file +" (useful for handling the permission-denied error) +if !exists(':W') + command W w !sudo tee % > /dev/null +endif + +" Highlight current line - allows you to track cursor position more easily +set cursorline + +" map CTRL-L to piece-wise copying of the line above the current one +imap @@@hhkywjl?@@@P/@@@3s + + +" Allow to copy/paste between VIM instances +"copy the current visual selection to ~/.vbuf +vmap y :w! ~/.vbuf + +"copy the current line to the buffer file if no visual selection +vmap y :.w! ~/.vbuf + +"paste the contents of the buffer file +nmap p :r ~/.vbuf + +"------------------------------------------------------------------------------ +" Moving around, tabs, windows and buffers +"------------------------------------------------------------------------------ +" Switch between the last two files +nnoremap + +" easy way to edit reload .vimrc +nmap V :source $MYVIMRC +nmap v :vsp $MYVIMRC + +" Quickly open a buffer for scribble +map q :e ~/buffer + +" Quickly open a markdown buffer for scribble +map x :e ~/buffer.md + +" Remove the Windows ^M - when the encodings gets messed up +noremap m mmHmt:%s///ge'tzt'm + +"------------------------------------------------------------------------------ +" Spell checking +"------------------------------------------------------------------------------ + +" Pressing ,ss will toggle and untoggle spell checking +map ss :setlocal spell! + +" visual shifting (does not exit Visual mode) +vnoremap < >gv + +" Switch CWD to the directory of the open buffer +map cd :cd %:p:h:pwd + +" Treat long lines as break lines (useful when moving around in them) +map j gj +map k gk + +" Close the current buffer (w/o closing the current window) +map bd :bd + +" Close all the buffers +map bda :1,1000 bd! + +" Useful mappings for managing tabs +map tn :tabnew +map to :tabonly +map tc :tabclose +map tm :tabmove +map tj :tabnext +map tk :tabprevious + +" Let 'tl' toggle between this and the last accessed tab +let g:lasttab = 1 +nmap tl :exe "tabn ".g:lasttab +au TabLeave * let g:lasttab = tabpagenr() + +"------------------------------------------------------------------------------ +" Visual mode related +"------------------------------------------------------------------------------ + +" Visual mode pressing * or # searches for the current selection +" Super useful! From an idea by Michael Naumann +vnoremap * :call VisualSelection('f', '') +vnoremap # :call VisualSelection('b', '') + + +noremap :echo '戒黄赌毒及上下左右键!' +noremap :echo '戒黄赌毒及上下左右键!' +noremap :echo '戒黄赌毒及上下左右键!' +noremap :echo '戒黄赌毒及上下左右键!' +inoremap fn =expand("%:t") + + +function! TogglePaste() + if &paste + setlocal nopaste + else + setlocal paste + endif +endfunction + +function! ToggleRspecTest() + let l:line=getline('.') + if l:line =~? ',\s*now:\s.*true' + call setline('.', substitute(l:line, "\,\\s*now:\\s*true", "", "")) + else + call setline('.', substitute(l:line, "\\([^\\s]\\)\\s*do", "\\1, now: true do", "")) + endif +endfunction + +" set paste +nnoremap tp :call TogglePaste() +nnoremap tt :call ToggleRspecTest() diff --git a/SpaceVim.d/autoload/yadr-sudo-write.vim b/SpaceVim.d/autoload/yadr-sudo-write.vim new file mode 100644 index 0000000..7b9a67f --- /dev/null +++ b/SpaceVim.d/autoload/yadr-sudo-write.vim @@ -0,0 +1,3 @@ +" w!! to write a file as sudo +" stolen from Steve Losh +cmap w!! w !sudo tee % >/dev/null diff --git a/SpaceVim.d/autoload/yadr-whitespace-killer.vim b/SpaceVim.d/autoload/yadr-whitespace-killer.vim new file mode 100644 index 0000000..b0c2703 --- /dev/null +++ b/SpaceVim.d/autoload/yadr-whitespace-killer.vim @@ -0,0 +1,15 @@ +" via: http://rails-bestpractices.com/posts/60-remove-trailing-whitespace +" Strip trailing whitespace +function! StripTrailingWhitespaces() + " Preparation: save last search, and cursor position. + let _s=@/ + let l = line(".") + let c = col(".") + " Do the business: + %s/\s\+$//e + " Clean up: restore previous search history, and cursor position + let @/=_s + call cursor(l, c) +endfunction +command! StripTrailingWhitespaces call StripTrailingWhitespaces() +nmap ,w :StripTrailingWhitespaces diff --git a/SpaceVim.d/autoload/yadr-window-killer.vim b/SpaceVim.d/autoload/yadr-window-killer.vim new file mode 100644 index 0000000..d177e90 --- /dev/null +++ b/SpaceVim.d/autoload/yadr-window-killer.vim @@ -0,0 +1,20 @@ +" Use Q to intelligently close a window +" (if there are multiple windows into the same buffer) +" or kill the buffer entirely if it's the last window looking into that buffer +function! CloseWindowOrKillBuffer() + let number_of_windows_to_this_buffer = len(filter(range(1, winnr('$')), "winbufnr(v:val) == bufnr('%')")) + + " We should never bdelete a nerd tree + if matchstr(expand("%"), 'NERD') == 'NERD' + wincmd c + return + endif + + if number_of_windows_to_this_buffer > 1 + wincmd c + else + bdelete + endif +endfunction + +nnoremap Q :call CloseWindowOrKillBuffer() diff --git a/SpaceVim.d/autoload/yadr-wrapping.vim b/SpaceVim.d/autoload/yadr-wrapping.vim new file mode 100644 index 0000000..35d514c --- /dev/null +++ b/SpaceVim.d/autoload/yadr-wrapping.vim @@ -0,0 +1,20 @@ +" http://vimcasts.org/episodes/soft-wrapping-text/ +function! SetupWrapping() + set wrap linebreak nolist + set showbreak=… +endfunction + +" TODO: this should happen automatically for certain file types (e.g. markdown) +command! -nargs=* Wrap :call SetupWrapping() + +vmap gj +vmap gk +vmap g$ +vmap g^ +vmap g^ +nmap gj +nmap gk +nmap g$ +nmap g^ +nmap g^ + diff --git a/SpaceVim.d/autoload/yankstack.vim b/SpaceVim.d/autoload/yankstack.vim new file mode 100644 index 0000000..5fd6927 --- /dev/null +++ b/SpaceVim.d/autoload/yankstack.vim @@ -0,0 +1,2 @@ +nmap p yankstack_substitute_older_paste +nmap P yankstack_substitute_newer_paste diff --git a/SpaceVim.d/autoload/yapf.vim b/SpaceVim.d/autoload/yapf.vim new file mode 100644 index 0000000..b810d38 --- /dev/null +++ b/SpaceVim.d/autoload/yapf.vim @@ -0,0 +1 @@ +autocmd FileType python nnoremap = :0,$!yapf diff --git a/SpaceVim.d/init.toml b/SpaceVim.d/init.toml new file mode 100644 index 0000000..a980d5f --- /dev/null +++ b/SpaceVim.d/init.toml @@ -0,0 +1,78 @@ +#============================================================================= +# basic.toml --- basic configuration example for SpaceVim +# Copyright (c) 2016-2017 Wang Shidong & Contributors +# Author: Wang Shidong < wsdjeg at 163.com > +# URL: https://spacevim.org +# License: GPLv3 +#============================================================================= + +# All SpaceVim option below [option] section +[options] + # set spacevim theme. by default colorscheme layer is not loaded, + # if you want to use more colorscheme, please load the colorscheme + # layer + colorscheme = "NeoSolarized" + colorscheme_bg = "dark" + + # Disable guicolors in basic mode, many terminal do not support 24bit + # true colors + enable_guicolors = false + guifont = "SauceCodePro Nerd Font Mono:h11" + # Disable statusline separator, if you want to use other value, please + # install nerd fonts + statusline_separator = "nil" + statusline_inactive_separator = "bar" + buffer_index_type = 4 + windows_index_type = 3 + enable_tabline_filetype_icon = false + enable_statusline_mode = false + statusline_unicode_symbols = false + # Enable vim compatible mode, avoid changing origin vim key bindings + vimcompatible = true + filemanager = "nerdtree" + enable_neomake = false + enable_ale = true + bootstrap_after = "paiyou#after" + +# Enable autocomplete layer +[[layers]] +name = 'autocomplete' +auto-completion-return-key-behavior = "complete" +auto-completion-tab-key-behavior = "cycle" + +[[layers]] +name = 'shell' +default_position = 'top' +default_height = 30 + +[[layers]] +name = "lang#ruby" + +[[layers]] +name = "unite" + +[[layers]] +name = "tmux" + +[[layers]] +name = "lang#javascript" + +[[layers]] +name = "colorscheme" + +[[layers]] +name = "VersionControl" + +[[layers]] +name = "checkers" +enable_neomake = false +enable_ale = true + +[[layers]] +name = "git" + +[[layers]] +name = "lang#markdown" + +[[layers]] +name = "lang#go"