Questions tagged [cursor-motions]

Commands that moves the cursor. A motion command is used after an operator command to move over the text that is to be operated upon.

Filter by
Sorted by
Tagged with
6
votes
5answers
751 views

truncate sentence: delete up to, but not including period

How can I set up a keybinding to delete up to the end of a sentence that ends with a period, but keep the period? The commands df., d), and D all truncate the sentence but don't keep the period. ...
5
votes
1answer
115 views

Is there a shortcut to reuse the last operator+motion without repeating the whole change?

Many times I find my self running ciw or c2W but with different text. Like ciwnewtext<esc> and then ciwanothertext<esc>. The dot command . will repeat the whole change (it does not allow ...
4
votes
1answer
127 views

Why is block selection characterwise?

Looking at the documentation I found this piece: a} *v_a}* *a}* *a{* a{ *v_aB* *v_a{* *aB* aB "a Block", select [count] Blocks, from "[count]...
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 ...
4
votes
1answer
657 views

How to select the content within brackets including brackets and without including brackets?

I have some code structure e.g { { // Some content goes here } [ // Some content goes here ] } I want to select the content inside { } in some case and also content inside with ...
3
votes
1answer
413 views

Remap standard motions

I have a file formatted like this +---------------------------------+ | Text text text | | Text text text | | Text text text | +---------------------...
17
votes
3answers
2k views

How to jump to middle of buffer

By pressing gg and G you can jump to both ends of a buffer. 42G jumps to the line 42. Is there any quick g shortcut to jump to the middle of buffer. Something like roughly round(number of lines/2)G ?...
22
votes
5answers
3k 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 ...
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, ...
5
votes
1answer
339 views

Which text object defines text enclosed in space?

Since I need to operate on a sequence of symbols between spaces I'd like to know which text object defines it. Here is an example: 45908 Sep 24 21:31 [r].t3891993.tr some another text. ...
0
votes
1answer
65 views

How to operate on all of a word without its surrounding space?

In vim you can do daw to delete the entire word, but it also removes the space after the word, (caw too). Is there a way to operate on the entire word without effecting the space around it? For ...
2
votes
1answer
101 views

Is there a way to make the `r` operator accept a motion?

What I would like to do is issue a raiw where the current word would be replaced by an aaaaa word. example: this is a w[o]rd <--- cursor on [] raiw <--- command this is a aaaa &...
61
votes
3answers
17k views

Why does vim use hjkl for cursor keys?

Why use the keys hjkl on the same line instead of keys in a triangle like wasd for moving on video games? Why not something equivalent with right hand, like ijkl or pl;'?
4
votes
4answers
985 views

Fastest way to delete part of word from end of word?

Let's say I have the following text and my cursor is on the "d" someCamelCaseWord ^ I want to delete "Word" so that the text reads "someCamelCase" What's the fewest number of ...
1
vote
1answer
41 views

Make pipe behave like `col('.')`

So when I go to the first character in a line, the first character in that line is a tab character, and I execute echo col('.'), I will get 1. However when I type 2| I won't go to the next character, ...
1
vote
1answer
62 views

Act on lines changed by previous command

Is there a way to target the set of lines changed in the previous command? Say I do a search and replace, bulk indent, or some other command that affects either a series or scattered collection of ...
2
votes
2answers
443 views

Jump cursor vertically over code blocks. Keep horizontal position

I'm thinking about a feature which I think would improve my workflow a lot. I don't know if it already exists.. The feature is about moving the cursor vertically over code blocks without losing its ...
1
vote
1answer
104 views

wrap breaks when using delete or change word type commands

Using these options set wrap linebreak nolist set showbreak=~ "adds specified character after wrap set breakindent "forces word wrap to start at last lines indentation level set display=lastline "...
6
votes
5answers
414 views

How to ignore a column when visually selecting a paragraph

I have a file that looks like this: # Section 1 # # new: a.txt # new: b.txt # # # Section 2 # # [n]ew: c.txt # new: d.txt # new: e.txt # My cursor is on the first new of the second section and I ...
6
votes
1answer
122 views

Delete to ; if exists, otherwise to end of line

autocmd FileType cpp nnoremap <buffer> C ct; autocmd FileType cpp nnoremap <buffer> D dt; These two are quite useful, but sometimes there is no ; after the cursor and then D doesn't do ...
0
votes
1answer
452 views

Gotchas for changing spacebar to insert a space?

I find that one of my most common actions is to insert a space, therefore I am thinking about changing the spacebar to insert a space. Right now I rarely use the space bar in normal mode, which is ...
4
votes
3answers
347 views

Change or reverse order of arguments

A common task I run into is having to change the order of arguments. So, for example, I might have something like this: stringInsert( "text to insert", buffer ); and need to change it into this: ...
10
votes
3answers
4k views

Is it possible to have vim show the list of available marks when using marks?

That is, when you hit the marks operator key ` or ' you get a list of the available marks - i.e. the list vim gives from the ex command :marks. Then, when you press a letter to jump to the mark, you ...
4
votes
3answers
329 views

How can you indent your current file without losing your cursor position?

I was reading that the way to indent in vim is a gg=G sequence. This however loses my cursor position. How can I indent my file without losing my cursor position?
1
vote
2answers
320 views

Philosophical question: Is remapping keys to allow navigation in Insert Mode bad practice? In fact, why even have Normal Mode? [closed]

I decided to remap the arrow keys to C-h, C-j, etc. in my vimrc. Then I decided to allow half-page scrolling (which I use a lot) with C-u and C-d. But now I'm realizing that I rarely use hotkeys in ...
6
votes
2answers
3k views

Jumping to start/end of function definition in C++

Is there an easy way to jump to the beginning or end of the function your cursor is currently inside? It doesn't seem like sentence/paragraph/section have useful syntax aware meanings when editing C++....
1
vote
4answers
141 views

Motion remap to select function doesn't work with v

I want to add a motion: :onoremap <silent> f( :<C-U>normal! f)vF(b<CR> If I have this line, where the asterisk is my current position: int a = fo*o(4, 5, 99); I want to type vf( ...
2
votes
1answer
88 views

For column navigation, is there a nice to display column numbers the way we typically display line numbers?

When navigating within a line, I find myself navigating one character or word at a time, which I feel it one of my greatest inefficiencies. Navigating to a particular line is easy, because we have ...
11
votes
3answers
654 views

How can I use marks to jump to locations in files I have recently opened, but not changed?

Often times I edit a file - think my work is done - then close the file and move on to the next thing. But then I realise I need to go back to that code and tweak it a bit more. If I open the file ...
17
votes
1answer
306 views

Why does “Operator” + “Motion” behave inconsistently?

This is something that has bugged me for a long time, but I've never gotten around to asking about. Say the text in your buffer looks like this: Hello World If I put my cursor somewhere in line 2, ...
8
votes
3answers
818 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 ...
5
votes
1answer
187 views

cpoptions and parenthesis text objects

Haskell has a literal syntax for anonymous functions of \pattern0 pattern1 [...] patternN -> expression which interacts oddly with vim's parenthesis text objects when pattern0 starts with a (. ...
4
votes
3answers
630 views

Why does replace not accept a motion?

A lot of operator like delete, change, indent, switch-case accept a motion to apply on. For example, let say I want to replace the current word with all letter a, I do: viwra Compared to the ...
4
votes
1answer
153 views

Motion to jump back one level of indentation, not including blank lines

I've been authoring a lot of F# in Vim lately. Like Python it is pretty strictly indentation-based. However, unlike Python mode for Vim, it does not appear that the standard F# Vim plugin supports any ...
4
votes
1answer
159 views

Compute the distance between two marks

I came across a question, while writing some vimscript. I wanted to know the "distance in motion" between two marks in the buffer. The interesting point of this can be to know how many time I have to ...
6
votes
1answer
867 views

What does vim consider a paragragh?

Suppose I have the following piece of code through which I would like to navigate ===>Cursor is here and when I press { SomeTest { line1 line2 line3 line4 ...
2
votes
1answer
79 views

Why doesn't n jump to the last character matched with f?

I have a vim script that does the following: normal 3f, normal lvnh"+y But if I search for anything other than /,/ before hand, the n in normal lvnh"+y matches whatever I searched for last instead ...
4
votes
1answer
2k views

Change/delete matching brackets at the same time

Sometimes I write something in brackets and then realize I've typed the wrong kind. For instance, in LaTeX: \command(arguments) Which should be: \command{arguments} I can jump between the two ...
16
votes
1answer
3k views

End of python block motion

I need a motion that moves to end/beginning of a python block, and I need another motion that moves to begining/end of previous/next method/class (all combinations). I've tried vim-indent-object, ...
4
votes
1answer
86 views

Deleting to the begin of the line with d _

In Vim, v_ selects text from the current position to the actual begin of the line. Example: Test test Test te|st Now pressing v_ we get the selection: Test test [Test te]st From this I would ...
0
votes
2answers
945 views

How can I change/delete comments easily?

For commenting and uncommenting I now use the vim-commentary plugin, also the NERD commenter can be used as mentioned in: How to comment out a set of lines which are selected in visual mode? I would ...
1
vote
2answers
520 views

How do I get matchit to work with '/>' (self-closed tags)?

I really like to jump from one <el> to the end of </el> with matchit. I am using it for jsx, but it does not seem to work if I have an element that is declared with />, does anybody ...
4
votes
1answer
142 views

What are the rules for “w” word motion when characters are not in iskeyword?

If I have a shell script with code like ... chars+=('5') chars+=('6') ... chars+=('%') chars+=('&') ... and iskeyword is defined as iskeyword=@,48-57,_,192-255,- This definition indicates to ...
2
votes
1answer
185 views

How can I print out the iskeyword characters?

When I use :set iskeyword? to view keyword characters, result for shell scripts is: iskeyword=@,48-57,_,192-255,- :h iskeyword says @ expands to any alpha character that the isalpha() functions ...
0
votes
1answer
261 views

Goto First line of page

I know to go to the last line of the page i use L. How do I get to the first line of the page ? or what is the opposite of L
9
votes
1answer
733 views

Change the cursor shape in operator pending mode

My cursor in Gvim: My cursor in Gvim after pressing d: Is there any way I can change the cursor in terminal Vim when in operator pending mode? It doesn't have to look exactly like the screenshots. ...
4
votes
1answer
120 views

How can I make f motions wrap across lines?

I don't actually want f itself to wrap across lines, but I would like to know how I can create a single key mapping which will jump to the next instance of the letter which follows it. The mapping ...
4
votes
3answers
197 views

How to find the next SpellLocal

I am curious to know how I can find the next instance of a SpellLocal mistake (either by a motion key or via a search command) in vim.
4
votes
1answer
130 views

textobj-user: must the patterns be different?

I'm trying to make a text-object that is a paragraph surrounded by lines containing %. To test something simpler, I tried: call textobj#user#plugin('pc', { \ 'code': { \ 'pattern': ['%<', '%'...
4
votes
0answers
50 views

How can I specify the movement direction for text objects?

How can I specify a direction (for going backwards) for commands working on text objects like 2caw? E.g. I like to make 2caw replace bbb ccc in aaa bbb ccc ddd while on c.