You are not logged in.

#1 2011-09-04 22:46:34

dclarkson77
Member
Registered: 2011-09-04
Posts: 2

[SOLVED] Navigating text files (LaTeX) in VIm

Hi all,

I have began using vim (in the terminal) for editing my LaTeX files. Obviously as I am writing a large amount of text, and how LaTeX treats formatting, each paragraph is a single line in vim. I have figured out line wrapping no problems and amended that in my.vimrc however with each paragraph a long line I am fiing it very hard to navigate around the document. I am unable to jump between lines on the screen using "j" and "k" as it jumps to the end of the actual line, which may be 4 or 5 lines below. While I can jump a few words at a time I was hoping there was a more intuitive and quicker solution. Maybe something that displays a paragraph as multiple lines in vim but does not interfere with the actual file to prevent issues with compiling the LaTeX?

Tanks in advance,
Danny smile

Last edited by dclarkson77 (2011-09-05 12:40:36)

Offline

#2 2011-09-04 23:07:56

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] Navigating text files (LaTeX) in VIm

You want to navigate using "screen lines" - use 'gk' instead of 'k'; some sample shortcuts

noremap    <Up> gk
noremap    <Down> gj

Some general links:
http://vim.wikia.com/wiki/Move_cursor_b … n_wrapping
http://vim.runpaint.org/display/working … ong-lines/

There may be a better LaTeX-oriented way via some plugin.

Last edited by karol (2011-09-04 23:13:45)

Offline

#3 2011-09-05 01:06:08

Berticus
Member
Registered: 2008-06-11
Posts: 731

Re: [SOLVED] Navigating text files (LaTeX) in VIm

karol's got the right idea. But also, did you know that you can split a paragraph up into multiple lines? As long as there isn't a blank line, it's considered to be on the same paragraph. So typically at around column 80, I'll just create a new line. I have a line going down column 80 to indicate when I'm getting close.

Offline

#4 2011-09-05 01:15:35

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] Navigating text files (LaTeX) in VIm

Berticus wrote:

karol's got the right idea. But also, did you know that you can split a paragraph up into multiple lines? As long as there isn't a blank line, it's considered to be on the same paragraph. So typically at around column 80, I'll just create a new line. I have a line going down column 80 to indicate when I'm getting close.

You mean a general way to fold text to a certain width? Try 'fold' - it uses 80 chars by default so 'fold foo' should work.


Edit:
Sorry, I'm sleepy, now I see that wasn't really a question ;P
Still, 'fold' may be helpful so you don't have to manually cut it at 80 chars (on some old documents you weren't creating with this "rules") or hack a script to do so.

Last edited by karol (2011-09-05 01:20:58)

Offline

#5 2011-09-05 01:20:59

bohoomil
Member
Registered: 2010-09-04
Posts: 2,376
Website

Re: [SOLVED] Navigating text files (LaTeX) in VIm

Put those two options in your .vimrc, though the first one you most likely already have there:

set wrap
set linebreak

:: Registered Linux User No. 223384

:: github
:: infinality-bundle+fonts: good looking fonts made easy

Offline

#6 2011-09-05 01:24:41

Runiq
Member
From: Germany
Registered: 2008-10-29
Posts: 1,053

Re: [SOLVED] Navigating text files (LaTeX) in VIm

Berticus wrote:

karol's got the right idea. But also, did you know that you can split a paragraph up into multiple lines? As long as there isn't a blank line, it's considered to be on the same paragraph. So typically at around column 80, I'll just create a new line. I have a line going down column 80 to indicate when I'm getting close.

However---should you ever want to use version control with LaTeX, wrapping lines like this might become an issue: A one-word change that results in a re-wrap of the paragraph can mess up the diff display of your version control system. There's two ways around that: 1. Use a word-based diff such as wdiff, or 2. write one sentence per line.

Just thought I'd point that out.

Offline

#7 2011-09-05 01:56:17

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: [SOLVED] Navigating text files (LaTeX) in VIm

bohoomil wrote:

Put those two options in your .vimrc, though the first one you most likely already have there:

set wrap
set linebreak

On top of those two lines, I set this as well:

set textwidth=0

Offline

#8 2011-09-05 02:24:55

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] Navigating text files (LaTeX) in VIm

skottish wrote:

On top of those two lines, I set this as well:

set textwidth=0

To help with pasting or ...?

Offline

#9 2011-09-05 03:21:02

bohoomil
Member
Registered: 2010-09-04
Posts: 2,376
Website

Re: [SOLVED] Navigating text files (LaTeX) in VIm

karol wrote:
skottish wrote:

On top of those two lines, I set this as well:

set textwidth=0

To help with pasting or ...?

http://vim.wikia.com/wiki/Automatic_word_wrapping


:: Registered Linux User No. 223384

:: github
:: infinality-bundle+fonts: good looking fonts made easy

Offline

#10 2011-09-05 03:47:34

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] Navigating text files (LaTeX) in VIm

@bohoomil
I was asking about

'textwidth' 'tw'        number  (default 0)
                        local to buffer
                        {not in Vi}
        Maximum width of text that is being inserted.  A longer line will be
        broken after white space to get this width.  A zero value disables
        this.  'textwidth' is set to 0 when the 'paste' option is set.  When
        'textwidth' is zero, 'wrapmargin' may be used.  See also
        'formatoptions' and |ins-textwidth|.
        When 'formatexpr' is set it will be used to break the line.
        NOTE: This option is set to 0 when 'compatible' is set.

(emphasis mine)
I think I got it backwards ;P

Offline

#11 2011-09-05 12:39:20

dclarkson77
Member
Registered: 2011-09-04
Posts: 2

Re: [SOLVED] Navigating text files (LaTeX) in VIm

Hi all,

thanks for the comprehensive replies! I knew it would be a simple solution. @karol, the links are very helpful and what I am currently using at the moment (I really need to work on a few documents). @bohoomil, sounds a (maybe) simpler solution but as @Runiq points out seems there is a bit more to it. When I get a chance I will try it out and report back.

Once again thanks all for your help!

Danny big_smile

Offline

#12 2011-09-05 18:22:11

bohoomil
Member
Registered: 2010-09-04
Posts: 2,376
Website

Re: [SOLVED] Navigating text files (LaTeX) in VIm

@karol: Sorry, my receptors must have fallen asleep before I actually did. ; )


:: Registered Linux User No. 223384

:: github
:: infinality-bundle+fonts: good looking fonts made easy

Offline

#13 2011-09-05 18:33:02

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] Navigating text files (LaTeX) in VIm

bohoomil wrote:

@karol: Sorry, my receptors must have fallen asleep before I actually did. ; )

No problem. Nighty-night ;P

Offline

#14 2011-09-05 22:04:53

Mr.Elendig
#archlinux@freenode channel op
From: The intertubes
Registered: 2004-11-07
Posts: 4,092

Re: [SOLVED] Navigating text files (LaTeX) in VIm

A little sidenote:  :h text-objects , you are going to love those.


Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest

Offline

#15 2011-09-05 23:47:36

Runiq
Member
From: Germany
Registered: 2008-10-29
Posts: 1,053

Re: [SOLVED] Navigating text files (LaTeX) in VIm

Mr.Elendig wrote:

A little sidenote:  :h text-objects , you are going to love those.

This…

…is the best thing since sliced bread.

Offline

Board footer

Powered by FluxBB