87
votes
Accepted
Why does vim use hjkl for cursor keys?
From http://www.catonmat.net/blog/why-vim-uses-hjkl-as-arrow-keys/:
When Bill Joy created the vi text editor he used the ADM-3A terminal, which had the arrows on hjkl keys. Naturally he reused the ...
45
votes
Accepted
Delete until the right end of the current inner block
I would use
d])
which means delete (d) to the next unmatched ')' (])).
See :help ]).
35
votes
Accepted
Simplest way to delete a "composite" word?
What you are calling a composite word is actually a WORD (by opposition to a word). Reading :h word and :h WORD should be helpful:
*word*
A word consists of a sequence of ...
34
votes
Accepted
How to jump to middle of buffer
You can use N% to jump to the Nth percent of the file. So e.g. 50% jumps roughly to the middle of the buffer. See the help at :h N%
29
votes
Accepted
End of python block motion
With the update from November 2017 of $VIMRUNTIME/ftplugin/python.vim following ft-specific motions are available for the python language
[[ Jump backwards to begin of current/previous toplevel
[] ...
29
votes
Why does vim use hjkl for cursor keys?
Nobe4's answer is great, and explains why we use hjkl very well. However, it's really interesting to see the full keyboard, and a lot of strange things about vim make more sense when you can see the ...
24
votes
Accepted
Why is the underscore command _ useful?
Good question!
As a motion by itself, you're right, _ is not a particularly useful key. :h _
*_*
_ <underscore> [count] - 1 lines downward, on the first non-...
19
votes
Why does vim use hjkl for cursor keys?
As to why these arrows were printed on these keys... it's because they could be used with the control key for local cursor movement. Ctrl-H and Ctrl-J (backspace and line feed) are obvious, and an ...
16
votes
Accepted
How to delete entire function definition (C style)
Motion ][: next } in the first column
V][d does what you want. More details can be found under :h ][ and :h section:
*section*
[...]
The "]" and "[" ...
16
votes
Accepted
Vim normal mode: why is j/k jumping paragraphs instead of lines?
Vim is not really jumping paragraphs... These are actually really long lines.
The default behavior is for Vim to wrap long lines, so they might end up taking multiple lines in your screen, but they're ...
15
votes
Accepted
Which text object defines text enclosed in space?
I believe you are looking for the WORD text object.
From :h WORD:
A WORD consists of a sequence of non-blank characters, separated with white
space. An empty line is also considered to be a ...
15
votes
Accepted
Key binding to select the current paragraph
See:
:h ip
:h ap
You are looking for the built in vip.
Also, :h text-objects is a good start to find the text objects you are looking for.
Edit To address your comment: to move the cursor to one ...
13
votes
Accepted
Why does >3k move the cursor up when >3j does not move it down?
Yes, Vim automatically moves to the top most indented line. To see this, position the cursor in the middle of a paragraph and use >ap to indent the whole paragraph.
Note that this is not specific ...
11
votes
Why do `cw` and `ce` do the same thing?
The difference between the behavior of the motion in cw vs. dw can be explained simply: normally if you want to change a word you're going to leave the whitespace following it, while deleting a word ...
11
votes
Accepted
How to select the content within brackets including brackets and without including brackets?
You can use text objects to accomplish this. Start a selection with v and then:
For selecting inside use: i{
For selecting the whole block including braces use: a{
You can also do this with any ...
11
votes
Why does "e" move you one character before the actual end of the word?
This is assuming that your setup is using the ordinary e. If this doesn't answer your question, check if e is mapped to anything with :nmap e
This comes from a fundamental misunderstanding of where ...
11
votes
Simplest way to delete a "composite" word?
Another more general solution is to delete up to the whitespace character using dt (with a space after the t), which means "delete to [character]. This often is useful for things like dt: and similar ...
11
votes
Accepted
How to go back to the start of a visual selection?
You can use the o visual-mode command to jump to the "other" end of the visual selection.
11
votes
Accepted
How to append to the end of word with one key stroke?
object_name = "foo"
another_long_object_name = "bar"
again_different_length_word_which_needs_same_modification = "spam"
I would like to press a keystroke when standing ...
10
votes
A version of `w` which skips to the next underscore
This can be done very easily with the iskeyword option. From :h iskeyword
*'iskeyword'* *'isk'*
'iskeyword' 'isk' string (Vim default for MS-DOS and Win32:
...
9
votes
Multiple cursors at desired location
More Vim ways.
First task:
\section[foobar baz]{foobar baz}
Workflow:
\section[]{}
hh
ifoobar baz<Esc>
$.
Second task:
variable1 = 2
my_variable2 = 12
var3 = 14
Command:
3:norm ...
8
votes
How to disable arrow keys in vim?
You could add this to your .vimrc to disable the arrow keys in Command, Insert, Normal and Visual Mode:
" Remove newbie crutches in Command Mode
cnoremap <Down> <Nop>
cnoremap <Left>...
8
votes
Why can ci" be outside of quoted area and ci( only works inside parentheses?
The other answers covered why this happens. Here's a nice way to work around it.
wellle/targets.vim. I just recently found this plugin, and I think it's extremely underrated. It provides a new text ...
8
votes
truncate sentence: delete up to, but not including period
t and f are nice when we are on the same line. If the period is on another line, we're back to /\.. If you want to type ds, or cs, or ys, ... it can be done thanks to an operator-pending mode mapping:
...
8
votes
How to use 'w' to navigate in CamelCase words?
This is not how w and iskeyword works. Consider this example:
!his!s!!hort!entence
^^ ^^^ ^ ^^
Pressing w repeatedly, you will see the cursor stops where sequences of !s meet sequences of alpha ...
8
votes
Accepted
8
votes
Accepted
Unable to set iskeyword for colon ( : ) character
You are looking for
set iskeyword-=:
That is, making : explicitly not a keyword character. If : is in iskeyword it will be included in ciw.
8
votes
Accepted
Why does `yW` yank until the end of the WORD, but `W` move to the next one?
It might be useful to quote :help exclusive, here:
A character motion is either inclusive or exclusive. When inclusive, the
start and end position of the motion are included in the operation. When
...
7
votes
How to disable arrow keys in vim?
This is how I do it, I call it hard_ass.vim
for key in ['<Up>', '<Down>', '<Left>', '<Right>']
exec 'noremap' key '<Nop>'
exec 'inoremap' key '<Nop>'
exec '...
7
votes
Accepted
Delete to ; if exists, otherwise to end of line
This should do the trick for you:
nnoremap <buffer> <expr> C (getline('.')[getpos('.')[2]:] =~ ';')? "ct;" : "c$"
<expr> allows us to do conditional mapping
getline('.') =~ ';' ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
cursor-motions × 269cursor-movement × 42
key-bindings × 40
visual-mode × 25
normal-mode × 24
cut-copy-paste × 22
object-motions × 20
vimscript × 14
custom-text-object × 14
neovim × 12
vimrc × 9
cursor × 9
search × 7
insert-mode × 7
replace × 7
ex-mode × 5
map-operator × 5
indentation × 4
functions × 4
filetype-tex × 4
repeated-commands × 4
find × 4
count × 4
substitute × 3
highlight × 3