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
1answer
42 views

Remapping motion keys [duplicate]

I recently found the awesome plugin named CamelCaseMotion which is awesome. I used their suggested mappings in my .vimrc for the plugin like this: map <silent> w <Plug>CamelCaseMotion_w ...
1
vote
4answers
39 views

How to end selection at an occurrence of a word?

Let's say I have this text with | as my cursor: <<<<<<< HEAD hi ======= hello ====== >>>>>> XXXX GGg| Now, I'd like to select from >>>> to say second=== or ...
3
votes
1answer
28 views

How do I get the text that is chosen by some motion?

I'm wanting to write a simple plugin that allows using a motion to choose some text and then processes that text. I'm trying to find out how to get the text that a motion results in. So far I haven't ...
0
votes
1answer
39 views

how to have a new line from within brackets

I normally write my functions this way public void test() {} to continue, I need to insert a new line from within the brackets, so the final output is this: public void test(){ // cursor is ...
2
votes
0answers
20 views

Different behavior when selecting quote blocks vs. selecting parentheses blocks [duplicate]

When I have a line of code such as: result = function(myVar); then I can delete the text "myVar" with the command di( only if my cursor is already positioned inside the parentheses. However, when I'...
1
vote
1answer
21 views

How to wrap a command which can handle a text object?

The scenario is that the plugin I use (iron.nvim) has a mapping crt which handle text objects. Ultimately, this mapping is based on a command <Plug>(iron-send-motion). I would like to create a ...
0
votes
1answer
60 views

Can I select and paste with a single operation?

Here's my use case. I have the following text: This is a [hyperlink](http://someurl.com). Now I want to replace the http://someurl.com text with a new URL in the default register (something I've ...
0
votes
1answer
69 views

How to create new operator by using existing operator with current motion?

function! OperatorFunc(type, ...) " how to call another operator with current motion? " do other stuff endfunction Is it possible to get motion text? such as get iw from yiw
15
votes
1answer
1k views

Why is the underscore command _ useful?

I'm a bit puzzeled as to why the underscore command _, which jumps to the beginning of the (COUNT - 1)th line below the cursor, gets its own key. When would I use this rather than + or ^?
0
votes
1answer
44 views

text object for highlighted text

If I have a file that contains this_is_the_first_underscore_phrase this_is_the_first_underscore_phrase I search for "first" /first and my cursor is placed onto the start of the word "first". I know ...
1
vote
2answers
54 views

visual line mode is ended by inner block motion

When I do Vi{y to select inside a { block and yank it, it doesn't paste how I expect. I noticed that after V (which puts me into VISUAL-LINE mode), the i{ object takes me into VISUAL mode. Here's a ...
3
votes
1answer
80 views

How does Ctrl-I works?

I have completely clean vimrc, no plugins, and the following test file: foo bar baz baz baz baz baz baz baz baz Now, I press / to start search, then type baz, press Enter, press n twice. It will ...
0
votes
1answer
36 views

Number in the beginning vs. number in the end

Yes, I know that d2e and 2de are two different commands and therefore works slightly different, though it's not visible to the eyes. Let's call them "number-in-the-middle" (nim) and "number-in-the-...
0
votes
0answers
24 views

Select characters in Visual mode (works differently than Normal mode)

I'm trying to understand the difference in character counting between Normal and Visual modes. Roses are red, Violets are blue, Sugar is sweet, And so are you. The task is to copy everything from ...
1
vote
0answers
32 views

Repeat previous square bracket command [duplicate]

I am using the ] commands (e.g. ]]) a lot and have a bunch of custom ones too. Is there a command that repeats the last such command, similar to how . repeats the last edit?
0
votes
1answer
34 views

(how) can I use di< / di> to delete inner block of xml

What would be the best way to delete / change the inner block of an xml element? I could use df< when my cursor is inside the block, i.e. when I have: <elem>foo bar<\elem> ^ ...
2
votes
1answer
44 views

Modify `iskeyword` for keyword-local completion only

Context Some time ago, I added the following line to ~/.vim/after/ftplugin/sh.vim to make working with parameter expansions easier: setlocal iskeyword+=$ This is nice to be able to e.g. ysiw" via ...
1
vote
1answer
114 views

Repeat complicated motions

I know that similar things were asked here several times. I know that to repeat a motion ; works. Unless it doesn't(in case there is count for example), but then repmo.vim usually works. And I know ...
1
vote
0answers
27 views

]m moves to class definitions not method definitions inside nested classes

I am editing a java file. ]m takes me from one class to the next, instead of to the next method definition. How do I get it to take me between methods? Example: public class Baz { public class ...
1
vote
1answer
51 views

Automatically jump to text object during `ci(`

Suppose my cursor is at the beginning of the line of code: def f(a, b, c, d, e): If I want to change inside the parenthesis using the text object command ci(, I need to first navigate to some ...
1
vote
1answer
28 views

Why is :execute required in this --remote-silent command?

Let's say I want to jump to a particular position in a file in an existing Vim server: This command jumps to the correct line, but not the correct column, leaving the cursor at the start of the line: ...
20
votes
4answers
2k views

Simplest way to delete a “composite” word?

Apologies if "composite" is not the technical term. I mean the following: Hi, I-am-a-composite-word and we are not I would like to delete only the composite word. In command mode, if I move the ...
4
votes
2answers
211 views

How to delete entire function definition (C style)

How can I delete the block int Test() { // } when my cursor is before int (or even better when it is anywhere on that line)? The shortest I could come up with is d<line>G where <line> ...
2
votes
1answer
65 views

Is there a text object or motion for non-comment lines are not separated from comment lines by blank lines? E.g., in git commit messages

Consider the text A B # C # D Is there a text object or motion that will select lines A and B if the cursor is on either, but not select lines C and D? ap or ip with the cursor on any of those four ...
1
vote
0answers
30 views

How can I prevent <CR> from moving the cursor downward? [duplicate]

In the vim help doc, it says: *CTRL-M* *<CR>* [count] lines downward, on the first non-blank character |linewise|. That is, in the normal mode, <CR> has the same ...
0
votes
1answer
33 views

How to move a line onto the end of some other line

For example suppose i have 1 the cat jumps 2 over the moon I would like the result 1 the cat jumps over the moon In general how can I move line X onto the end of line Y. A solution that would ...
1
vote
2answers
50 views

Delete entire block, with the prefixes before the opening {

My problem Consider a code block prefixed with a few words (function name, for example). The vim cursor is in the middle of the prefix word. The line ends with a {, which declares a block which spans ...
2
votes
1answer
52 views

change inner backslashed quotes

I know the ci" motion and others :changes, but I need something like a ci\" in order to change inner a backslashed quotes. Assuming * as the cursor position: a = "message says: \"fo*o bar\"" I would ...
2
votes
1answer
49 views

Unable to set iskeyword for colon ( : ) character

I am using vim to edit LaTeX files. Throughout the text, there are labels to equations, tables etc. for which an accepted convention among TeX writers is the following \label{eq:massenergy} , \...
1
vote
2answers
47 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} ...
0
votes
1answer
58 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 ...
0
votes
1answer
34 views

Delete from the next character till EOL

My problem Consider the following line: I have just pasted @SrvrlessDaysTLVtlv before tlv@serverlessdays.io, and I'd like to delete anything from the small-case t till EOL. What have I tried d$ ...
0
votes
1answer
69 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
2
votes
3answers
106 views

How to indent one line multiple times?

Like doing >> but 5 times >>>>>>>>>>>>. I am not trying to indent multiple lines.
5
votes
4answers
181 views

Delete with search motion in normal command

I am attempting to delete from start of line until string foo. In normal mode, 0d/foo accomplishes this. Now, I would like to do this for every line in my buffer. Reading documentation and SO it ...
2
votes
2answers
387 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: ...
0
votes
1answer
53 views

How to replace ) by <left> when closing bracket [config]

I have the following in my .vimrc, it permits to automatically close brackets. ino " ""<left> ino ( ()<left> ino ' ''<left> ino [ []<left> ino { {}<left> What I would ...
0
votes
1answer
60 views

Enable %-key jumping/highlighting for backticks (`) and single-quotes (') in M4 files

Background When working on .c and .h files, I have a couple options turned on, namely: filetype plugin on filetype indent on autocmd BufEnter *.c setlocal tabstop=8 shiftwidth=8 softtabstop=8 ...
0
votes
3answers
67 views

mystery cursor motion

I hope someone can riddle me this one: I have set up the function below to have a slightly more fancy behavior of the End key, moving first to the end of the line, but if the cursor is already at the ...
0
votes
2answers
107 views

Simple modification of behavior of Home, End keys

I'm completely new to Vim scripting, so forgive me if this may seem trivial, but I would like to modify the Behavior of the Home and End keys such that, if the cursor is somewhere between the first ...
0
votes
2answers
169 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} ...
1
vote
2answers
68 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} ...
2
votes
1answer
53 views

Key binding to select the current paragraph

I'm using the following key binding to visually select the current paragraph. nnoremap <leader>v }kV{j Is works as follows: } Move below the current paragraph. k Move one line up. V Start ...
1
vote
2answers
180 views

How to select/delete/yank the contents of only the current fold?

When using foldmethod=marker, how do you select or reference exactly the contents of the current fold? I want to swap the order of two folds. If they were paragraphs, I would do dap { p. However, I ...
2
votes
2answers
202 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 ...
4
votes
3answers
188 views

Reverse a set of paragraphs

Is there a good way to reverse a set of paragraphs (navigable via cursor motion { and })? My practical use case is reversing the order of blocks of latex code (ie, reversing the order of jobs in a ...
2
votes
1answer
51 views

How do I move by paragraphs, but end up *in* the paragraph?

So I often use repeated invocations of gqip to re-wrap paragraphs of text or comments. Unfortunately, the quickest way I've memorized for moving between paragraphs, }, lands me between them: Qui⁁ut ...
2
votes
4answers
299 views

Delete from cursor position to end of text object

I often find myself in this situation: \foo{\bar abc \baz{def} more stuff} ↑ and I want to change anything from the cursor position to the correct enclosing brace. In simple cases, ct} ...
3
votes
1answer
182 views

:exe moves cursor to first line of buffer

function! DebugC() let l:debugStr = "printf(\"" . s:debugPrefixStr . s:debugCounter . "\");" if g:debugstringAlwaysIncludeHeader let l:incStr = "#include <stdio.h>; " ...
0
votes
1answer
80 views

Delete to next search result?

I often use dt, but that only deletes to a character. Is there something like dt that lets me type in a search instead of a single char? I would want to delete from my current cursor to that first ...