I have a simple goal: Ctrl-C map, a command that I don’t think I have ever used to remove vim, automatically insert the correct character (s) at the beginning of a line to comment on that line according to the file type of the file.
I decided that I could use the auto command to recognize the file type and set the vim variable to the correct comment character when the file is open. So I tried something like:
" Control C, which is NEVER used. Now comments out lines!
autocmd BufNewFile,BufRead *.c let CommentChar = "//"
autocmd BufNewFile,BufRead *.py let CommentChar = "
map <C-C> mwI:echo &CommentChar<Esc>`wll
This map marks my current location, goes to the beginning of the line in insert mode, echoes the comment character at this point, goes into command mode, returns to the given character and goes two characters to the right to make comments for inserted characters (subject to C style comment )
The italic part is that part with which I have problems; he is present only as the owner of the place to represent what I want to do. Can you help me figure out how to achieve this? Bonus points if you use strlen (CommentChar) to put the right number of spaces to the right! Extra bonus points for vim-master, which includes how to make block-style comments if you are in visual mode!
I'm still pretty new to vim scripts; my .vimrc is a fair 98 lines, so if you could help me by explaining any answers you provide! Thank.
source
share