evil.org 5.8 KB

Editing with Evil

Evil is an amazing way to edit text in emacs. It's built on top of vim, which is an amazing text editor in its own right! When you edit text with evil mode enabled, you have three different states that you use: normal, insert, and emacs. Emacs state is a normal emacs session with evil commands temporarily disabled. Insert mode lets you type characters, delete them, and use normal emacs commands. Normal mode is like emacs' god-mode, which lets you call commands without pressing alt, meta, esc, or ctrl. For example in normal mode dd lets you delete the line, on which point sits.

An evil command in normal mode looks like the following:

Some text objects

  • aw around word. So a including the surrounding whitespace.
  • iw inner word. The word not including whitespace.
  • as around sentence
  • is inner sentence
  • ip inner paragraph
  • ap around paragraph
  • i" inner string
  • a" around string
  • i) inner paren
  • a) around paren
  • i] inner block
  • a] around block
  • i} inner brace
  • a} around brace
  • it inner tag
  • To change all of the contents of an inner tag, you could do =cst(=

hello

    ( hello )
  • at around tag
  • i> inner single tag
  • hello

ci>p

    hello

  • a> around single tag

CamelCaseMotion lets you change camel cased text i,w is inner word of the camel cased word, but it's not working

  • aa around function argument
  • ia inner function argument
  • foo (42, bar(5), 'hello')
    There's a nice delete indent object, that is also not working
  • ai around indentation (including the line above)
  • ii inner indentation (excluding the line above)
  • #+BEGIN_SRC python def foo(): if 3 > 5: return True return "foo"

#+END_SRC

cool commands

find a replace text only in lines 50-100 :50,100s/old/new/g

visually select words. u changes them into lowercase. U uppercases them.

3fh moves point to the 3rd occurrence of "h" on the current line

C-o in normal mode lets you jump back to the previous location

o moves you back to the beginning of the last word O moves you back to the end of the last word e moves you forward to the beginning of the next word E moves you forward to the end of the next word

~)~ move to the next sentence ( move to the last sentence

~}~ move to the next paragraph { move to the last paragraph

m<char> mark the current position of point and store it in that mark "char". '<char> moves to the mark named by ".

http://keyxl.com/aaa8263/290/VIM-keyboard-shortcuts.htm https://www.maketecheasier.com/vim-keyboard-shortcuts-cheatsheet/

evil-surround

Evil surround is a really cool way to surround highlighted regions of text.

Commands

  • dst deletes the surrounding html element

text text text point text text text

With point at the position "point" typing dst will delete the surrounding html element and change the text into:

  • cs<char><char> change the surrounding char to char

"What whats point up dog?"

With point at the position "point" typing cs,' will delete the surrounding html element and change the text into:

'What whats point up dog?'

With point at 'point' cs'<q> will change the above into

What whats point up dog?

type cst* to change the surrounding pair to =

*What whats point up dog?*

Hello world!

ysiw]

[Hello] world!

cs](

{ Hello } world!

  • S<text object> or gs<text object> in visual state will surround a text object
  • ys<text object> or yS<text object> will surround an object in normal state

extending

A surround pair is a char and the char's surrounding chars. It can look like this:

#+BEGIN_SRC emacs-lisp (?* . ("*" . "*")) #+END_SRC

or this:

#+BEGIN_SRC emacs-lisp (?< . surround-read-tag) #+END_SRC

use bash commands in evil with the ! operator

which calls a function that lets you surround a text object with an html element. It would be nice to have a surround for elisp function for "(" that would let you surround a text object with a lisp function!

Here is some original text:

4 I went home 3 I drank the juice 2 I bought the juice 1 I went to the store

When select the paragraph, !sort, you get the text sorted by number

1 I went to the store 2 I bought the juice 3 I drank the juice 4 I went home

When you select the paragraph, !sort -r, you get reverse order

4 I went home 3 I drank the juice 2 I bought the juice 1 I went to the store

When you select a large paragraph, !sort -R, is random order

delete all text in a file that doesn't have this in it!

replace in a file

2 I bought the juice 2 I bought the juice 4 I drank the juice 5 I went to the store 66666 nt home 9 I went to the store 1 I went to the store 3 I drank the juice 3 I drank the juice 3 I drank the juice 422 I bought the juice 2391 I went to the store 232 I bought the juice 4 I went home 4 I went home 4 I went home :v/TEXT /d

:<range> s/<search_string>/<replace_string>/<modifer>

  • range
  • Possible values are "%" which means the whole file. Or ,
  • modifier determines the replace behavior
  • g "global" replace on all lines w/o prompting
  • gc "Ask for confirmation before making the replacement
  • gn ignore the place function and highlight the finds