Questions tagged [cursor-movement]
Moving the cursor another place in the buffer.
249
questions
0
votes
1answer
28 views
Template plugin(?) to jump to next occurance of '<++>'
I just noticed that my current box with vim is missing a crucial feature, but I am unable to bring it back.
A long time ago I had a vim setup where I could press Ctrl+J (IIRC) and then my cursor ...
1
vote
2answers
69 views
Changing content within the specified [count] number of braces for each line
I need to change the content within a [count] number of braces for each line in my buffer.
1 {Lorem} ipsum dolor {amet} blah blah {change this text} more blah blah
2 Hello. The {sun} rises in {the} ...
20
votes
3answers
1k views
How can I get ‘n’ to go forward even if I started searching with ‘?’ or ‘#’?
Vim has (at least) two sets of commands that search in opposite directions. Typing / and then a pattern will search forward through the document for the pattern; typing ? and then a pattern will ...
8
votes
2answers
264 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. ...
1
vote
2answers
89 views
How to remove a line and paste it at the beginning of a range
How to remove a line and paste it at the beginning of a range?
line 1
line 2
line 3
line 4
xxxxxxxx
For example, here I want to remove the 5th line and paste it before the first two lines, to change ...
17
votes
4answers
7k views
Scroll a quarter (25%) of the screen up or down
I often find scrolling a full page too disorienting, half a page too much, but a quarter page is just right. I currently do it just by holding down the arrow keys.
How do I scroll 25% of the page ...
28
votes
1answer
15k views
How can I jump to the next “paragraph”?
Right now I'm working with some blocks of text that are over 1000 lines long. Is there a simple way to move to the beginning of the next paragraph?
My workaround for now is searching for two ...
0
votes
1answer
90 views
`0` only moving to first “visible” column
I have a strange trouble with vim (8.0.95). My format options are fo=cq and nowrap. When I have a long line, which does not fit my terminal window, the view of the file does not include the first ...
6
votes
2answers
397 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 ...
0
votes
2answers
452 views
How to make f{char} case insensitive?
Regarding this command:
f{char} To [count]'th occurrence of {char} to the right. The
cursor is placed on {char} |inclusive|.
{char} ...
0
votes
1answer
75 views
Jump to next semicolun
I can use fd to jump to the next d character. How can I jump to the next semicolun? f; doesn't seem to work. Also, for other special symbols.
Thanks
45
votes
8answers
17k views
Why is using arrow keys in normal mode considered bad practice?
I have read it in many articles (e.g.) that it's a bad practice to use arrow keys in normal mode. Could somebody explain why is it considered a wrong practice, if at all?
7
votes
2answers
5k views
Move inside next quotes?
I have a file with several lines like so:
{"latin": "", "french": "", "italian": "", "catalan": "", "portuguese": "", "romanian": "", "spanish": "", "english": ""}
I want to quickly move between the ...
4
votes
2answers
276 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 ...
2
votes
2answers
468 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:
...
12
votes
6answers
8k 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 ...
1
vote
2answers
76 views
How to change f{char} to search left if no char was found searching right?
Regarding this command:
f{char} To [count]'th occurrence of {char} to the right. The
cursor is placed on {char} |inclusive|.
{char} ...
12
votes
4answers
3k views
Vim HardMode Fine Grain Movements
I recently found out about Vim hard mode and I've decided to try and use it. However, I'm running into some problems with fine grain movements.
For example, let's say I really just want to move up or ...
7
votes
2answers
7k views
How to go to end/get out of the parenthesis of a line in vim?
I read the solution answered in https://stackoverflow.com/questions/11037825/vim-get-out-of-parenthesis-brackets-etc. That is nothing but command A that takes away you in the end of line.
But, my ...
2
votes
1answer
421 views
Make ctrl-j and ctrl-k work like they do in less?
I would like to use ctrl-k and ctrl-j to not only move the cursor up or down (by lines), but also to scroll the portion of the document that is visible. Effectively, leave the cursor where it is and ...
2
votes
2answers
526 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
...
3
votes
1answer
58 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
429 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
208 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
804 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
432 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
265 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
126 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 ...
40
votes
6answers
6k 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
41 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
162 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
373 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
89 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 ...
19
votes
2answers
1k 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
608 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
843 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
631 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
170 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
215 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
311 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
101 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
254 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
212 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 ...
1
vote
1answer
377 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
537 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
179 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
67 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
197 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-...
6
votes
1answer
253 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 ...
3
votes
3answers
99 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 ...