1

I work in two broadly different ways in vim (that are relevant to this question):

  1. I am writing text or markdown-formatted content, writing paragraphs of text. In this case I am generally writing new content, so it is most elegant for sidescrolloff to be set to 0, otherwise the window content jumps left when I near the end of a line.

  2. I am editing existing programming code (e.g. python), which may have line lengths longer than it 'should' have (e.g. longer than textwidth). In this case I don't want to reformat those lines - I want to work with them at the length they are. In this case it is more elegant if sidescrolloff is, for example, 20, so that when my cursor gets nearer the end of the window/line on the right I can see the text to the right more clearly.

Is there an elegant way to set the value of sidescrolloff differently depending if I am appending at the end of a line versus in the middle of it (i.e. the middle of the content)? Or perhaps a way to set it depending if I am in insert mode or normal mode?

Alternatively, are there any other elegant solutions to my problem?

In both these cases I use textwidth=78 and nowrap.

  • Have you looked into using modelines or filetypes? – PhilippFrank Mar 23 '15 at 12:09
2

The 'sidescrolloff' option so far is a global option; i.e. it can have only one fixed value. However, you can use :autocmds to dynamically switch its value based on the current buffer's filetype (Markdown vs. Python), or syntax (inside comments vs. inside code (can use my OnSyntaxChange plugin for that)), or use the CursorMoved[I] events (for inserting in the middle vs. end).

  • thanks for the response, sorry for the slow reply. If I went for the lo-fi autocmd approach, i.e. autocmd FileType markdown set sidescrolloff=0, doesn't that require me to then create a corresponding autocmd for every other filetype I use (since it's a global option). Is there a way to create an autocmd that only applies for files that are not type XYZ? – Andrew Ferrier Apr 30 '15 at 21:51
  • 1
    Yes, you can do that with a global autocmd and a conditional: autocmd FileType * if &filetype != 'markdown' | set sidescrolloff=3 | endif; I would then combine this with the other (positive) one via else. – Ingo Karkat May 1 '15 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.