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
8
votes
1answer
367 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
172 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 ...
18
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 ...
6
votes
2answers
241 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
1k 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
156 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
979 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-...
33
votes
4answers
18k views

How to disable arrow keys in vim?

I want to teach myself using hjkl more than using 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
350 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 ...
6
votes
2answers
3k 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
119 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 ...
13
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
82 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
332 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
136 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
1k 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
111 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
83 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
155 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
248 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
75 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
99 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
95 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
159 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
332 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
2answers
928 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 ...
3
votes
1answer
224 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
367 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 ...
3
votes
1answer
400 views

How to skip over indentation whitespace with horizontal motion?

I have a file that uses 4-space indentation. By default, when I move horizontally, Vim moves over those spaces one by one. How can I configure Vim so that it moves 4 spaces horizontally when moving ...
17
votes
3answers
10k views

Multiple cursors at desired location

I'm using vim-multiple-cursors plugin. I would like to put cursors exactly where I want. For example ([x] are the cursor positions): Lorem ipsum dolor sit amet[1], consectetur adipiscing elit, sed ...
8
votes
4answers
1k views

Grok Vim motions and simple edits

I'm returning to Vim after using Emacs for a few years. I'm trying to grok Vim by reading and watching tutorials, as well as actually using it daily. When editing text, I find the Emacs commands of ...
8
votes
1answer
120 views

change meaning of “paragraph” for TeX input?

I'm writing LaTeX code which has a lot of sections like this \begin{definition} blah blah blah ... ... \end{definition} In normal text, I'm very fond of gq] to rewrap everything nicely. Inside a ...
3
votes
1answer
2k views

Visual select single column from cursor to last line with text in column

There are already a lot of similar questions to this. Jump to last line, but stay in the same column How to go to the end of the file in vim while preserving the current column under the cursor? How ...
4
votes
3answers
2k views

navigate within nerdtree

I wonder how folks navigate efficiently with in a nerdtree window, for example if I'm in a folder like this: ├── m1.py ├── m1.pyc ├── m2.py ├── m2.py.bak ├── m2.pyc ├── main.py ├── matplotdemo.py ├── ...
4
votes
2answers
244 views

column-wise f, F, t, T

Sometimes, I need to delete until a character up or down the same column. Consider a file with the following content: abc def hij When cursor is on b, doing a column-wise dfi should remove ...
9
votes
1answer
3k views

Define word boundaries

I use, e.g., dw to delete a word based on word boundaries defined by changing character classes, so that this command applied on abc,def,ghi will result in ,def,ghi. (So far so good, and it worked for ...
10
votes
3answers
534 views

Is there a motion similar to a" that never includes leading whitespace?

I'm using the a" motion rather often in vim; e.g. using ca" while refactoring a piece of code to replace a hardcoded argument with a variable name. The problem with this approach is that a" includes ...
11
votes
2answers
197 views

Rectangular regions as text objects?

Is it possible to define a text object in vim that will act on a rectangular region? For instance, suppose I have vertically aligned columns of text, like this: column 1 co column 2 col lumn 1 ...
8
votes
3answers
2k views

How to simply remove braces

One of my friend told me that I can use the trick below to remove a pair of curly brackets. Put the cursor inside the curly bracket pair you want to remove. y i { to yank the text in braces , then v ...
3
votes
3answers
2k views

Run macro over a visual selection with line movements

I can find an answer to a similar problem here, however although I can get that example to function I can't get what I want to do to work. Here is the example text to be edited, a partial section of ...
2
votes
2answers
189 views

Using the % command on a line without a bracket

I like formating code this way: class A { } unlike another common way: class B { } The thing is, when using the % command to go to the enclosing bracket, which is very useful for copying/deleting ...
2
votes
1answer
124 views

What's the best way to arrange subwords navigation?

I want Vim to treat the following as separate words: FirstSecondThird firstSecondThird first_second_third first.second.third first-second-third first#second#third What is the best solution for this? ...
6
votes
2answers
169 views

Recognize bash variable as distinct word

Is there any way to make vim treat bash variables (anything prefixed with a $, really) as distinct words? For instance, with the following lines: "name $suffix.ext" "name$suffix.ext" with the ...
27
votes
1answer
14k 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 ...
32
votes
5answers
2k views

Is there a text object for the entire buffer?

I often find myself typing commands like gg"+yG or ggdG and would like a more efficient way to do this without having to move the cursor twice. Is there any command that I can use e.g. y[movement] to ...
10
votes
3answers
2k views

How do I move to the last character in a sentence?

In normal mode ( and ) move to the previous or next first character in the sentence, respectively. How do I move to the very last character. If all of my sentences end with a period I can use )T. (...
30
votes
4answers
465 views

How can I treat LaTeX quotes as a text object?

Quotation marks in LaTeX are different than in normal text, in that they're formatted ``like this'' (or `like this' for single quotes). This makes it difficult to navigate through them in Vim. I ...