Code Monkey home page Code Monkey logo

novim-mode's Introduction

No Vim Keybindings Mode

Some, indeed many, may say this is counter-productive or even sacrilegious. But Vim is a lot more than just a keybinding paradigm; firstly it has one of the richest plugin ecosystems of any editor, but also it is a -if not the most- ubiquitous text editor that's been battle tested for over 25 years. There are more reasons to use it than merely its famous shortcut vocabulary.

This plugin is an attempt to expose everything else about Vim without the overhead of cultivating Normal Mode fluency. This is not a rebellion, it is merely a manifestation of the distinction between Vim the editor and Vim the keybinding paradigm. Please do not dismiss Normal Mode just because this plugin exists, give vimtutor a try, modal editing is popular for a reason.

Vim itself already has support for something similar in its optional mswin.vim config file. However it still assumes the necessity of Normal Mode and such heritage as SHIFT+INSERT-style combinations. This plugin however, attempts to avoid Normal Mode unless absolutely necessary, say for interacting with the NERDTree buffer, wherein Insert Mode has no purpose.

The name novim-mode is a nod to the prevalence of 'vim-mode' plugins and extensions available in environments outside the editor, such as web browsers. In the same way that the love of Vim has led to efforts to export it elsewhere, 'novim-mode' is the love of 'conventional' editing imported into Vim.

Installation

Use your favourite plugin manager, eg, for vim-plug;

Plug 'tombh/novim-mode'

Usage

Most keybindings should work as you might expect from, say Atom or Sublime Text; SHIFT+ARROW to select and CTRL+C/V to copy/paste. But don't expect Vim to completely bend to your will, it is still useful to familiarise yourself with some of Vim's basic concepts. For instance you may on occasion find yourself stuck in a particular Vim mode, like when pasting text without 'Paste Mode' then inserted text can trigger random mappings. In such case CTRL+Q may not kill Vim and you'll need to find a way of getting to Normal Mode and typing :q then <RETURN>. Such is life with Vim, this plugin is highly unlikely to ever change that. (BTW conventional pasting is on by default, but to exit an errant 'Paste Mode' use :set nopaste.)

If you are new to Vim, then perhaps the only remaining confusion after installing this plugin will be about where files go when you open new ones. This question will be answered by Vim's concept of 'buffers'. You may wish to install something like vim-buftabline to give a familiar list of open files along the top of the editor.

Keybindings

Vim in the terminal

Both Vim and Neovim can be used both as GUI apps and in the terminal. However, original Vim in the terminal has problems with many key combinations - essentially most combinations that are not a plain CTRL+KEY. To get around this you can use the vim-fixkey plugin. It does have some caveats, which you can read about in its docs, but basically it just makes recording macros a little bit more tricky because of the timing between Esc combinations. vim-fixkey also doesn't enable ALT+non-alphanumeric combinations, but novim-mode usually has alphanumeric siblings which you can still use. However, if you are not particularly tied to Vim, you can use Neovim in the terminal which has much better support for key combinations and will work without the need for vim-fixkey. Note that the GUI versions of both Vim and Neovim also don't have these key combination problems.

Most terminal emulators (ie. xterm, rxvt, PuTTY, etc) default to intercepting CTRL+S to suspend output (CTRL+Q unsuspends if you're wondering), if so you will need to disable this behaviour to use novim-mode's shortcuts for saving and quitting. Most often you simply need to add the following to your ~/.bashrc, ~/.zshrc or similar:

stty -ixon
stty stop undef

However some GUI terminals also have their own settings for suspension. For instance Konsole, which can be unset by going to Settings -> Configure Profile -> Choose current profile -> Edit Profile -> Advanced Tab and disabling Enable flow control using Ctrl+S and Ctrl+Q

One further common problem is that tmux can change key combination behaviour, most notably for SHIFT+ARROW combinations, to overcome this add set-window-option -g xterm-keys to your ~/.tmux.conf config.

General editor shortcuts

  • CTRL+N: Open a new file.
  • CTRL+O: Open an existing file. Causes too many conflicts, use (ALT+;, type edit) or a file manager instead
  • CTRL+S: Saves the current file.
  • CTRL+Q: Quit Vim.
  • CTRL+G: Goto line.
  • ALT+; or ALT+c: Vim's command prompt.
  • ALT+o: Replaces native CTRL+O to give one-off Normal Mode commands.

Pane controls

  • ALT+ARROW: Change pane/buffer focus.
  • CTRL+W: Closes current pane-like thing. Also closes associated quickfix and location panes.

Selecting, copy and paste

  • SHIFT+ARROW: Select text
  • CTRL+C: Copy selection or copy line if no selection.
  • CTRL+X: Cut selection or cut line if no selection.
  • CTRL+V: Paste current selection.
  • CTRL+A: Select all.
  • CTRL+D: Select word under cursor. Use something like vim-multicursors for multi cursor support.
  • CTRL+L: Select line under cursor, repetition selects more lines.

Indenting

  • TAB or ALT+]: Indent current line or selected text. TAB currently broken for Neovim
  • SHIFT+TAB or ALT+[: Unindent current line or selected text.

Finding, replacing

  • CTRL+F: Find text. When text is selected that selection is searched for.
  • F3 and SHIFT+F3: Find next and previous occurences.
  • CTRL+H: Find and replace. [FIND] and [REPLACE] are prepopulated.

Undoing

  • CTRL+Z or CTRL+U: Undo.
  • CTRL+Y: Redo.

Other text manipulation tricks

  • CTRL+LEFT/RIGHT: Move cursor per word (works in selection as well).
  • CTRL+ALT+k: Delete current line. Currently broken in terminal Vim
  • CTRL+ALT+d: Duplicate current line. Currently broken in terminal Vim
  • CTRL+UP/DOWN: Move current line or selected text up/down.

Note that CTRL-based shortcuts are paired with uppercase letters in these docs because Vim does not recognise the difference between cases when using CTRL combinations and documenting in uppercase implies something of this distinction.

Interoperability

When adding a new binding of your own that needs Normal mode, you should use <C-O> before the targeted command, for example;

" Ensure CtrlP doesn't get overridden by autocomplete in insertmode
inoremap <C-P> <C-O>:CtrlP<CR>

Overriding or disabling shortcuts in this plugin can be done in several ways. The simplest way is to use:

let g:novim_mode_use_shortcuts = 0
inoremap ... custom mapping ...
call novim_mode#StartNoVimMode()

Shortcuts are also grouped roughly under the headings described above, so you may be able to disable one of the following:

let g:novim_mode_use_general_app_shortcuts = 1
let g:novim_mode_use_pane_controls = 1
let g:novim_mode_use_copypasting = 1
let g:novim_mode_use_indenting = 1
let g:novim_mode_use_finding = 1
let g:novim_mode_use_undoing = 1
let g:novim_mode_use_text_tricks = 1

" Small fixes to HOME and PAGEUP behaviour
let g:novim_mode_use_editor_fixes = 1
" Allows scrolling through wrapped lines one visual line at a time
let g:novim_mode_use_better_wrap_navigation = 1

Lastly you can unmap a mapping using commands such as nunmap, iunmap, sunmap, etc.

Known issues

  • Because a lot of the keybindings trigger brief switches to NORMAL mode in the background, then be careful of plugins that cause a delay between switching modes. I know that vim-airline in particular has this problem.
  • In Neovim there seems to be a bug where only SHIFT+TAB and not TAB works for indenting during selection mode.
  • Mapping <CTRL+M> internally means mapping <RETURN>. This is a throwback to Vim's days as a pure terminal application.
  • CTRL+BACKSPACE internally represents <CTRL+H>, which can be annoying. Again this is a throwback to Vim's days as a pure terminal application.

novim-mode's People

Contributors

omentic avatar tombh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

novim-mode's Issues

Detect mouse-triggered selection in order to switch its visual selection to Selection mode

With commit e3f8943 there was an improvement to selection behaviour in order to support snippet plugins that auto-select the parts of snippet that a user needs to fill. However, the downside to the approach I took is that now mouse selection selects in Visual mode, which is not like normal selection behaviour, namely pressing any key doesn't exit the selection and indeed SHIFT+arrow does unexpected things (if you're not used to Vim).

So I need to think of a way to fix that.

Breakage on neovim 0.8.0

See neovim/neovim#18547.

Currently looking into fixing this but likely won't have time until the weekend. It seems the maintainers are well aware of people using this and so have provided some example scripts as workarounds.

In principle this shouldn't be an issue because of autocmd, we may just have to tweak existing commands to explicitly enter insert mode again.

Close buffer *and* buffer's pane when more than 1 buffer is visible

Currently, if you have a split (or more) then closing a buffer will just close the buffer and not the split, which doesn't feel like the expected thing to do - it should close the pane (and the buffer).

This will need looping through winnr('$') and counting the number of wins that respond true to IsEditable().

Will also need to not close the buffer (ie just the pane), if the pane's buffer is also open elsewhere.

Arrow Keys and Mouse Sending Characters Instead of Expected Input

As soon as this plugin is enabled everything gets weird. I can't use a lot of the commands.
For example Alt-; doesn't do anything.
Also my arrow keys place "COCOCOBOAODOAODOCOBODOAOCODOCOBODOAOCODOAOCOAOAOAOA" on the screen instead of the expected behavior.

Using vanilla vim on ubuntu 17.

Fairly excited about this plugin. I would like to help, but I don't know enough about vim to help debug.

error on vim startup

I'm having trouble installing this plugin.

I start with Ubuntu Xenial 16.04 LTS
Using the packaged version 2:7.4.1689-3ubuntu1.2
I have a completely clean vi/vim config. No .vimrc , no .vim/ , nothing.
I install https://github.com/junegunn/vim-plug according to its instructions.
I created the .vimrc, added novim-mode , and ran :PlugInstall no problem. novim-mode says it was installed. Looks good so far.

However, when I restart vim from the command line, I get this:

Error detected while processing BufEnter Auto commands for "*":
E15: Invalid expression: >execute('call s:InsertMode()')})
E116: Invalid arguments for function timer_start
Press ENTER or type command to continue

After I hit enter, I can use vim as before, but none of this plugin's features are present.

Advice?

Conflict with telescope

Since novim-mode is always active, it tampers with UI plugins like telescope. Due to that, it forces you into insert mode by default and you need to Shift+Esc out of it. Is there any way to disable novim-mode until you're in the editor environment?

Neovim Terminal not opening in insert mode.

I am using the neovim terminal in termux to execute python code. And wanted that the terminal to open in insert mode so that I can input. The keymap I use for this purpose is:-
inoremap <F4> <C-o>:w<CR><C-o>:term python %<CR>
And it works fine with the novim plugin disabled but if the plugin is enabled the terminal opens in nornal mode and I can't input any value until I jump to insert mode.
Strangely this behaviour is ironic to novim as its made for keeping things in insert mode but in this case it does just the opposite.
And I have tried to debug the issue by setting these options to false

let g:novim_mode_use_general_app_shortcuts = 1
let g:novim_mode_use_pane_controls = 1
let g:novim_mode_use_copypasting = 1
let g:novim_mode_use_indenting = 1
let g:novim_mode_use_finding = 1
let g:novim_mode_use_undoing = 1
let g:novim_mode_use_text_tricks = 1

" Small fixes to HOME and PAGEUP behaviour
let g:novim_mode_use_editor_fixes = 1
" Allows scrolling through wrapped lines one visual line at a time
let g:novim_mode_use_better_wrap_navigation = 1

But the problem still persists even if I set all the options to 0 so ig the problem is with some core thing.

Scrolling deletes the last line.

I am using novim with neovim in termux. But there scrolling or more clearly swiping (same as scrolling) deletes the last line instead. It behaves normally if this plugin is disabled. Thank you.

Is it possible to toggle novim-mode?

Hi there,

I frequently run into the issue that if I'm pair programming with colleagues we have to switch editors because they can't use vim. As the title suggests, I was wondering if it was possible to toggle novim-mode on and off, so I can use vim as normal, then when I colleague wishes to type I can switch into novim-mode.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.