@@ -1175,6 +1175,7 @@ fn search_impl(
11751175 regex: &Regex,
11761176 movement: Movement,
11771177 direction: Direction,
1178+ scrolloff: usize,
11781179) {
11791180 let text = doc.text().slice(..);
11801181 let selection = doc.selection(view.id);
@@ -1233,7 +1234,11 @@ fn search_impl(
12331234 };
12341235
12351236 doc.set_selection(view.id, selection);
1236− align_view(doc, view, Align::Center);
1237+ if view.is_cursor_in_view(doc, 0) {
1238+ view.ensure_cursor_in_view(doc, scrolloff);
1239+ } else {
1240+ align_view(doc, view, Align::Center)
1241+ }
12371242 };
12381243}
12391244
@@ -1257,6 +1262,8 @@ fn rsearch(cx: &mut Context) {
12571262// TODO: use one function for search vs extend
12581263fn searcher(cx: &mut Context, direction: Direction) {
12591264 let reg = cx.register.unwrap_or('/');
1265+ let scrolloff = cx.editor.config.scrolloff;
1266+
12601267 let (_, doc) = current!(cx.editor);
12611268
12621269 // TODO: could probably share with select_on_matches?
@@ -1281,7 +1288,15 @@ fn searcher(cx: &mut Context, direction: Direction) {
12811288 if event != PromptEvent::Update {
12821289 return;
12831290 }
1284− search_impl(doc, view, &contents, ®ex, Movement::Move, direction);
1291+ search_impl(
1292+ doc,
1293+ view,
1294+ &contents,
1295+ ®ex,
1296+ Movement::Move,
1297+ direction,
1298+ scrolloff,
1299+ );
12851300 },
12861301 );
12871302
@@ -1289,6 +1304,7 @@ fn searcher(cx: &mut Context, direction: Direction) {
12891304}
12901305
12911306fn search_next_or_prev_impl(cx: &mut Context, movement: Movement, direction: Direction) {
1307+ let scrolloff = cx.editor.config.scrolloff;
12921308 let (view, doc) = current!(cx.editor);
12931309 let registers = &cx.editor.registers;
12941310 if let Some(query) = registers.read('/') {
@@ -1303,7 +1319,7 @@ fn search_next_or_prev_impl(cx: &mut Context, movement: Movement, direction: Dir
13031319 .case_insensitive(case_insensitive)
13041320 .build()
13051321 {
1306− search_impl(doc, view, &contents, ®ex, movement, direction);
1322+ search_impl(doc, view, &contents, ®ex, movement, direction, scrolloff);
13071323 } else {
13081324 // get around warning `mutable_borrow_reservation_conflict`
13091325 // which will be a hard error in the future