Created
November 16, 2014 15:36
-
-
Save vpArth/20a27f4616670c32c152 to your computer and use it in GitHub Desktop.
Vim Snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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>== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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