Questions tagged [cursor-movement]

Moving the cursor another place in the buffer.

Filter by
Sorted by
Tagged with
4
votes
2answers
204 views

Why after pressing $ in normal mode Vim goes to the last symbol in line, but in visual mode it goes on the /n newline symbol?

Is it possible to change that somehow? Either to make Vim go one symbol further in normal mode, or one symbol less in visual mode?
7
votes
2answers
4k views

Tag navigation using CTRL+] does not work with Non English keyboard on Windows

When using gVim on Windows 7 I cannot use ^] (CTRL+]) to jump to tags as described in the Vim documentation: <C-LeftMouse> *<C-LeftMouse>* *CTRL-]* CTRL-] Jump to ...
6
votes
2answers
292 views

Fold/Unfold on moving vertically

Currently my init.vim (neovim's equivalent to the .vimrc) sets the foldmethod to marker: set foldmethod=marker When I open a file all sections are folded and if the curser is placed in the ...
6
votes
2answers
2k views

How to quickly add content in a new line at end of file?

I often have to add stuff at the end of a file, hence I go to the last line: :$ yet this is at the beginning of the line. Often I discover myself doing: Ctrl + Arrow Right to jump by word until I ...
7
votes
2answers
765 views

Go to the next word starting with specific letter on current line

I want to have the command which is stated in the title. I looked for it in intrinsic Vim command but did not find it. I ran some tutorial online about functions in vim, The idea would be to have ...
4
votes
1answer
2k views

How to move cursor in a specific column

I know that there is already a method to move the cursor to a particular line in vim like :25 and it moves to line number 25. But can I configure vim to move to 15th column in 25th line say something ...
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?
12
votes
3answers
2k views

Mapping with motion

I'm trying to understand how can I use operator with subsequent motion inside a mapping. For example: nmap /c c{here we pending for a motion}/<C-r>"<CR> The map should do the following: ...
1
vote
1answer
886 views

Position cursor at end of line in insert mode

(This question pertains to nvi instead of vim.) To facilitate editing, I created the following mappings map! ( (?)@^[F?xi map! [ [?]@^[F?xi map! { {?}@^[F?xi so that entering ( will insert (|)@, ...
6
votes
1answer
133 views

How to keep in the undo history just one change for this command?

I want to keep in the undo history just one change for a long command such as: d0kJx. (I took the command from this answer.) This command (d0kJx) does this (The ^ is the cursor position): Before: a ...
0
votes
1answer
570 views

On Ubuntu and in tmux, vim does not react to Ctrl+Home and Ctrl+End

Outside of tmux they work well. These key combinations should move the cursor to the beginning of the document and, respectively, to the end of the document. How do I make them work? Thank you very ...
8
votes
3answers
1k views

How to delete till the end of the previous line?

An example (The ^ is the cursor position): Before: a bc def ghi j k l mn o p q rs ^ After: a bc def ghimn o p q rs ^ or at least: a bc def ghimn o p q rs ^ I know I ...
6
votes
4answers
2k views

How to change the behavior of cursor motions? (ex: go from one line to the end of the previous one)

I am relatively new to using vim. I have to admit it is a powerful tool, however it can be very frustrating if one doesn't learn how to use it. Whatever, there is one or two things that annoy me ...
8
votes
1answer
2k views

How do I get back to the previous line after moving?

I am new to Vim. My code file has 300 lines. Suppose currently the cursor is on line 254, and I used gg command the cursor turn to line 1. I want to go back to line 254 but I forget that line number. ...
2
votes
1answer
288 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
1answer
251 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 ...
11
votes
2answers
475 views

Scrolling issues when the `wrap` option is set

I find myself dealing with this issue every time the wrap option is active (in my particular case whenever I'm working with markdown files). What happens is that, while scrolling up and down the ...
5
votes
2answers
416 views

One-handed Vim utilisation

Today I found myself struggling with Vim while being on the phone. I had only one hand to move around, so the home row was fine but with small hands, every <C-x> shortcuts (<C-d>, <C-u&...
0
votes
3answers
121 views

Mapping to “bh” causes cursor to be trapped in first column

I'm looking to map Ctrl-N to lbvhe in normal mode. This should visually select the word under the cursor, and works fine unless the word is at the beginning of a line. Having investigated, I've found ...
13
votes
2answers
7k views

What is the difference between j, CTRL-J, <NL> and CTRL-N in normal mode?

I saw somewhere on the web someone using Ctrl-J and as I didn't know this mapping I looked up in the relevant doc and found the following: j or <Down> or CTRL-J or <NL>...
2
votes
1answer
426 views

Original column number in a mapped function called with a count

Here's an example: function! TestCursorPosWithCount() range echo virtcol('.') endfunction nmap <leader>c :call TestCursorPosWithCount()<CR> If I press <leader>c, the column ...
11
votes
6answers
7k views

How to delete line above/below cursor, but not current line?

Is there a command for deleting line (or n lines) above current one? Above = current not included. I.e., is there an alternative to dk which doesn't delete current line? Similar to how o/O and p/P ...
6
votes
1answer
798 views

Move cursor by percentage

I know that you can go to the Nth % percentage of a file by typing N% in normal mode. Is it possible to advance the line by a given percentage? To clarify, for an example, can I type something to ...
14
votes
1answer
4k views

Hand Placement for Vim Navigation

I'm a new Vim user, and I want to ask this somewhat elementary question in order to make sure I start learning Vim the right way and don't develop bad habits. When you use Vim, how do you position ...
9
votes
2answers
2k views

Go to X bytes from here

How can I move X bytes forward, starting from the current cursor location (including line breaks)? [count]go could be used to move forward X bytes from the start of the buffer. I tried Shift + V, G, [...
3
votes
2answers
126 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:...
5
votes
1answer
291 views

How can I advance a page without losing my column position?

I like using Ctrl-f and Ctrl-b to "page-up" and "page-down", but I was wondering if there was a way to do that without losing my current position in a row? For example, I like to work with tab-...
2
votes
1answer
909 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?
8
votes
6answers
3k views

Using vim when press both opening and closing parenthesis/brackets/etc

When I learned to program, I would press both the opening and closing brackets/etc then the left arrow key then enter the text. So to put in [hello] I would type [], and then the left arrow so that it ...
2
votes
1answer
829 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 ...
10
votes
2answers
4k views

Go to last non-whitespace character of previous/next line?

I like the - and <C-M> normal-mode keys for going to the first non-whitespace character of the previous/next line. Are there coresponding keys for going to the last non-whitespace character on ...
14
votes
3answers
1k views

Edit different words simultaneously, one the same line like in Sublime Text with multiplie selections

is it possible to edit more than one word simultaneously, which are on the same line? For example, let's say I have this: Spam and Eggs is all you need for a healthy breakfast and I would like to ...
7
votes
1answer
1k views

Cursor moves one character backwards on exiting insert mode

I recently have noticed that entering and then exiting insert mode will move your cursor one space to the left. This is a default behavior of vim, since it still occurs with vim -u NONE -U NONE -N. ...
38
votes
6answers
5k views

Can I delete an entire line, except the line break?

A fairly common operation for me in vim, since I am compulsive-obsessive and like to keep my files free of whitespace, is to delete the contents of an entire line, but not the line itself (i.e. not ...
20
votes
2answers
608 views

How can I use a line number to copy a line to where my cursor is?

A lot of times I'm in a situation similar to this: 1. <Line 1> 2. <Line 2> 3. <Line 3> 4. <Cursor is here> 5. <I want to copy line 1 here> An easy solution is mm:1<...
7
votes
3answers
159 views

How to jump only in currently open file?

Quite often, when using CTRL-O to jump back to an older position, vim takes me to other files I've been editing previously. Is there a command, to go back within the jumplist just in the current file?
4
votes
1answer
535 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 ...
13
votes
1answer
9k views

Jumping to a byte offset, and displaying position as byte offset

How can I move the cursor to the nth byte in the buffer? How can I display the current cursor position in the ruler in terms of the byte offset, rather than lines and columns? (Follow-up question: ...
9
votes
3answers
883 views

How can I delete a function call, leaving its inner content intact?

Let's say I have a line like this: a = x(y(z)); And I want to change it to: a = y(z); What's the most efficient way to do this?
4
votes
2answers
577 views

How to jump to the end of quoted string, considering escaped delimiters

Assuming the following situation $someVar = "Some String with \"escaped\" inner delimiters"; with the cursor somewhere in the double-quote delimited string. What is the quickest way to jump to the ...
2
votes
1answer
827 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 ...
1
vote
1answer
124 views

How can I clear normal mode command count in mappings?

I have a mapping like this: noremap <expr> zj FindNext() FindNext will calculate which line to go, and return something like 10G. This works without a count, but with a count the line number ...
4
votes
1answer
854 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 % ...
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 ...
2
votes
2answers
189 views

Using the % command on a line without a bracket

I like formating code this way: class A { } unlike another common way: class B { } The thing is, when using the % command to go to the enclosing bracket, which is very useful for copying/deleting ...
4
votes
1answer
436 views

How to resume previous multiple cursors?

I'm using multiple cursors plugin. I'm trying to do the same thing as the second example in their github page. Just trying to add double quote around each of the weekday: mon tue wed thu fri sat ...
1
vote
1answer
74 views

Gvim doesn't remember cursor position within line if previous session ended on line 1

I noticed that whenever I quit Gvim, it will remember the line and position within the line that the cursor was on, unless the cursor was on line 1. If the cursor was on line 1, then it will not ...
8
votes
2answers
251 views

What does [count]% do?

I would expect [count]% to jump back and forth between matching braces count times or something like that, but instead, typing that command seems to move the cursor to a random place in the buffer. ...
2
votes
1answer
139 views

Backward motions in Operator-pending mode move cursor

If i type, for example, y/foo<CR> in Normal mode, i "yank" all the text until the next occurrence of "foo" without side effects. However, if i type y?foo<CR> in Normal mode, i "yank" the ...
2
votes
2answers
139 views

How to add a string to cursor point of gvim through a shell script

When gvim is opened it saves the cursor position whether it is minimized or not. So I'm curious whether it is possible to add a string starting from the cursor blinking position by running a shell ...