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
3
votes
3answers
2k views

A version of `w` which skips to the next underscore

I frequently work with code style which asks that many non-class symbols use snake_case -- Python, Ruby, and C especially. If I have a symbol like longfirstpart_longsecondpart, I'd like to be able to ...
2
votes
1answer
73 views

How to move to top/bottom of region delimited by consecutive blank lines

I have two commands for somewhat emulating the Emacs command narrow-to-defun. I have two commands that move to the top/bottom of the current paragraph nnoremap <silent> <leader>gt mp{...
3
votes
4answers
489 views

How to get around this common multiple-cursors use case?

I have a lot of difficulty doing things like the following in Vim: From 1 'apple' 2 'orange' 3 'pear' 4 $fruit1 = 5 $fruit2 = 6 $fruit3 = To 1 2 3 4 $fruit1 = 'apple'; 5 $fruit2 = 'orange'; 6 $...
7
votes
3answers
3k views

How to use 'w' to navigate in CamelCase words?

How would I use set iskeyword to be able to use w to count Capital letters as words? For example for the following sentence, ThisIsAShortSentence Pressing w will jump from T -> I -> A -> S -> S
3
votes
2answers
219 views

Highlight everything inside (, [, and { and expand outwards

Suppose I have a line of text of the form (123[456{789}abc]def) and the cursor is inside the curly braces. In sublime text, we can use ctrl-shift-m repeatedly to jump to highlighting 789, {789}, 456{...
1
vote
2answers
476 views

Replace a word in a stream of words separated with underscore

Does anyone know a quick shortcut I can use to replace a word in a series of words connected with underscores? Given: Create_in_one_of_these_words I want to make, where | is cursor: Create_in_|...
3
votes
0answers
154 views

how to delete a paragraph respecting the folds?

I have a file (filetype=javascript), this is how it looks without folds: and with folds: I can move with the { and } motions skipping the empty lines inside the folds (thanks to these question and ...
0
votes
1answer
340 views

Jump to specific character after cursor

What I want to do is jump to the first instance of character < X > after the cursor. I already know how to achieve this on the current line, but I was wondering if there was a way to apply this to ...
1
vote
1answer
2k views

how to remap backtick mark with single-quote mark globally [duplicate]

I want to swap ' with ` for all combinations of commands in normal mode. I have tried the following: nnoremap ' ` nnoremap ` ' It works for commands like '', ``, but failed for d'', y'', etc. ...
3
votes
1answer
85 views

How to search in visual mapping?

I am trying to create a text object for consecutive lower-case letters. Here is how I am setting up the inner text object: xnoremap in :<C-u>normal! ?[^a-z]?e+1<CR>v/[^a-z]/s-1<CR> ...
0
votes
1answer
68 views

How can you turn off text highlighting (hlsearch) with custom text objects?

I am implementing a custom text object in visual mode, but this text object uses regular expressions to find the beginning and ending of the selection. However, when I do this, other parts of the text ...
2
votes
0answers
464 views

Using text objects with IJKL navigation keys

Like many people, I prefer a triangular or inverse-T navigation key format like IJKL instead of HJKL for ergonomic reasons. There's a pretty simple way to set this up in vim that I've used for years: ...
2
votes
1answer
120 views

Prepare a range for an ex command without visual mode or line numbers

Background: I can pipe a paragraph through an external command using !ip and the cursor goes to the end of the following prompt: :.,.+5! If I want to use the built-in sort or center functions I ...
0
votes
2answers
202 views

Ammend 'w' behavior - ignore operators and brackets - '(', '[' '{', '*', '+', '='

As the title says. Is it possible? Steps to reproduce: Type in sample(text) and put the cursor on the first character then press w. Expected behavior: Cursor moves to beginning of next word - text ...
1
vote
1answer
102 views

How do I apply the Lowercase action to a line movement?

From the vim-as-language article: Vim’s "verbs" mostly fall into 2 main categories. Some of them act on a single character, and others act on a "motion" or "text object". And from the vim wiki for ...
1
vote
2answers
266 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-...
4
votes
2answers
107 views

Linewise inner tag without the tag lines?

An example HTML, with the cursor where the brackets are: <foo> <bar> baz quux [] </bar> </foo> I would like to outdent the text inside <...
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 ...
0
votes
3answers
237 views

Add line at the end of text

I have 5000 text files in a folder with different names. I just need to add one more line to the end in all files. Example: HELLO HELLO HELLO HELLO I need make it HELLO HELLO HELLO HELLO abc ...
6
votes
5answers
844 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
127 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
128 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
1k 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
500 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 ?...
25
votes
5answers
4k 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
822 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, ...
6
votes
1answer
403 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
69 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
110 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 &...
65
votes
3answers
19k 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
1k 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
44 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
466 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
145 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
418 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
153 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
579 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
427 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: ...
12
votes
4answers
6k 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
341 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
340 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
4k 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
162 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
90 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
827 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 ...
20
votes
2answers
353 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, ...
9
votes
3answers
957 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 ...