Questions tagged [cursor-movement]

Moving the cursor another place in the buffer.

Filter by
Sorted by
Tagged with
3
votes
1answer
57 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 ...
2
votes
0answers
356 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
2answers
175 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, ...
2
votes
2answers
706 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 ...
2
votes
1answer
427 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 ...
3
votes
1answer
244 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 ...
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 ...
39
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 ...
0
votes
0answers
40 views

Prevent viewport from jumping to the right

As soon as I put the cursor on column 79 or beyond, the Vim viewport jumps to make sure the cursor is put in the middle of the viewport. I find it massively disturbing, but could not navigate my way ...
5
votes
1answer
159 views

How to move around comments in any type of file?

In $VIMRUNTIME/ftplugin/vim.vim, some mappings are installed to move the cursor to the previous/next comment: " Move around comments nnoremap <silent><buffer> ]" :call search('^\(\s*".*\n\...
8
votes
1answer
360 views

Motion for moving to non-top-level Python function definition

I'm looking for something like [[ (or [], ]], ][) that works with non-top-level function definitions instead of the next line with a top-level class or function definition on the first character. ...
2
votes
2answers
83 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 ...
18
votes
2answers
993 views

Using % in languages without curly braces

In C and C-like languages, I can use % to jump to the corresponding curly brace that the cursor is on. This is a well-known "trick". But in Ruby for example: def fun [1, 2].each do |n| end ...
1
vote
2answers
543 views

How to move to same indentation as previous line

Suppose I have many lines of various indentations. E.g. qqqq wwwwwwww eeeeee rrrrrrr tttttt yyyyyyy If I am anywhere on the fourth line above which is blank. Is there a ...
7
votes
1answer
765 views

What do matchit.vim's [%, ]%, a% do?

matchit's %/g% are simple enough to use, but I'm having trouble understanding the other mappings, which sound potentially useful but don't seem to work in any understandable way. ]% Go to [count] ...
0
votes
1answer
577 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 ...
6
votes
2answers
154 views

How can I undo an entire command (e.g. d4b), including the motions?

Say I do d4b, then realize I only needed d3b. If I hit u, it'll only undo the d part, and I'll still be 4 words back as if I just did 4b. I'd like to end up exactly where I was before I executed d4b. ...
5
votes
1answer
193 views

Is there a % equivalent for editing python code?

When I edit C-style languages, I can use % to jump between pairs of square brackets, braces, and parenthesis. If there an equivalent between for, while, def, if and the last indented line for the ...
2
votes
1answer
266 views

Move cursor from surrounds

What is best way to move cursor from the inside surrounds '"([{ (and other types)? For example, I'm typing if (condition) { body }. I've typed the condition, then I should go to body. For me it's ...
2
votes
1answer
95 views

Move cursor after yank according to direction

I want to use yt<anyChar> for yanking and for jumping, so that cursor moves to the first char before <anyChar>. For backward moving this is working by default (after yT<anyChar> ...
0
votes
1answer
247 views

Removing trailing spaces with the substitute command changes the cursor position

From http://vim.wikia.com/wiki/Remove_unwanted_spaces function TrimWhiteSpace() %s/\s\+$//e endfunction autocmd FileWritePre * call TrimWhiteSpace() autocmd FileAppendPre * call TrimWhiteSpace() ...
6
votes
1answer
198 views

How to move the cursor to the next reference, option, heading in man pages?

If we load the built-in man.vim filetype plugin by writing in our vimrc: runtime ftplugin/man.vim We can read a man page inside a Vim buffer, using the :Man command described in :h :Man: MAN ...
0
votes
1answer
333 views

Prevent W from jumping to next line

Pressing W (as in Shift+w) when there is only one word in front of the cursor causes the cursor to immediately jump to the next line. This is unlike what happens when doing the reverse with B, where ...
2
votes
3answers
489 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 ...
0
votes
0answers
161 views

How to make vim automatically do a CTRL+D after jumping to a tag?

When I use CTRL+] to jump to a tag, the cursor will be placed at the center of the window. How can I make it stop at the top of the window? Now I do this by pressing CTRL+D after each jump. I was ...
0
votes
0answers
66 views

Column-based w command?

From a given cursor position, how can I move vertically to the next non-whitespace character (in the same column), whether up or down? Since I highly doubt this is a built-in motion command (if it is ...
1
vote
2answers
143 views

Prevent the cursor from moving to the top of the file

I started using Seeing is Believing and updated my vimrc: nmap <leader>s A # => <Esc>:%.!seeing_is_believing --timeout 12 --line-length 500 --number-of-captures 300 --alignment-...
5
votes
1answer
229 views

Indent Lines Up Without Moving

I frequently use the >8j and >8k commands to indent several lines at once. Using j, the lines are indented and my cursor stays at the first line. When I use k, the lines are indented, but my ...
2
votes
3answers
92 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 ...
2
votes
2answers
316 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) ...
0
votes
2answers
255 views

Current line position when switching buffers

When switching buffers with :e# or <ctrl>-^, I commonly see the line with the cursor (the current line) move to the middle of the window (maybe related to the scroll_cursor_halfway function ...
5
votes
2answers
189 views

Keystroke to move cursor to the last character of a highlight?

In Visual Mode, you can do this using the o keystroke. However with search highlighting, ie ? or / -- I have a whole selection, but I want to move specifically to the last character of the highlight....
6
votes
2answers
2k views

How can I restore the cursor position when opening a file?

If I edit a file with vim that I have previously edited, I'd like vim to jump to the position I was in when I last closed the file. How can I accomplish this?
2
votes
2answers
512 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 ...
4
votes
2answers
208 views

Jump to a series of line numbers one by one after a stay of x seconds at each line

I have a set of 10 line numbers, n1, n2 ,..., n10 in a code of 1000+ lines. I need to jump from one line to another. My normal practice is to do n1G, n2G... till the set is complete. It takes about 5 ...
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 ...
6
votes
2answers
752 views

Jump to next identifier in Vim help files

I regularly find myself in the situation that I am reading a help topic and see an identifier (the blue underlined words) that I want to follow with <C-]>. However, most of the time the ...
2
votes
1answer
83 views

How to handle intersections in an algorithm trying to draw ascii diagrams?

For learning purpose, I'm trying to reimplement a small subset of the features provided by the DrawIt plugin. So far, here's what I have: " data "{{{ let s:draw_state = 'disabled' let s:draw_chars ...
6
votes
2answers
4k views

Vim jump between words and stop at end of line

In normal mode, b and w are jumping between words, and I would like to stop at the end of line. For example: The cursor is right over here When I press w, what I expect is Instead, the cursor ...
1
vote
1answer
155 views

Automatizing cursor movement in normal mode

Beginner Vim user here. I already learned about automating deleting with commands, which happens this way: [number]d[j/k/h/l] [OR] d[number][j/k/h/l] Where number stands for the amount of the ...
22
votes
5answers
2k views

Delete until the right end of the current inner block

Let's say that I have a code like this (| represents the cursor position): func1(x|, func2(), y); I would like to get: func1(x|); Is there a way to delete the code from the position of the cursor ...
1
vote
0answers
174 views

In Vim what is the reason that ce and cw are the special case to be the same if the cursor is on a non-blank?

Why not just let the meaning of w in cw the same as in dw? I means the w in dw for me is at the next word's start. Does it make something more convenient or just more complicated? If the latter, I ...
0
votes
1answer
166 views

Map movement keys to jump words like in non-modal editors [closed]

Coming from non-modal editors, I still get confused with e, w, b in Vim. One feature I like about non-modal editors is jumping words by simply combining Ctrl with ←→ arrow. So I thought I ...
16
votes
2answers
6k views

How do I make Vim always display several lines after EOF?

In Vim, I don't like how when you reach end of file it puts the last line at the bottom of the screen. Is there anyway to make the last line be something like 10 lines above the bottom of the screen ...
5
votes
2answers
402 views

Is there a way to use an ex command without moving the cursor?

I have relativenumber turned on and sometimes find it convenient to use ex copy/move/delete on certain lines. For instance, my cursor might be at the top of the screen and there are two lines I want ...
1
vote
1answer
111 views

ci" - change at the closest quotes (not on the same line)

I've been using Spacemacs recently and I am trying to reproduce one nice feature that I've seen there in Vim. Currently: ci" will change everything inside double quotes (cursor does not have to be ...
17
votes
4answers
2k views

How to replace inner text with yanked text

An editing pattern I frequently run into is the following: I want to yank a piece of text inside quotes or brackets, and replace that piece of text inside another pair of quotes/brackets. For example,...
12
votes
1answer
818 views

Why does >3k move the cursor up when >3j does not move it down? [duplicate]

Hitting >3j indents the current line and the three below it, and >3k does the same but with the three lines above. However, when indenting down, my cursor is left on the same line as it started, ...
0
votes
0answers
1k views

Vim bind ctrl arrow key not working on osx

I know they have many topics about that, but i no one of them works. My configuration worked before to switch between split window, but my session has been re-init and i lost my osx config and it's ...
3
votes
1answer
522 views

How to go to the end of the line even in on a wrapped line?

I would like to map <End> and <Home> to go to the end or beginning of the current line (not the screen), even if the cursor is on a wrapped line: |1 First line. | |2 This is some ...