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
5
votes
1answer
195 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 (. ...
6
votes
3answers
754 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
227 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
178 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
1k 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
81 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 ...
19
votes
1answer
4k 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
88 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
1k 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
671 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
165 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 ...
3
votes
2answers
297 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
302 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
777 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
132 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
219 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
133 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.
8
votes
1answer
429 views

Can I add a custom paragraph delimiter?

Paragraphs are delimited by empty lines, both in vim and tex, but sometimes I wish vim to treat an entity as a paragraph and not tex. Can I, e.g., make vim treat lines containing only a "%" as a ...
9
votes
2answers
201 views

Make sense of "[[", "]]", "[]", "]["

I found it hard to understand these text object motions: *]]* ]] [count] sections forward or to the next '{' in the first column. When used after an ...
21
votes
2answers
5k views

Why do `cw` and `ce` do the same thing?

This has always bugged me about the w and W motion commands—they seem to work differently when used with the change command than they do when used alone, or with the delete command. For example, with ...
8
votes
2answers
341 views

How do I surround a quoted string without including leading whitespace?

I have a string like 'foobar', and I want to surround it with parentheses: ('foobar'). With vim-surround, I can do ysi'), which produces '(foobar)'... Not what I want I can also ysa'), but that will ...
12
votes
2answers
2k views

Is there a text object for current line?

Is there a text object for current line? Is there a text object for ^$?
5
votes
1answer
175 views

Text formatting CVS-friendly

I have seen this very interesting article: http://dustycloud.org/blog/vcs-friendly-patchable-document-line-wrapping/ --- basically it is a suggestion for hard-breaking lines of text (for example, in ...
7
votes
2answers
1k views

How to jump back to the cursor position before I entered insert mode?

I'm trying to set up normal mode mappings to make it easy to add white space around the cursor: <C-h> will add one space to the right of the cursor; <C-j> will add a newline below; <C-...
38
votes
5answers
22k views

How to disable arrow keys in vim?

I want to teach myself to prefer hjkl more over the arrow keys in order to stay on the home row. (I am very aware that one should not use hjkl as the main navigation keys as there are more powerful ...
6
votes
2answers
474 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 ...
9
votes
2answers
6k 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 ...
1
vote
1answer
168 views

ci[ ; bracket recognition fails

i have the following Text in my vim ('|' is my cursor.: "|--------------[ LatexBox ]------------- When i press ci[, nothing happens. I would expect that it doesn't matter where exactly in the line ...
16
votes
3answers
2k views

Mapping with motion

I'm trying to understand how can I use operator with subsequent motion inside a mapping. For example: nmap /c c{here we pending for a motion}/<C-r>"<CR> The map should do the following: ...
2
votes
1answer
1k views

Position cursor at end of line in insert mode

(This question pertains to nvi instead of vim.) To facilitate editing, I created the following mappings map! ( (?)@^[F?xi map! [ [?]@^[F?xi map! { {?}@^[F?xi so that entering ( will insert (|)@, ...
1
vote
1answer
83 views

How can I execute a command with a motion to the next/previous number?

I want to essentially be able to use a command similar to dt#, where the # represents any numerical character. My use case is modifying a script where I have a few server instances with long names ...
3
votes
2answers
392 views

Find based on text objects

I am a big fan of text objects, and I like their composability. For example, if I have \label{sec:this-is-a-section} I can easily copy the sec:this-is-a-section part by navigating inside, and ...
6
votes
1answer
144 views

How to keep in the undo history just one change for this command?

I want to keep in the undo history just one change for a long command such as: d0kJx. (I took the command from this answer.) This command (d0kJx) does this (The ^ is the cursor position): Before: a ...
10
votes
3answers
2k views

How to delete till the end of the previous line?

An example (The ^ is the cursor position): Before: a bc def ghi j k l mn o p q rs ^ After: a bc def ghimn o p q rs ^ or at least: a bc def ghimn o p q rs ^ I know I ...
4
votes
1answer
127 views

Hard wrapping a range to textwidth with an ex command

Also asking how to apply an ex range to a normal command. In a file of some 125k lines with a preamble followed by 8 columns of 10 character wide text, the contents of the column are 8 characters of ...
1
vote
1answer
95 views

How to write literal for Tab key to use for motion?

I've the following dummy file created via: echo -e "a a\tb b\tc c" > file Is there any literal for space which I can use for motion argument? For example this works (which removes the 1st a a ...
5
votes
1answer
200 views

Applying an ex command to a visual selection or text object

Is it possible to apply an ex command to something smaller than a line? For instance, I tried to define a mapping that would remove an \emph{} from the enclosed word. The best I could do was: ...
4
votes
2answers
330 views

surround plugin and TeX quotes `'

Is it possible to make the surround plugin work on `TeX-style quotes' and ``TeX-style double quotes''? (Normally, if `this is quoted'| and `this', va' will select from the first closing mark to the ...
5
votes
1answer
85 views

How to keep a text object a" when it contains a breakline?

I noticed that if I have a quoted string which contains one new line character I can't use the text objects i" and a" anymore. For example if I have: This is some text which is less than 80 character ...
4
votes
1answer
107 views

Jumping to *just before* the nth occurence?

I can use f or F to highlight/change or jump to the next occurrence of say, a comma. This is way useful, but is there a way to highlight/change to the character just before? Say I have some code: ...
2
votes
2answers
99 views

How can I conveniently yank then change small text?

This is more of a specific deeper dive into vanilla Vim then the question Can I make Vim also save “small deletions” into register "1?. A common text editing situation I run into is to yank a text ...
15
votes
1answer
1k views

How to treat underscores like space?

Is it possible for vim to treat underscores like spaces or hypens, so when I use the sequence dw, it doesn't delete whole sentence some_long_text_with_underscores, when the cursor is at the beginning?
2
votes
1answer
188 views

Custom motion to change, delete or select matching pattern

I'm looking how I might use "Operator-Pending" mode to make a custom motion that allows change, delete or visual selection of a pattern match under the current cursor position. In short, after ...
9
votes
1answer
380 views

Is it possible to use '/' search as an inclusive motion (similar to what 'f' is to 't')?

I've been a long time fan of the t and f motions to modify text up to or including some character. For more complicated criteria, I've started using / followed by a search string to modify text up to ...
8
votes
3answers
1k views

Move after end of word or Delete after cusor

What is the fastest sequence to delete to the end of line after the cursor position? Example: I want to delete this line in a faster way Sequence: 5eD will delete the last character of the word ...
4
votes
1answer
263 views

Use motion when putting

A very common use case I'm having is to copy something (let's say a word) and I want to paste it in another context (let's say a word with quotes). The way I do it is: const char *foobar(void) { ...
17
votes
2answers
2k views

Expand f and t motion to next lines

Is there a way that t{char} and f{char} will continue to work in the next lines if {char} is not present in a given line? I would like to avoid using /{char}<CR> to save 1 keystroke and to not ...
2
votes
1answer
429 views

Motion key for next highlighted item?

Using the normal spell-check mechanism in vim one can jump from one misspelling to the next using ]s. Sadly vim's spell-check is completely useless for Turkish. Using the vimchant plugin that hooks ...