About: SmartHome and SmartEnd over wrapped lines   Sponge Permalink

An Entity of Type : owl:Thing, within Data Space : 134.155.108.49:8890 associated with source dataset(s)

This topic has been discussed before, see Smart home. The reason I am bringing this up again is because previous implementations of the Smart Home functionality have not worked well over lines that are wrapped. The implementation below works pleasingly well even when lines are wrapped, stepping through the wrapped lines by or one by one. It also solves the " for one character on a line" insert mode problem, and is Replace mode friendly.

AttributesValues
rdfs:label
  • SmartHome and SmartEnd over wrapped lines
rdfs:comment
  • This topic has been discussed before, see Smart home. The reason I am bringing this up again is because previous implementations of the Smart Home functionality have not worked well over lines that are wrapped. The implementation below works pleasingly well even when lines are wrapped, stepping through the wrapped lines by or one by one. It also solves the " for one character on a line" insert mode problem, and is Replace mode friendly.
Version
  • 6(xsd:integer)
dbkwik:vim/property/wikiPageUsesTemplate
Previous
  • 1059(xsd:integer)
Category
  • Moving
Author
  • Gerald Lai
Complexity
  • intermediate
Created
  • 2005(xsd:integer)
ID
  • 1061(xsd:integer)
NEXT
  • 1063(xsd:integer)
Rating
  • 11(xsd:integer)
abstract
  • This topic has been discussed before, see Smart home. The reason I am bringing this up again is because previous implementations of the Smart Home functionality have not worked well over lines that are wrapped. The implementation below works pleasingly well even when lines are wrapped, stepping through the wrapped lines by or one by one. It also solves the " for one character on a line" insert mode problem, and is Replace mode friendly. Of course, cursor positioning can be achieved via vanilla Vim way: using 0, ^, g0, g$, g_, etc, but it's easier and faster when two keys take care of all of the functions. Especially over wrapped lines. "place in vimrc nmap :call SmartHome("n") nmap :call SmartEnd("n") imap =SmartHome("i") imap =SmartEnd("i") vmap :call SmartHome("v") vmap :call SmartEnd("v") function SmartHome(mode) let curcol = col(".") "gravitate towards beginning for wrapped lines if curcol > indent(".") + 2 call cursor(0, curcol - 1) endif if curcol == 1 || curcol > indent(".") + 1 if &wrap normal g^ else normal ^ endif else if &wrap normal g0 else normal 0 endif endif if a:mode == "v" normal msgv`s endif return "" endfunction function SmartEnd(mode) let curcol = col(".") let lastcol = a:mode == "i" ? col("$") : col("$") - 1 "gravitate towards ending for wrapped lines if curcol < lastcol - 1 call cursor(0, curcol + 1) endif if curcol < lastcol if &wrap normal g$ else normal $ endif else normal g_ endif "correct edit mode cursor position, put after current character if a:mode == "i" call cursor(0, col(".") + 1) endif if a:mode == "v" normal msgv`s endif return "" endfunction
Alternative Linked Data Views: ODE     Raw Data in: CXML | CSV | RDF ( N-Triples N3/Turtle JSON XML ) | OData ( Atom JSON ) | Microdata ( JSON HTML) | JSON-LD    About   
This material is Open Knowledge   W3C Semantic Web Technology [RDF Data] Valid XHTML + RDFa
OpenLink Virtuoso version 07.20.3217, on Linux (x86_64-pc-linux-gnu), Standard Edition
Data on this page belongs to its respective rights holders.
Virtuoso Faceted Browser Copyright © 2009-2012 OpenLink Software