I started learning Vim/NeoVim a few years ago in order to become faster at text editing, mainly for coding. However this term I am in a lot of classes that require writing, so for this blog I wanted to set up my Nvim to behave like a word processor.
Back ground of Vim
Vim is a simple, terminal based text editor, centered around keyboard navigation rather than, mouse navigation. When using Vim the mouse is not used whatsoever. This is achieved through Vim modes. The most used being:
Normal mode: When the user presses <Escape> they enter normal mode. When in normal mode, is when the user can navigate the page or enter commands. Insert mode: Pressing <i> enters insert mode, once in insert mode, the user can insert text. Visual mode: Pressing <v> enters visual mode, which allows the user to select text. Vim uses grammar oriented shortcuts: For example <2ft> this would translate to “second forward letter t” -> “move the cursor to the second t”
Why would I want to use Vim as a word processor rather than just using a word processor?
Mainly because editing text with a mouse is cognitively taxing and not fun. Vim allows me to edit any text in an efficient, fast and fun way, regardless of the file type. I can use it for coding, writing English, and creating presentations. This unified approach reduces cognitive overhead immensely because I do not have to learn new applications that have different shortcuts, I can learn one set and get really good at that set of shortcuts, and I never have to reach for the mouse when I am working in Vim!
How I made Vim into a word processor
Since Vim/NeoVim is open source it is very easy to hack and customize, this made it very easy to create a command called WordMode that turns the editor from a code editor into a word processor. I will not explain this function, but if anyone is interested in adding this to their NeoVim setup, the code will be included at the end.
Conclusion
Creating a WordProcessor mode in Vim has been a game changer for me, because I used to find my self getting stuck while writing and not knowing what to say. Vim allows me to get my ideas out fast, which allows me to flow smoothly while writing.
sources
Download:
https://github.com/neovim/neovim
https://www.lazyvim.org/
Other
- Learn Vim Progressively:
https://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/ - Learning Vim in 2014:
https://benmccormick.org/learning-vim-in-2014/ - Vimcasts:
http://vimcasts.org/ - Vim Video-Tutorials by Derek Wyatt:
http://derekwyatt.org/vim/tutorials/ - Learn Vimscript the Hard Way:
https://learnvimscriptthehardway.stevelosh.com/ - 7 Habits of Effective Text Editing:
https://www.moolenaar.net/habits.html - vim-galore:
https://github.com/mhinz/vim-galore
https://en.m.wikipedia.org/wiki/File:Neovim-logo.svg
-- Define the "Word Processing Mode"
local function word_processor_mode()
-- Set format options for text formatting
vim.opt_local.formatoptions = 't1'
-- Set text width to 80 for line wrapping
--vim.opt_local.textwidth = 80
-- Map 'j' and 'k' to move through visual lines instead of wrapped lines
vim.api.nvim_buf_set_keymap(0, 'n', 'j', 'gj', { noremap = true, silent = true })
vim.api.nvim_buf_set_keymap(0, 'n', 'k', 'gk', { noremap = true, silent = true })
vim.api.nvim_buf_set_keymap(0, 'n', '0', 'g0', { noremap = true, silent = true })
vim.api.nvim_buf_set_keymap(0, 'n', '$', 'g$', { noremap = true, silent = true })
vim.api.nvim_buf_set_keymap(0, 'v', 'j', 'gj', { noremap = true, silent = true })
vim.api.nvim_buf_set_keymap(0, 'v', 'k', 'gk', { noremap = true, silent = true })
vim.api.nvim_buf_set_keymap(0, 'v', '0', 'g0', { noremap = true, silent = true })
vim.api.nvim_buf_set_keymap(0, 'v', '$', 'g$', { noremap = true, silent = true })
-- Enable smart indent
vim.opt.colorcolumn = ''
vim.opt_local.smartindent = true
vim.opt_local.spell = true
vim.opt_local.wrap = true
vim.opt_local.linebreak = true
-- Enable spell checking with English (US) dictionary
vim.opt_local.spelllang = 'en_us'
-- Disable tab expansion to spaces
vim.opt_local.expandtab = false
-- Set background to light mode
vim.opt.background = 'light'
vim.opt.scrolloff = 1
-- require('zen-mode').toggle()
end
-- Create a command to trigger "Word Processing Mode"
vim.api.nvim_create_user_command('WordMode', word_processor_mode, {})