You are not logged in.
I am trying to configure my .vimrc in order to enable code block comment and uncomment
by ,/ and ,<Space> combinations but it can't seem to work.
Any ideas?
I like this one cause, i can add an if for every filetype
that i want to enable this feature.
if &filetype == "vim"
map ,/ :s/^/"/<CR>
map ,<Space> :s/^"//<CR>
elseif &filetype == "c"
map ,/ :s/^/\/\//<CR>
map ,<Space> :s/^\/\///<CR>:nohlsearch<CR>
elseif &filetype == "cpp"
map ,/ :s/^/\/\//<CR>
map ,<Space> :s/^\/\///<CR>:nohlsearch<CR>
endif
Last edited by arkara (2010-07-23 16:20:09)
Offline
There are plugins like nerdcommenter that help w/ such tasks.
http://aur.archlinux.org/packages.php?ID=27698
Offline
Awesome. But is there a way to change the mappings?
Offline
i've got a function from rson's vimrc that works great. it toggles comments on/off of a visual block. you can define start and end comment strings ('//' and '' or '<!--' and '-->' for example) globally or by filetype.
here's some snippets:
" default comment symbol
let g:StartComment="#"
let g:EndComment=""
" example of changing it for a filetype
au FileType c,cpp let g:StartComment = "//"
" call the function on ,c (my local leader is ',')
vmap <LocalLeader>c :call CommentLines()<CR>
" and the function itself
function! CommentLines()
try
execute ":s@^".g:StartComment."@\@g"
execute ":s@".g:EndComment."$@@g"
catch
execute ":s@^@".g:StartComment."@g"
execute ":s@$@".g:EndComment."@g"
endtry
endfunction
//github/
Offline
Block insert works for me. ^V to select a column and I to insert, in this case a comment character.
Offline
Block insert works for me. ^V to select a column and I to insert, in this case a comment character.
shit, never knew that (X to remove, in this case a comment character, too). epically useful in general, thanks.
//github/
Offline
egan wrote:Block insert works for me. ^V to select a column and I to insert, in this case a comment character.
shit, never knew that (X to remove, in this case a comment character, too). epically useful in general, thanks.
One more solution:
X command is ok to remove properly lined up comment character columns.
To insert multiple comment characters I use the substitution command. E.g. select a visual block of lines to comment (V command), then insert the comment characters by "substituting" the beginning of those lines:
:'<,'>s#^#// #
Or for standard C comments repeat this for the end of line as well with this comment sequence:
:'<,'>s#^#/* #
gv
:'<,'>s#$# */#
Certainly you can remove this by backward substitution over the same visual selection:
:'<,'>s#/\* ##
gv
:'<,'>s# \*/##
Which is useful if the comment characters happen to be not properly lined up.
To know or not to know ...
... the questions remain forever.
Offline
Or use emacs, just highlight the lines you want and press M-;
Last edited by moljac024 (2010-07-24 09:16:53)
The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...
Offline
Or use emacs, just highlight the lines you want and press M-;
SACRILEGE!!!
This is a vim only topic.
(But if I'm on emacs, I certainly use this feature...)
To know or not to know ...
... the questions remain forever.
Offline
egan wrote:Block insert works for me. ^V to select a column and I to insert, in this case a comment character.
shit, never knew that (X to remove, in this case a comment character, too). epically useful in general, thanks.
You obviously didn't see my first post about comments
archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson
Offline