3

I know the linebreak option can be used to soft-wrap lines within vim (without inserting any newlines into the file being edited).

However, I often need to navigate over long lines that have been wrapped. I am aware that gk and gj allow moving up and down display lines, rather than real lines in the file, but I need to be able to achieve this behaviour with other motions like $ (which should go to the end of the current display line, rather than going to the real end, which may be several display lines down).

Being able to manipulate display lines with linewise-visual mode would also be extremely useful. Is there any succinct way to achieve this? I know creating mappings, such as 0 g0, $ g$ is an option, but I want this to work with all motions that deal in some way with lines, and making that many mappings would be quite inconvenient.

  • 1
    You mean mapping the non-g motions to the g ones right? Such as map j gj and map $ g$ etc. correct? There are really not many more commands that work differently when wrap is on... Which commands do you think you might be missing? – filbranden Feb 2 at 19:30
  • 1
    @filbranden as far as I can tell, actions like dd, yy do not have an equivalent. Not all motions can just be prefixed with g. There is no gy, and gd does something totally different. My problem is primarily when I want to use visual line mode to select a couple of lines (for deletion, yanking, etc), because V would select all of the "lines", rather than the current one. – myc3lium Feb 2 at 20:02
  • So dd should do what, exactly? – D. Ben Knoble Feb 3 at 0:41
  • 1
    I feel like the right solution for many of these cases is to use hooks that will split long lines when reading files and joining them back only when saving. So you see multiple lines in Vim (and you can edit line by line) but when you're done editing it's saved with long lines... I have a similar case where I should use something like that. What's the format of the file for which you'd like to use something like that? (Mine is Markdown...) – filbranden Feb 3 at 1:31
  • @filbranden I'm editing markdown files, yes. – myc3lium Feb 4 at 21:48

Your Answer

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

Browse other questions tagged or ask your own question.