我在vim中使用相对行号设置。我希望vim在我处于插入模式时自动切换到绝对行号,并在正常模式下返回到相对。目前我已经在我的vimrc
中尝试了这段代码 autocmd InsertEnter * :set number
autocmd InsertLeave * :set relativenumber
不幸的是,这只会让我成为那里的一部分。这在我第一次离开插入模式时切换相对数字,但在再次进入插入模式时将不再返回绝对数字。
答案 0 :(得分:5)
首先,做一个
autocmd InsertEnter * :set norelativenumber
autocmd InsertLeave * :set relativenumber
然后
public class FCar extends Fragment implements AdapterView.OnItemSelectedListener {
public FCar() {
}
CarDataBaseAdapter carDataBaseAdapter;
SessionManagement session;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// inflating the view
final View rootView = inflater.inflate(R.layout.fragment_car, container, false);
// declaring stuff, not sure why it has to be final
final Spinner carSpinner;
final EditText editTextDistance, editTextMin;
Button btnSubmitCar;
// create new car database
carDataBaseAdapter = new CarDataBaseAdapter(getActivity());
carDataBaseAdapter = carDataBaseAdapter.open();
SQLiteDatabase x = carDataBaseAdapter.getDatabaseInstance();
session = new SessionManagement(getActivity().getApplicationContext());
// display existing tables
/*
Cursor hi = x.rawQuery("SELECT name FROM sqlite_master WHERE type='table'", null);
hi.moveToFirst();
int f = hi.getCount();
String g = Integer.toString(f);
Toast.makeText(getActivity().getApplicationContext(), g, Toast.LENGTH_LONG).show();
while ( !hi.isAfterLast() ) {
String h = (hi.getString( hi.getColumnIndex("name")) );
hi.moveToNext();
Toast.makeText(getActivity().getApplicationContext(), h, Toast.LENGTH_LONG).show();
}
*/
// Get References of Views
carSpinner = (Spinner) rootView.findViewById(R.id.spinner_car_type);
editTextDistance = (EditText) rootView.findViewById(R.id.editTextcarDistance);
editTextMin = (EditText) rootView.findViewById(R.id.editTextcarMin);
// Spinner click listener
carSpinner.setOnItemSelectedListener(this);
// set default spinner selection
carSpinner.setSelection(0);
// Spinner Drop down elements
List<String> categories = new ArrayList<>();
categories.add("Standard");
categories.add("Truck");
categories.add("Electric/Hybrid");
// Creating adapter for spinner
ArrayAdapter<String> dataAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, categories);
// Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// attaching data adapter to spinner
carSpinner.setAdapter(dataAdapter);
// identifying the button
btnSubmitCar = (Button) rootView.findViewById(R.id.button_car_submit);
btnSubmitCar.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// take username entry from login / sign up form via method in FProfile
// String currentUser = getSingleEntry();
String username = session.getUsername();
SimpleDateFormat formata = new SimpleDateFormat("MM/dd/yyyy", Locale.CANADA);
String date = formata.format(new Date());
String type = carSpinner.getSelectedItem().toString();
// convert distance to integer
int distance = 0;
try {
distance = Integer.parseInt(editTextDistance.getText().toString());
} catch (NumberFormatException nfe) {
System.out.println("Could not parse distance " + nfe);
}
// convert minutes to integer
int time = 0;
try {
time = Integer.parseInt(editTextMin.getText().toString());
} catch (NumberFormatException nfe) {
System.out.println("Could not parse minutes" + nfe);
}
// Save the Data in Database
carDataBaseAdapter.insertEntry(username, date, type, distance, time);
// link back to input menu
Intent intent = new Intent(getActivity(), MainActivity.class);
intent.putExtra("caller", "Input");
startActivity(intent);
}
}
);
return rootView;
}
答案 1 :(得分:0)
set number
map <Esc> :set relativenumber!<CR>
点击该键应该切换行相对编号