RROx bookclub - Text editors
Thibault Lestang
03.06.2020
- Text editors
- Primary motivation: working with code
- Much of your files are text files
- Read and edit text efficiently
- Using the keyboard
- One swiss army knife for all your editing
- Working with plain text
- Is Microsoft Word a text editor?
- Plain text
- Using plain text files/data is best practice
- Composing documents in plain text
- Common text editors
- Text based text editors
- Graphical text editors
- Wait but yout didnt mention RStudio?
- There is no “best” editor.
- Personnal opinion: Emacs or Vim
- Demo
- Navigation
- Getting help
- Windows, frames and buffers
Text editors
Wikipedia
A text editor is a type of computer program that edits plain text.
Primary motivation: working with code
- A computer code is text.
- Working with code is different from working with prose.
- Indentation, syntax highlighting.
- Navigate through code, jump to definition
Much of your files are text files
- Data (CSV, JSON, XML…)
- Notes
- Email
- Paper (markdown, latex)
- Web (HTML and markup languages)
- Can you think of more?
Read and edit text efficiently
- Convenient navigation commands
- Compare files
- Search and replace
- Syntax hightlighting, indentation
- Navigate through function definitions
- Auto-completion
- Jump to docs
- Jump to definition
- …
Using the keyboard
- Using the mouse is slow.
- Using the mouse cannot be automated.
Everything you type can be automated (macro or written in a file).
- Efficiency
- Reproducibility
One swiss army knife for all your editing
Automation also happens in your brain: muscle memory.
Working with plain text
Is Microsoft Word a text editor?
It is a word-processor.
Word processors deal with rich-text formats, than contain much more information
than the symbols themselves:
- Font
- Font face
- Pages
- Margins
- Headers
- …
(Can be) useful when writing documents but not when writing code.
Plain text
Text editors deal with plain text files.
A text file is a sequence of bytes describing, a sequence of letters and symbols,
plus some invisible symbols (end of line).
Plain text is just text. Nothing more.
Using plain text files/data is best practice
Text files can be used anywhere
- Read by any editor.
- On any platform.
- Independently of the encoding
Using plain text ensures both longevity and portability of your data/files.
Not format, no ties to any particular software, or/and particular version.
Text files can be versioned using version control (Git, Mercurial…)
Composing documents in plain text
- Markdown
- ReStructuredText
- AsciiDoc
- LaTeX
- Emacs Org-Mode
- Rmarkdown
- …
Tools like pandoc let you go from one format to another, and produce (compile)
your documents… including word processor formats!
Common text editors
Text based text editors
You can open them in your terminal.
Examples:
Not relying on a graphical envirionment adds an extra layer of flexibility.
Example: editing files on a server without a graphical interface.
It allows for quick-edits, you don’t have to leave your terminal.
Less is more.
Graphical text editors
Popular examples:
- VScode
- Atom
- SublimeText
- Gedit (GNU/Linux)
Often require less configuration, more fancy functionalities by default.
Some think they look nicer.
Contain buttons, menus.
Wait but yout didnt mention RStudio?
RStudio is an Integrated Development Environment (IDE) for R.
It contains a text editor, but many other things such as
- debugger
- version control
- integrated terminal
- project management
- project build
- …
Popular IDES:
- Eclispe
- Visual Studio
- Xcode
- PyCharm (Python)
- CLion (C/C++)
- IntelliJ (Java)
- Spyder (Python)
- RStudio ( R )
- …
Pros and cons:
- Can be useful when working on a specific software project.
- All graphical software.
- Relatively heavyweight (compared to text editors)
- Not your swiss army knife.
Text editors are better suited to open files in different languages,
text-based data, and config files.
- Quality of embedded text editor varies widely.
There is no “best” editor.
But some are better than others.
People have strong opinions about text editors and IDEs.
It seemd to be very subjective.
Common points of discord are:
- Graphical vs text-based
- Vim vs Emacs (The Unix Editors war)
Personnal opinion: Emacs or Vim
- You’ll find them anywhere.
- Lightweight
- Text based: do not depend on any graphical interface.
- The most powerful editors
- They are OLD (but still WIDELY used)
- Highly customizable
- Naturally keyboard oriented
- Longevity
Cons
- Steep learning curve
- OLD (weird terminology)
- Surprising shotcuts in nowadays standards
- Really highly customizable
Demo
Navigation
- Basic mvt
- Movement by word, paragraph and sentence
- By default emacs assumes that sentences are separated by a period follow by two spaces. To change this
(setq sentence-end-double-space nil)
- M-k (kill-sentence)
- C-x
(backward-kill-sentence)
- Page up (C-v) and page down (M-v). C-M-v to (scroll-other-window)
- (move-to-window-line-top-bottom)
- Moving by balanced expressions C-M-f (forward-sexp) and C-M-b (backward-sexp)
- Moving down and up balanced expressions C-M-d (down-list) and C-M-u (up-list)
drop_na <- function(data, ...) {
ellipsis::check_dots_unnamed()
UseMethod("drop_na")
}
drop_na.data.frame <- function(data, ...) {
vars <- tidyselect::eval_select(expr(c(...)), data)
if (is_empty(vars)) {
f <- complete_cases(data)
} else {
f <- complete_cases(data[vars])
}
out <- vec_slice(data, f)
reconstruct_tibble(data, out)
}
- M-m (back-to-indentation)
- Using the mark
- C-x C-n (set-goal-column); C-u C-x C-n to unset
- C-k (org-kill-line)
- Mention kill-sentence here
https://oracleyue.github.io/2019/09/06/emacs-editing/
Getting help
- C-h f (describe-function)
- C-h v (describe-variable)
- C-h m (describe-mode)
- C-h k (describe-key)
- M-x apropos
Windows, frames and buffers
In Emacs, text is always displayed inside what is called a buffer.
Typically, a buffer will display the content of a file, but it could also display other things, such as
the content of a directory (using Dired).
- Opening a new file automatically creates a new buffer
- (list-buffers) C-x C-b
- C-x b (switch-to-buffer)
- C-u M-g M-g Go to line in previous buffer
Buffers are contained in “windows”
- (split-window-below) C-x 2
- (split-window-right) C-x 3
- (other-window) C-x o will cycle through the currently open windows.
Can use a prefix argument to jump several windows.
- (scroll-other-window) C-M-v
- (switch-to-buffer-other-window) C-x 4 b bufname <RET>
- (find-file-other-window) C-x 4 f filename <RET>
- (delete-window)
- (delete-other-windows)
Notice than deleting a window does not kill the buffer
- (kill-buffer) C-x k
- (kill-buffer-and-window) C-x 4 0
Windows can be enlarged and shrinked
RROx bookclub - Text editors
Thibault Lestang
03.06.2020
Text editors
Wikipedia
Primary motivation: working with code
Much of your files are text files
Read and edit text efficiently
Using the keyboard
Everything you type can be automated (macro or written in a file).
One swiss army knife for all your editing
Automation also happens in your brain: muscle memory.
Working with plain text
Is Microsoft Word a text editor?
It is a word-processor.
Word processors deal with rich-text formats, than contain much more information
than the symbols themselves:
(Can be) useful when writing documents but not when writing code.
Plain text
Text editors deal with plain text files.
A text file is a sequence of bytes describing, a sequence of letters and symbols,
plus some invisible symbols (end of line).
Plain text is just text. Nothing more.
Using plain text files/data is best practice
Text files can be used anywhere
Using plain text ensures both longevity and portability of your data/files.
Not format, no ties to any particular software, or/and particular version.
Text files can be versioned using version control (Git, Mercurial…)
Composing documents in plain text
Tools like pandoc let you go from one format to another, and produce (compile)
your documents… including word processor formats!
Common text editors
Text based text editors
You can open them in your terminal.
Examples:
Not relying on a graphical envirionment adds an extra layer of flexibility.
Example: editing files on a server without a graphical interface.
It allows for quick-edits, you don’t have to leave your terminal.
Less is more.
Graphical text editors
Popular examples:
Often require less configuration, more fancy functionalities by default.
Some think they look nicer.
Contain buttons, menus.
Wait but yout didnt mention RStudio?
RStudio is an Integrated Development Environment (IDE) for R.
It contains a text editor, but many other things such as
Popular IDES:
Pros and cons:
Text editors are better suited to open files in different languages,
text-based data, and config files.
There is no “best” editor.
But some are better than others.
People have strong opinions about text editors and IDEs.
It seemd to be very subjective.
Common points of discord are:
Personnal opinion: Emacs or Vim
Cons
Demo
Navigation
(setq sentence-end-double-space nil)
(backward-kill-sentence)#' from tidyR/R/drop-na.R #' @export drop_na <- function(data, ...) { ellipsis::check_dots_unnamed() UseMethod("drop_na") } #' @export drop_na.data.frame <- function(data, ...) { vars <- tidyselect::eval_select(expr(c(...)), data) if (is_empty(vars)) { f <- complete_cases(data) } else { f <- complete_cases(data[vars]) } out <- vec_slice(data, f) reconstruct_tibble(data, out) }
https://oracleyue.github.io/2019/09/06/emacs-editing/
Getting help
Windows, frames and buffers
In Emacs, text is always displayed inside what is called a buffer.
Typically, a buffer will display the content of a file, but it could also display other things, such as
the content of a directory (using Dired).
Buffers are contained in “windows”
Can use a prefix argument to jump several windows.
Notice than deleting a window does not kill the buffer
Windows can be enlarged and shrinked