Skip to content

Instantly share code, notes, and snippets.

@vpArth
Created November 16, 2014 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vpArth/20a27f4616670c32c152 to your computer and use it in GitHub Desktop.
Save vpArth/20a27f4616670c32c152 to your computer and use it in GitHub Desktop.
Vim Snippets
" Toggle comment line
" Ctrl+/
let s:comment_map = {
\ "c": '//',
\ "cpp": '//',
\ "go": '//',
\ "java": '//',
\ "javascript": '//',
\ "php": '//',
\ "python": '#',
\ "ruby": '#',
\ "vim": '"',
\ }
function! ToggleComment()
if has_key(s:comment_map, &filetype)
let comment_leader = s:comment_map[&filetype]
if getline('.') =~ '^\s*' . comment_leader . ""
execute 'silent s/^\(\s*\)' . comment_leader . '\(\s*\)/\1/'
else
execute 'silent s/^\(\s*\)/\1' . comment_leader . ' /'
endif
else
echo "Unknown filetype for commenting"
end
endfunction
nnoremap ^_ :call ToggleComment()<cr>==
" Moving lines(all modes, moves selected in visual)
" Alt+Shift+up_arrow/Alt+Shift+down_arrow
nnoremap <Esc>[1;4A :m-2<CR>==
nnoremap <Esc>[1;4B :m+<CR>==
inoremap <Esc>[1;4A <Esc>:m-2<CR>==gi
inoremap <Esc>[1;4B <Esc>:m+<CR>==gi
vnoremap <Esc>[1;4A :m '<-2<CR>gv=gv
vnoremap <Esc>[1;4B :m '>+1<CR>gv=gv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment