开发者

Using alt+backspace key in vim command line to delete by words

Is there a way to use the alt+backspace in vim command line? It gets unruly when having to backspace /very/long/file/path individually instead 开发者_如何转开发of using alt+backspace to delete by words.


try using instead <c-w> (that is ctrl+w) to erase words or <c-u> (ctrl+u) to delete lines.


http://vim.wikia.com/wiki/Map_Ctrl-Backspace_to_delete_previous_word

:imap <C-BS> <C-W>

sets ctrl backspace, i have to look at how to do alt


If you are at the end of the path you can hit B followed by a dW (case matters). This will jump you to the beginning of the word (ignoring the slashes) and subsequently delete the word (again ignoring the slashes).

Hope this helps.


Vim is unable to receive alt input. skeept's answer seems to be the best alternative.

See this answer:

The Alt/Meta key is problematic in Vim and most terminals, see this answer of mine for an overview of the situation (the situation is the same for Meta and Alt).

In short, Vim doesn't receive Alt at all: hitting Alt+Backspace is exactly the same as hitting Backspace.

Anyway, it will be better for you in the long term to learn and get accustomed to Vim's default key-mappings.


The answer marked as right does not correspond to the behaviour in most UI editors for Alt + BackSpace. The vim shortcut which correspond to this behaviour is db - aka delete back ( a word ?! ), dw would delete word forth, which would be the (Altr or Ctrl ) Del shortcut in most ui programs. Those work basically the same way as the w - move the cursor to the words beginnings and b, move the cursor back to the words beginning ...

Disclaimer: I have used for more than 10 years my .vimrc. , which might have some freaky twist which changes the default behaviour as well ...


Sure, it's as easy as:

if has('gui_running')
    imap <M-BS> <C-W>
else
    imap <Esc><BS> <C-W>
endif

The trick here is to know, given a hypothetical foo key, that after pressing a Alt+foo combination, many terminals will send an Escape code followed by foo. Apparently there are exceptions — some terminals do send something that vim can recognize as Alt. But if a imap <M-BS> <C-W> mapping doesn't work for you in terminal, then most likely your terminal sends an Esc instead, so the combination imap <Esc><BS> <C-W> should work for you.

You can read more about that in vim documentation by evaluating :help map-alt-keys


x then w should backspace per word as well. d then w will also delete the current word the cursor is on.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜