2

One of the features I miss in Visual Studio is the ability to hop over closing parenthesis, brackets, single-quotes and double-quotes with tab
Does anyone know of a script to do such a thing?

Pseudo Code:

If character to the right of cursor == ')' or '}' or '\'' or '"'
    Move cursor over one space.
Else
    indent-line/autocomplete/etc.
3

This answer depends on the bind-key.el file in Wiegley's use-package.

Probably a cleaner way to do this, but this should work for your purposes. You say you want the cursor to "hop" over the delimiters, but also say the cursor should move over one space. I assumed you meant 2 spaces. Remove the first (forward-char 1).

(defun special-tab ()
 "Wrapper for tab key invocation. 

  If point is just before a close delimiter, skip forward until 
  there is no closed delimiter in front of point. Otherwise, invoke 
  normal tab command for current mode.

  Must be bound to <tab> using bind-key* macro from bind-key package.

  Note, this function will not be called if `override-global-mode' is
  turned off."
  (interactive)
  (defun next-char-delims (delims)
    (let ((char (and (not (equal (point) (point-max)))
                     (string (char-after (point))))))
      (when char (member char delims))))
  (let ((open '("'" "\"" ")" "]")))
    (if (next-char-delims open)
        (progn (forward-char 1)
               (while (next-char-delims open)
                 (forward-char 1)))
      (call-interactively (key-binding (kbd "TAB"))))))

(if (macrop 'bind-key*)        
    (bind-key* (kbd "<tab>") 'special-tab)
  (user-error "Must have bind-key from use-package.el to use special-tab function."))
  • Comments are not for extended discussion; this conversation has been moved to chat. – Dan Jan 31 '18 at 10:29

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.