tags:

views:

477

answers:

2

Hi,

Im facing some problems, I looked around in the forum and didnt find any solutions discussed. Im sorry if these have been resolved earlier.

  • Is there someway I can make the VIM line break after 80 characters. I dont want the text to wrap around but create a new line. And I wish it would break off the complete last word. So instead of fo in the previous and o in the next line, can it break with foo in the next line?

  • When I end my comment and press enter, I get a # in the new line. This is cool but when I delete # and want to start a line of code, I dont get syntax highlighting there. It still thinks what Im typing is a comment. Is this a bug or am I doing it wrong?

  • One more thing is that I have set the shiftwidth to 4. But when I press Ctrl+S to save the document, the cursor jumps to the beginning of the sentence. I then need to manually go back to my original position to begin the code. Is there a way I can resolve this?

Thank you for reading this. I am new to Ruby and Vim. I hope you guys help me out.

+5  A: 

Ctrl-S ? This is not known to me. In Vim/Gvim, a file is usually saved by

:w filename.ext (if none's been given yet)

or

:saveas filename.ext

(for all of these commands try ":help :w" or ... the same principle).

I don't know about the comment part, since I don't do Ruby, but it would be pretty wise for you to get yourself a nice commenter plugin (I think I use LineCommenter) - eases up on the commenting. Just write the comment, and add the #'s later (set it to work in normal and in visual mode; it works beautifully).

As for the breaking the text part, that could be solved by adding

:set tw=80
ldigas
maybe CTRL-S is a gvim thing?
rampion
The problem with :set tw=80 method is that the line breaks only after the white space. This will leave the previous word, which exceeds the width limit in place. Is there a way to break the word itself?
kunjaan
No. I use GVim, and there's no such key. It's probably something mapped.
ldigas
@kunjaan - I don't understand what you want exactly. In your question, you said you didn't want "foo" broken. textwidth gives you that, it will move the complete word to the next line.
ldigas
gvim on windoze has the <C-S> mapped in mswin.vim by default, sourced from vimrc. Thank God we can customize :)
dr Hannibal Lecter
dr Hannibal Lecter - yes, it is there but it is not sourced by default.
ldigas
+2  A: 

"wrapscan" is the vim feature that wraps a whole word to the next line; it might not be set by default in your configuration - probably isn't. So in addition to :set tw=78 you probably want to try one of these:

:set wrapscan
:set wrap     <- just a shorter version
:set nowrap   <- to turn the wordwrap feature back off

Incidentally, rather than seting the text width (tw) to some number of characters (smaller than your window), you could instead set the margin you want to leave on the right side of the window like so:

:set wrapmargin=1

If wrapmargin is set to something other than 0, textwidth should be ignored.

I would use ":w" to save and continue editing (or ":w filename" if it's a new file) and "ZZ" or ":wq" to save-and-exit when you're done - none of those will move the cursor position.

I'm not sure where your "#" continuation is coming from, but I'd also make sure to set these if they aren't already (you can check what variables are set by just typing ":set" with no other options):

:set syntax=ruby
:set filetype=ruby
:syntax enable

If you started with an empty document and then added "#!/usr/bin/ruby" to it, vim won't notice you're editing ruby until you save&exit and reopen the file. There are other cases where syntax coloring isn't very bright or needs a nudge but yes, that sounds like a bug to me.

glenra