PropertyValue
rdfs:label
  • Smart home
rdfs:comment
  • A smart home is
  • The following lines (in your vimrc) implement smart home for normal, visual, operator pending, and insert modes. noremap col('.') == match(getline('.'),'\S')+1 ? '0' : '^' imap The first line is an expression mapping for normal, visual, and operator pending modes. The right-hand side of the mapping is an expression that is evaluated each time Home is pressed. The expression gives a string, and the result is as if the characters in the string had been pressed. The expression compares col('.') (the cursor column position, where 1 is the first column) and match(getline('.'),'\S')+1 (the index of the first non-whitespace character in the current line; 1 is added because the index starts at 0). If both sides of "==" are equal, the result is '0' (move to start of line); otherwise it is '^'
Version
  • 7
dcterms:subject
dbkwik:vim/property/wikiPageUsesTemplate
Previous
  • 313
Category
  • Moving
dbkwik:itlaw/property/wikiPageUsesTemplate
Complexity
  • advanced
Created
  • 2002
ID
  • 315
NEXT
  • 316
Rating
  • 35
abstract
  • A smart home is
  • The following lines (in your vimrc) implement smart home for normal, visual, operator pending, and insert modes. noremap col('.') == match(getline('.'),'\S')+1 ? '0' : '^' imap The first line is an expression mapping for normal, visual, and operator pending modes. The right-hand side of the mapping is an expression that is evaluated each time Home is pressed. The expression gives a string, and the result is as if the characters in the string had been pressed. The expression compares col('.') (the cursor column position, where 1 is the first column) and match(getline('.'),'\S')+1 (the index of the first non-whitespace character in the current line; 1 is added because the index starts at 0). If both sides of "==" are equal, the result is '0' (move to start of line); otherwise it is '^' (move to first nonblank character). In insert mode, the second line applies and if Home is pressed the result is Ctrl-O followed by Home. In insert mode, pressing Ctrl-O executes what follows as a normal-mode command, so the Home which follows invokes the normal mode mapping. The simple mappings have two deficiencies: * If there are no non-whitespace characters, match() returns −1 which becomes 0 after adding 1, and that value never equals the result from col('.'). Therefore the mapping always performs ^. * The mapping does not account for the case where the 'wrap' option is on and long lines are wrapped. In that case, pressing Home will jump to the first nonblank character or the start of the line, whereas moving to the start of the screen line may be wanted.