Questions tagged [cursor-movement]

Moving the cursor another place in the buffer.

Filter by
Sorted by
Tagged with
4
votes
1answer
960 views

How to save previous cursor position inside a function which has received a range?

I have the following code in a file: function! s:TrimWhitespace() abort range " Save cursor position, because the following substitution will move it let save_cursor = getpos('.') " ...
4
votes
1answer
29 views

Cursor Movement in y8k vs y8j [duplicate]

Why does y8j not move the cursor but y8k does move it up? What .vimrc entry would prevent yanking upwards moving the cursor?
4
votes
2answers
333 views

How do I make Vim preserve column position when moving between lines?

I'm using one of Vim distribution called SpaceVim and everything is good enough except some details. How do I make spacevim to preserve column position when moving between lines? For instance - move ...
4
votes
1answer
564 views

How to add numbered movement to the jump list?

I'm loving the fact that I can jump using relative numbers and a movement command but I always seem to find myself using the backticks to try and go back to where I was before the movement jump. I ...
4
votes
1answer
606 views

Vim forgets cursor column when I move over a line that ends with a brace in insert mode

Normally, when I use the up/down arrow keys to move between lines in insert mode (I'm using Vim wrong, I know), Vim remembers which column my cursor is in, so if I move to a line shorter than where my ...
4
votes
1answer
902 views

How to make a movement function work with delete, yank, etc

In hope of answering Using the % command on a line without a bracket I tried to write my first Vim script. My thought was to check if there was a { on the current line. If there was one I wanted % ...
4
votes
1answer
847 views

Keep Cursor In Current Position After Find-Replace

How does one keep the cursor in its place after a file-replace using :%s/find/replace/g ? I looked at restoring cursor position, but not quite what I was looking for, and I could jump back to previous ...
4
votes
1answer
86 views

Go to the last wrapped line with G

In Vim pressing G takes you to the last physical line. But, if the last line is wrapped around G puts the cursor on the first wrapped line in that last line, not the last wrapped line. So, is there ...
3
votes
3answers
2k views

Moving to the end of the last word on a line

There are commands to distinguish between the beginning of a line (0) and the beginning of the first word of the line (^), basically ignoring leading whitespace. But I can only find one way to move ...
3
votes
3answers
105 views

How to "find" or "till" a bigram?

I have to do a lot of hopping in lines. Often times I want to hop to a t in a line, and promptly press ft, only to discover that I have to do it 7 times before I can actually make it to my ...
3
votes
2answers
871 views

Move cursor to new line character

When in visual mode you can select the new line character. E.g.: The quick brown fox jumps over the lazy dog.⏎ In visual mode you can select both the period and the (invisible) carriage return, or ...
3
votes
1answer
283 views

How can a mapping have behavior dependent on the presence of a count?

I have this mapping to move by visible line when wrap is enabled nnoremap <silent> j gj nnoremap <silent> k gk But when I use a count (like 10 j), I expect to move by actual lines How ...
3
votes
1answer
1k views

How to replace a word with spaces

Suppose I have the following text: This is a test of the emergency broadcast system What I want to do is delete the word "test" and replace it with four spaces: This is a of the emergency ...
3
votes
3answers
186 views

How to go halfway into a line? Percentage navigation within a line

I know that e.g. 50% is a normal mode command to go halfway down a file, but [count]% is line-wise. How can I get to the halfway point of the line that my cursor is on?
3
votes
2answers
93 views

cmake movement plugin

I'm wondering, if there's a way to move with % in CMakeLists.txt files between foreach and endforeach, if and endif, function and endfunction, … googeling I only found plugins that allow calling ...
3
votes
1answer
80 views

Map <number><cr> to go to the line

I have the following line in my config: map <cr> G So I can type 123<cr> and go to the line 123, but I don't really want to go to the end of file if I did not type any numbers. How do I ...
3
votes
2answers
232 views

Replace text and move cursor to end of replacement in insert mode

How can I perform a search-and-replace and leave the cursor at the end of the replacement? I want to replace $...$ with \(...\) as I type in insert mode. Notice that I can't use an abbreviation, ...
3
votes
2answers
2k views

Vim navigate to next dot symbol in text

I'm trying to navigate to next dot in a file using windows version of vim: f. but it doesn't do anything as well as all other similar commands: F. d. D. What is correct way to do it?
3
votes
1answer
852 views

Go to Nth character in the file?

:goto goes to Nth byte of the file. I am looking for a way to go to Nth character. Given that Vim supports all kinds of multi-byte encodings, it would be odd if it did not exist, but I can't find one.
3
votes
1answer
60 views

Why does gUw keep cursor in same position but gUb moves it to the start of the word?

For example: if my cursor is on c in abcde and I do gUw then the result is abCDE with the cursor on C, while gUb results in ABcde with the cursor on A. Is this the expected behaviour? It seems that ...
3
votes
3answers
3k views

Control - Arrow to Skip Over Text

I am new to Vim, however I am learning to love it. As a former/current Windows user, there is one shortcut that I depend on and would like to configure in Vim. On windows I can use ctrl-arrow left ...
3
votes
1answer
316 views

Vertical motion within one column

How can one move vertically, staying in the same column (implicitly adding spaces), regardless of line lengths? (If the next line is shorter than the current, j will move the cursor to the last ...
3
votes
2answers
129 views

How to select with the same movement but on a different line

If I have the folowing file: XX:YY:ZZ foobar: some text XX:YY:ZZ foobar: some other text a text breaking the pattern XX:YY:ZZ foobar: some more text And I want to operate on the differents parts XX:...
3
votes
1answer
81 views

Using the % command in c++

The % command is quite nice, and I use it to copy/delete whole loops, functions and classes. In c++ though, you need to add a ; after your class declaration, so trying to motion over a whole class ...
3
votes
2answers
469 views

Simple keycombination to move to the last occurance of a character in a line

I am looking for a simple few key command which would move till the last occurrence of a character in the line. Is there anything already existing? The alternative is to jump to the next specified ...
3
votes
1answer
302 views

How to scroll two vertical splits at the same time?

I am not sure if it is even possible but, when I am working with vertical splits, sometimes, I want both of them to scroll up/down at the same time rather than using this combination: scroll down ...
3
votes
1answer
319 views

Keep relative cursor position after indenting with >>

Can I setup >> to keep the relative cursor position? For example, assuming the line is def fun(<cursor>): can I make >> result in def fun(<cursor>): ? Obviously, with ...
3
votes
1answer
187 views

How to get w word and b back to treat hyphens and underscores like spaces?

I currently have this in my vimrc set iskeyword+=- But when I press w or b my cursor skips over hyphens. Am I misunderstanding iskeyword? How do I get word and back commands to treat hyphens (and ...
3
votes
1answer
126 views

Register CursorMoved on certain key press and disable when move to new line

I'm trying to write a function that will highlight searches performed with the f and F keys. I currently have a solution here thanks to @filbranden, but would like to further improve it to only ...
3
votes
1answer
273 views

Moving over conceal

Is there a setting that allows you to move over concealed strings as if they were one (or even better: zero) characters? (This answer seems to suggest there's not.) As it is, any movement can land on ...
3
votes
1answer
1k views

VIM - How to select multiple lines that are not adjacent?

If you have the following text: line 1 line 2 line 3 You can hit CTRL+v on line 1 and hit j to select line 2. However, I want to select both line 1 and line 3, but not line 2. Is this possible?
3
votes
1answer
73 views

Cursor-movement after $ motion

I play the great game called VIM adventures (from which are the images bellow). The question is from the game, but is also reproducible in VIM so this is the place I ask. Assume you are in normal mode,...
3
votes
1answer
141 views

How to treat underscores as whitespace when skipping to the next word? [duplicate]

Let's consider an example where the cursor is at the beginning of the text one_two three. Underscores are treated as part of the word, so w moves right to the first letter of three. With set ...
3
votes
2answers
1k views

Vim keep last line at bottom of buffer

I need to configure Vim in such a way that it has a normal scrolloff of 3 or 5. But in such a way that it keeps the last line at the bottom of the screen. I don't want that as I scroll, the last lines ...
3
votes
1answer
451 views

How to jump to a character offset in a buffer?

Vim has the command :goto to go to a byte offset in a buffer. Is there an equivalent for a character offset? If not, is there a better way to implement it than repeatedly testing the cursor's ...
3
votes
1answer
534 views

Relative line number colouring

I have relative numbering turned on. There's no immediate way of telling which direction I want to move, however. For example, sometimes I see line number "7" and move 7j (7 lines down) when I really ...
3
votes
0answers
49 views

After a while in a session, commands to change one character change two. Why? [closed]

After vim has been open for a while (on Ubuntu in a console), I notice that commands start behaving differently. Mostly, they'll change or delete an extra character. For example: 123456 ^ cursor ...
3
votes
0answers
552 views

j and k keys not working like they should [duplicate]

I'm using gVim on my Windows 8.1 computer with a standard QWERTY keyboard, and neither the j and k keys, nor the Up and Down arrow keys let me move up and down in my text field while in normal mode. h ...
2
votes
3answers
580 views

Cursor to last edit works, last position doesn't

From How do I jump to the location of my last edit? I can press: `. to take my cursor to the position of last edit but: `` doesn't take me to the last position of my cursor, as it says it should ...
2
votes
2answers
533 views

Why does "e" move you one character before the actual end of the word?

Maybe it was discussed many times (I strongly believe), but I could not formulate my question properly. So lets imagine we have this sequence of words: foo bar baz Applying 3e will move us onto: ...
2
votes
2answers
452 views

How do I enable Bash keyboard shortcuts while in Insert mode?

I like using the Bash shortcuts while at the command line to move around and edit text. A sample of some commands from the link can be seen below: Ctrl + a Go to the beginning of the line (Home) ...
2
votes
2answers
603 views

Move to the first/last non-whitespace character of the column ("vertical W/B/E")

For instance move from (the cursor is on the letter in bold italic, in the second column) blablabla blablabla blablabla blablabla bla bla bla bLablabla l@st to blablabla blablabla blablabla ...
2
votes
2answers
704 views

Add a pipe character to the nth character of a line, which is after the end of the line

I need to annotate a text file, so I would like to add a | pipe character to the end of each line to put my annotations relatively close to the original text. Each line is up to 72 characters in ...
2
votes
1answer
1k views

Navigate to first diff in diff mode on startup?

Vim diff opens 2 files for diffing, but it doesn't navigate to the first diff section automatically on startup. Can I add something to startup script (like _vimrc) to do this?
2
votes
1answer
1k views

Move cursor among lines inside the same paragraph? [duplicate]

Inside a "logical" line (I mean a vim "paragraph" = chars sequence terminated by a LF/CR), I would like to move cursor from the phisical line where the cursor is positionated to near lines, (e.g. one ...
2
votes
2answers
47 views

Delete the content and the brackets of a level above while inside in the inner level

My cursor is at H { //foo { //bar { //cursor is Here } //bar2 } } How do I delete the outer layer of brackets while keeping the layer where my cursor is intact? End result ...
2
votes
3answers
101 views

How can I prevent Vim from centering the line under the cursor on `:edit`

Each time I want to save my work while editing a text file, I enter :write to save the file, and :edit to reload the file, with the side effect of resetting the undo/redo buffer. However, an unwanted ...
2
votes
2answers
91 views

How do I prepend text preserving camelcase

A common process for me is to have a camelCased word that I wish to prepend to. I find the vanilla method a little too cumbersome as I will describe below. What I'm wondering is if there is a better ...
2
votes
1answer
118 views

Is the current behavior of `ge` in Operator-pending mode a bug?

When motion ge is used with an operator, such as d, the operator acts not only on the current character (which is just inconvenient -- i would prefer that the current character be excluded), but also ...
2
votes
1answer
1k views

How to scroll through a really long line? [duplicate]

My web service log file has a line that's 34151 characters wide (lots of Soap XML). When wrapped it fills more than 1 screen. How can I scroll it smoothly in vim? Using navigation keys like $ and w ...