vim: f and t multiline option (#8448)

I'm not sure how compliant you're aiming to be with vim, but the `f`
behavior is more useful when it can search on multiple lines instead of
a single one, so I'd like to propose this change.

This change is quite frequent in vim/neovim as a plugin (e.g.
[clever-f](https://github.com/VSCodeVim/Vim),
[improved-ft](https://github.com/backdround/improved-ft.nvim), etc), and
in other vim emulations (e.g.
[vscode-vim](https://github.com/VSCodeVim/Vim)).
This commit is contained in:
Rom Grk 2024-02-27 21:34:19 -05:00 committed by GitHub
parent bd8896a3dc
commit 9a7a267203
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 186 additions and 37 deletions

View file

@ -17,7 +17,10 @@ mod visual;
use anyhow::Result;
use collections::HashMap;
use command_palette_hooks::{CommandPaletteFilter, CommandPaletteInterceptor};
use editor::{movement, Editor, EditorEvent, EditorMode};
use editor::{
movement::{self, FindRange},
Editor, EditorEvent, EditorMode,
};
use gpui::{
actions, impl_actions, Action, AppContext, EntityId, Global, Subscription, View, ViewContext,
WeakView, WindowContext,
@ -482,6 +485,11 @@ impl Vim {
let find = Motion::FindForward {
before,
char: text.chars().next().unwrap(),
mode: if VimSettings::get_global(cx).use_multiline_find {
FindRange::MultiLine
} else {
FindRange::SingleLine
},
};
Vim::update(cx, |vim, _| {
vim.workspace_state.last_find = Some(find.clone())
@ -492,6 +500,11 @@ impl Vim {
let find = Motion::FindBackward {
after,
char: text.chars().next().unwrap(),
mode: if VimSettings::get_global(cx).use_multiline_find {
FindRange::MultiLine
} else {
FindRange::SingleLine
},
};
Vim::update(cx, |vim, _| {
vim.workspace_state.last_find = Some(find.clone())
@ -628,11 +641,13 @@ struct VimSettings {
// vim always uses system cliupbaord
// some magic where yy is system and dd is not.
pub use_system_clipboard: UseSystemClipboard,
pub use_multiline_find: bool,
}
#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
struct VimSettingsContent {
pub use_system_clipboard: Option<UseSystemClipboard>,
pub use_multiline_find: Option<bool>,
}
impl Settings for VimSettings {