Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [motion]

is for moving the cursor around the buffer. Emacs provides key-bindings for alternative ways of moving the cursor interactively: by syntactical elements such as characters and words; by forward and backward searches; by arbitrary lines; by units such as sentences, paragraphs, and s-expressions; and by other methods unique to certain modes.

Filter by
Sorted by
Tagged with
19 votes
5 answers
5k views

Stop at beginning of a word on `forward-word`

I often use multiple invocations of forward-word followed by a single backward-word to move point to the beginning of a word on a line. I guess I never got used to the way forward-word differs from ...
user avatar
15 votes
4 answers
7k views

Emacs point(cursor) movement lag

When running previous-line, C-p or <up> the cursor jumps up a line without any issues or lags. When running next-line, C-n or <down> the cursor properly jumps down a line, but with a ...
Damian Chrzanowski's user avatar
15 votes
3 answers
904 views

Navigate by indentation

I want to navigate between the lines of a file based on indentation. The file is structured by indentation: a line that's more indented than the previous line is a child of the previous line, a line ...
Gilles 'SO- stop being evil''s user avatar
14 votes
1 answer
7k views

Find position in file by character number

When an error occur in compiling a program in Ghostscript, the error message gives a "Current file position is ..." with a number. I use emacs to edit the program file, so I would like to be able ...
Harry Weston's user avatar
13 votes
1 answer
355 views

Why doesn't M-v following C-v move cursor back to the original position?

M-v following C-v doesn't move the cursor back to the original position. Why is that? Can we make it happen?
Tim's user avatar
  • 5,027
12 votes
2 answers
678 views

How to handle next-line in keyboard macro?

I created a keyboard macro to join lines in a buffer using: F3 C-n M-x join-line RET F4. It works fine, except when lines get too long and start to wrap – which makes this macro dependent on the ...
Sébastien Le Callonnec's user avatar
10 votes
3 answers
2k views

How to persistently move the cursor in a buffer other than the current one?

NB: The post How to move point to the end of another buffer, using `with-current-buffer` and `goto-char`? presumably asks the same question as this one, but the answers given to it do not readily ...
kjo's user avatar
  • 3,247
10 votes
3 answers
1k views

How to jump to matching (double or single) quote of a quoted string?

When cursor on one quote symbol, how to jump to the pairing quote?
AhLeung's user avatar
  • 1,083
9 votes
3 answers
926 views

Keep moving to the end of lines

The default of key binding C-a/C-e is only for one thing, move to the beginning/end of the line, is there any package that can make Emacs act like this: If I'm not at the end of a line, C-e will go ...
CodyChan's user avatar
  • 2,649
7 votes
2 answers
1k views

Move cursor to beginning of visible text in current buffer

Is there a shortcut key combination for moving the cursor to the beginning, resp. end, of the visible text in the current buffer, i.e. to the first, resp. last, cursor position that can be seen on the ...
Evan Aad's user avatar
  • 1,551
6 votes
2 answers
577 views

org: move point to beginning of an item

When in org-mode, how to move point to the beginning of the current item? (in similar fashion like back-to-indentation) Example: Imagine following org buffer content * headline - [ ] Z this is an ...
jue's user avatar
  • 4,576
6 votes
1 answer
1k views

What is the correct way skip to prev/next method/function definition?

I do not want an answer about something like Imenu or tags - features that suppose you know some keywords about the method/function name to move to. What I want is just general commands which jump ...
zw963's user avatar
  • 161
6 votes
1 answer
641 views

backword-sentence and forward-sentence are moving over paragraphs

I use markdown-mode to edit markdown, but it's missing one very useful feature. Whenever I press M-a (backward-sentence) or M-e (forward-sentence) it takes me to the start or end of the paragraph, ...
Cristian's user avatar
  • 233
6 votes
2 answers
726 views

Is there an emacs command to go to end of code line (before line comment and whitespaces start)

say you have that: stuff indented stuff # commented stuff We already got move-beginning-of-line and back-to-indentation for the left side. Now, for the right side... I'd love to know if you ...
v.oddou's user avatar
  • 163
6 votes
1 answer
429 views

How does previous-line/next-line "know" the column it should move to from the end of the line

When I am on a long line, beyond the end of an adjacent line, if I move up or down to the other line the point will go to end of the line, naturally. Then when I move back to the longer line, it goes ...
Random832's user avatar
  • 578
6 votes
3 answers
639 views

In shift selection, retain the mark if it's already active

Under shift-select-mode, cursor keys behave like many other text editing environments: Shift+motion starts selecting (sets and activates the mark, in Emacs terms), and motion without Shift stops ...
Gilles 'SO- stop being evil''s user avatar
6 votes
1 answer
280 views

Point motion strategy for Emacs 25 and older

I've read What is inhibit-point-motion-hooks?. Assume some minor-mode my-mode that wants to do point-motion-y things. Assume my--point-entered and my--point-left functions that work fine in Emacs &...
Greg Hendershott's user avatar
5 votes
1 answer
2k views

How to move by whole line rather than within a wrapped line (emacs 23.1+)

I think this is mostly just a question of how to word the question... Prior to emacs 23.1, when pressing down-arrow or up-arrow the cursor would move up a whole line at a time even when that line was ...
ericx's user avatar
  • 283
5 votes
2 answers
248 views

Move cursor left/right while entering isearch

How can I move my cursor left and right while entering my isearch text? isearch-forward Enter some text Press cursor left to edit the search text Argh! Emacs returns the cursor to the main buffer. ...
forthrin's user avatar
  • 451
5 votes
1 answer
1k views

Is there a hook I can use to run my function when point moves?

I'd like to add some navigation context to the modeline. I can figure out where I am just fine and give the name of my function, but I don't know how to run this every time point moves. post-command-...
Sean Allred's user avatar
  • 6,941
5 votes
1 answer
1k views

How to skip forward to first whitespace character?

What is the easiest way to skip forward to the first whitespace character after the current cursor? I used to do it just by searching for a space (when I knew there was one there), but now that seems ...
Dave's user avatar
  • 153
5 votes
1 answer
1k views

How to jump up or down to first non-whitespace character in same column

I use evil-mode with Emacs and would like to accomplish this via evil-mode, but would be fine with doing it in an Emacs-centric way too. The subject line explains it well, but here is a post in which ...
Joe's user avatar
  • 571
5 votes
2 answers
1k views

One key shortcut to jump two-ways between matching opening/closing tags in nxml mode?

Context Editing an arbitrary XML file in nxml-mode. Need Let's say I have a structure like this: <a> <b>...</b> </a> Let's say the cursor is at the <a>. I'm ...
Stéphane Gourichon's user avatar
4 votes
2 answers
2k views

Make the cursor stop at the last character of a line instead of the newline character

How to make cursor stop at the last character of a line instead of at the linefeed character? I use evil-mode. Steps to reproduce the issue: Start Emacs in shell via emacs -nw -Q. Press C-e to move ...
chen bin's user avatar
  • 4,877
4 votes
2 answers
1k views

Move to the beginning of a heading smartly in Org-mode

I just started with Org-mode today and noticed whenever I press C-a on a heading, the cursor is moved all the way to the beginning of the line instead of the first character in the heading. Like so :-...
Chakravarthy Raghunandan's user avatar
4 votes
2 answers
436 views

How to scroll to the beginning of the line in Emacs

I have buffer and I end up at 1616 column (I have one very long line, bug string). Is there a way to scroll the beginning of the line with a single commands. Is there a way to reset the buffer without ...
jcubic's user avatar
  • 743
4 votes
3 answers
1k views

Moving cursor to the middle of the line where it currently is

Is there a way to define a function that, when called, would move the cursor to the middle (or close to the middle) of the current line, similarly to how we can move it to the beginning and end of the ...
Louis15's user avatar
  • 263
4 votes
3 answers
506 views

Is is possible to treat any symbol in the buffer as word when moving around?

When I move around specifically using M-f/b, I want to treat any symbol such as ", ', ., -, _, ?, !, *... as one word, so M-f/b will move around them instead of skipping them and jump to the next/...
CodyChan's user avatar
  • 2,649
4 votes
2 answers
421 views

How to move to the end/beginning of the window/screen line?

For example, I got a small window, a long whole line is split into multiple lines, not actually split, but with one arrow at the end of each line of the window, if I use C-e or End key, this will move ...
CodyChan's user avatar
  • 2,649
4 votes
1 answer
404 views

How to change Emacs' word movement behaviour?

I want to do this on forward-word: (| shows the cursor position) Normal Behaviour: int main(int argc, char *args[]) { int a = 45|; printf|("%i", a); } What I want to do: //forward-...
shigi's user avatar
  • 41
4 votes
1 answer
295 views

Ignore tags in `org-end-of-line` and similar motions

Is there a convenient function for jumping to the last non-tag character in the line of an org-mode heading? For instance... * This is |my header :tag1:tag2: I would like a command that moves ...
Alexey Shiklomanov's user avatar
4 votes
2 answers
846 views

Move to goal-column inserting spaces if necessary

I have a bunch of lines of text and I'm trying to insert text starting at a certain column on each line. For example: 'Some text' This is ok 'Another longer text' ask Ram 'weird stuff' ...
ShreevatsaR's user avatar
4 votes
1 answer
775 views

How can I move by screen lines as quickly as forward-line?

next-line is very slow, and this is creating problems. I'll give some background then explain why. By default, linum.el treats a wrapped line as a single line, and it takes into account hidden lines ...
JCC's user avatar
  • 1,029
3 votes
3 answers
344 views

Move point inwards while counting number of nested parentheses without throwing an error

I would like to write a function that counts the number of nested parentheses while moving the cursor to the innermost bracket without throwing an error. (defun count-and-move () (interactive) ...
Sati's user avatar
  • 815
3 votes
2 answers
775 views

Emacs flickering when using before-save-hook with gofmt

I am trying to use gofmt on my go before I save it. ; Run gofmt before save (setq gofmt-command "goimports") (setq exec-path (cons "/usr/lib/go/bin" exec-path)) (add-to-list 'exec-path "/home/...
giodamelio's user avatar
3 votes
1 answer
80 views

How to calculate a point N lines from another point in elisp?

Given a point, how can I get the point N lines before/after it? Will post own answer, but I'm not sure it's optimal.
ideasman42's user avatar
  • 8,826
3 votes
2 answers
601 views

How to use a menu to jump between sections of a document?

I would like to define my own rules for what a section of a document is, then use this so I can popup a list of sections I can auto-complete or use arrow keys to jump between them. Take a simple ...
ideasman42's user avatar
  • 8,826
3 votes
1 answer
286 views

New line in cursor-intangible area and line-beginning position

I want to make the beginning of a line uneditable, which I can achieve by applying the read-only and cursor-intangible properties. But I have the problem, that line-beginning-position moves point not ...
Shmozart's user avatar
3 votes
2 answers
263 views

How to move up to the ending parenthesis of the enclosing list (if it exists)?

In paredit mode, C-M-u (paredit-backward-up) is used to move the point backward up out of the enclosing list The point is parked at the beginning parenthesis of the enclosing list. My question is: ...
tinlyx's user avatar
  • 1,364
3 votes
1 answer
187 views

What is the difference between `M-f` and `C-right`?

The documentation states the following: (forward-word &optional ARG) is bound to M-f (right-word &optional N) is bound to C-right Could there be any difference between the two? It just doesn't ...
Chanhee Jeong's user avatar
3 votes
1 answer
97 views

How to tell Occur to show the line in the top of the buffer

I usually use occur to make an index of the beginning of different things. When I jump to the occurrence, Occur shows the line in the middle of the buffer. How can I instruct occur to show the ...
onlycparra's user avatar
3 votes
1 answer
185 views

next/prev-imenu-item function

I would like to have a single shortcut to jump to the next item on the imenu of current buffer. E.g., if the current buffer is in org mode, next-imenu-item = org-next-visible-heading. Anyone did ...
AhLeung's user avatar
  • 1,083
3 votes
2 answers
921 views

How to move the cursor to the beginning/end of a shift-selected region by a left/right motion?

In most modern editors, after canceling a selection by a left/right motion, the cursor will be moved to the beginning/end of the previously-selected region correspondingly. Similarly, if we cancel a ...
AhLeung's user avatar
  • 1,083
3 votes
1 answer
1k views

How to jump multiple lines in emacs?

Suppose I want to jump x amount of lines up or down. Is there a convenient command for it?
Prikshet Sharma's user avatar
3 votes
1 answer
579 views

Moving around within xml documents?

Are there any useful functions / modes / hydras / utilities for navigating xml documents? Some features that might be nice to have: Jump to parent Jump to next child Jump to matching tag (like % in ...
Att Righ's user avatar
  • 775
3 votes
1 answer
4k views

Move cursor up or down multiple lines while preserving column

I find it convenient to move by multiple lines for quickly scrolling up/down: ;; replaces forward-sentence (global-set-key (kbd "M-e") (lambda () (interactive) (next-line 3))) ;; ...
user2445797's user avatar
3 votes
1 answer
143 views

Move point to just before end of a comment

Given that the point is right in front of a comment, how do I move it to the end of the comment, but before the comment end markers? For example: for a C++ // xxx comment, I would like to move the ...
Lindydancer's user avatar
  • 6,170
3 votes
1 answer
396 views

Make evil paragraphs behave like vim paragraphs

I have moved from vim to emacs using evil-mode. I've found that I prefer emacs (as long as I can edit text vim style), but I have one small inconvenience. I've found, mainly while writing prose, but ...
jamesmaj's user avatar
  • 341
3 votes
0 answers
79 views

Is there a way to move region with arrow keys or similar?

Say I have a function int calc(int that, int this); I want to mark int that and then move it right across words by hitting modifier arrow key (or similar) twice to get int calc(int this, int that); ...
mcp's user avatar
  • 556
3 votes
1 answer
76 views

How can I find corresponding balanced parentheses?

I have this LaTeX code: \caption{Lorem ipsum dolor sit amet: foo), bar), baz) and qux) consectetuer adipiscing elit.} I want to put a marker immediately before the first { and one immediately after ...
Onner Irotsab's user avatar