开发者

why can't I comment lines in visual mode

I want to comment several lines in my .vimrc, the usual way I do it is :x,ys/^/"/ and x stands for the start line number and y stands for the line number of the last line. I read some post which said in visual mode this task can be done by the following step:

1 Select your lines with VISUAL BLOCK

2 press I to insert before all highlighted lines.

3 type your comment charact , in this case should be "

4 then ESC

I fllowed the above steps and met met problems in step 2 . the thing开发者_运维问答 is when I select the lines in Visual mode and press I , vim ( I use version7.2) go back to insert mode and the cursor back to the start of the first line. so if you continue to do the step 3 and step 4, you end up in just inserting " at the start the first line , far from what I want to achieve.

so could you point out what's wrong with the recipe ? thanks in advance


dammit, it's my fault . The recipe is absolutely right, If I'm patient enough to enter ESC in step 4, I see what I. want to see......


Select the block in visual mode, and then use :s/^/"/. When you press :, vim will automatically start the command with :'<,'> which indicates the effective range is the marked visual block.

Actually, your proposed sequence works also, as long as you use visual block mode, started with CtrlV (that is, vim should display -- VISUAL BLOCK -- on the status line).


I find this plugin very helpful with pretty much all of my commenting needs. http://www.vim.org/scripts/script.php?script_id=1218

Favorites... (work both in visual and normal mode)

Toggle comment.

,c<SPACE>

Yank selected lines before commenting them out. (can then paste with p)

,cy

Toggle lines individually.

,ci

Supports a great number of file types and comes with documentation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜